Skip to content

Commit

Permalink
Show two decimals on doughnutTooltip if total share shown is less tha…
Browse files Browse the repository at this point in the history
…n 1%

Signed-off-by: Christian König <ckoenig@posteo.de>
  • Loading branch information
yubiuser committed Jan 18, 2023
1 parent 678d7b9 commit 9f7a04a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions scripts/pi-hole/js/index.js
Expand Up @@ -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)
Expand Down

0 comments on commit 9f7a04a

Please sign in to comment.