From 9f7a04a37cd75a147e52c984d562e6fdd302bb66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 18 Jan 2023 22:02:51 +0100 Subject: [PATCH] Show two decimals on doughnutTooltip if total share shown is less than 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 | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index 430385ae..9c02b906 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -729,10 +729,17 @@ function doughnutTooltip(tooltipLabel) { // to compensate rounding errors we round to 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" ? "< 0.1" : tooltipLabel.parsed.toFixed(1); + var itemPercentage; + + // if we only show < 1% percent of all, show each item with two decimals + if (percentageTotalShown < 1) { + itemPercentage = tooltipLabel.parsed.toFixed(2); + } else { + // show with one decimal, but in case the item share is really small it could be rounded to 0.0 + // we compensate for this + itemPercentage = + tooltipLabel.parsed.toFixed(1) === "0.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)