Skip to content

Commit 2fb304c

Browse files
authored
BUGFIX: Prevent division by zero in sparkline rendering (#39)
Prevent division by zero in sparkline rendering when `max` is 0 for whatever reason. In this case a 0 value will be rendered now instead of crashing the whole content release.
1 parent db29a0a commit 2fb304c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Classes/Utility/Sparkline.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ class Sparkline
1313
*/
1414
private static function getY($max, $height, $diff, $value)
1515
{
16+
// prevent division by zero
17+
if ($max === 0) {
18+
return round(floatval(($height + $diff)), 2);
19+
}
20+
1621
return round(floatval(($height - ($value * $height / $max) + $diff)), 2);
1722
}
1823

@@ -58,4 +63,4 @@ public static function sparkline($svgClass, $values, $lineColor = '#aaa', $fillC
5863
return '<!-- Generated with https://github.com/jxxe/sparkline/ -->' . $svg;
5964
}
6065

61-
}
66+
}

0 commit comments

Comments
 (0)