From 776f6df822bbc7fa58eefc830abd8ec2d2ece692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 14 Oct 2022 10:59:12 +0200 Subject: [PATCH] Indicate item share is less than 0.1% MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- scripts/pi-hole/js/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index 474fb9f981..96436a6e25 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -729,17 +729,21 @@ function doughnutTooltip(tooltipLabel) { // to compensate rounding errors we round to two one decimal var label = " " + tooltipLabel.label; + // in case the item share is really small it could be rounded to 0.0 + // we compensate for this + var itemPercentage = + tooltipLabel.parsed.toFixed(1) === 0 ? "< 0.1" : tooltipLabel.parsed.toFixed(1); // even if no doughnut slice is hidden, sometimes percentageTotalShown is slightly less then 100 // we therefore use 99.9 to decide if slices are hidden (we only show with 0.1 precision) if (percentageTotalShown > 99.9) { // All items shown - return label + ": " + tooltipLabel.parsed.toFixed(1) + "%"; + return label + ": " + itemPercentage + "%"; } else { return ( label + ":
• " + - tooltipLabel.parsed.toFixed(1) + + itemPercentage + "% of all queries
• " + ((tooltipLabel.parsed * 100) / percentageTotalShown).toFixed(1) + "% of shown items"