diff --git a/index.php b/index.php
index 0766664..7024745 100644
--- a/index.php
+++ b/index.php
@@ -92,29 +92,38 @@ foreach ($chartData as $x => $y) {
';
}
-$numLabels = floor($height / 50);
-$labelModulation = 2 * 10 ** (1 + floor(-log($yRange / $numLabels, 10)));
-$labelInterval = round($yRange / $numLabels * $labelModulation) / $labelModulation;
+$numLabels = floor($height / 25);
+$labelModulation = 10 ** (1 + floor(-log($yRange / $numLabels, 10)));// / 5;
+$labelInterval = ceil($yRange / $numLabels * $labelModulation) / $labelModulation;
+// Top and bottom grid lines
$gridLines =
"M0,0 ".$width.",0
M0,".$height.",".$width.",".$height."
";
+// Top and bottom grid labels
$gridText =
''.labelFormat($yMax).'' .
''.labelFormat($yMin).'';
+// Start at the first "nice" Y value > min + 50% of the interval
+// Keep going until max - 50% of the interval
+// Add Interval each iteration
for (
- $labelY = $yMin + 0.5 * $labelInterval - fmod($yMin + 0.5 * $labelInterval , $labelInterval) + $labelInterval;
- $labelY < $yMax - 0.5 * $labelInterval;
+ $labelY = $yMin - fmod($yMin, $labelInterval) + $labelInterval;
+ $labelY < $yMax;
$labelY += $labelInterval
) {
-
$labelHeight = transformY($labelY);
$gridLines .= "M0,".$labelHeight." ".$width.",".$labelHeight."
";
- $gridText .= ''.labelFormat($labelY).'';
+ if (
+ $labelY < $yMax - 0.4 * $labelInterval &&
+ $labelY > $yMin + 0.4 * $labelInterval
+ ) {
+ $gridText .= ''.labelFormat($labelY).'';
+ }
}
// in case some dingbat has PHP short tags enabled
@@ -133,8 +142,8 @@ echo '<'.'?xml version="1.0" standalone="no"?'.'>';
-
-
+
+