improve grid placement and plot gradient

This commit is contained in:
Joshua Seigler 2016-06-26 14:42:05 -04:00
parent b1e5fababa
commit 141509d21c

View file

@ -92,29 +92,38 @@ foreach ($chartData as $x => $y) {
'; ';
} }
$numLabels = floor($height / 50); $numLabels = floor($height / 25);
$labelModulation = 2 * 10 ** (1 + floor(-log($yRange / $numLabels, 10))); $labelModulation = 10 ** (1 + floor(-log($yRange / $numLabels, 10)));// / 5;
$labelInterval = round($yRange / $numLabels * $labelModulation) / $labelModulation; $labelInterval = ceil($yRange / $numLabels * $labelModulation) / $labelModulation;
// Top and bottom grid lines
$gridLines = $gridLines =
"M0,0 ".$width.",0 "M0,0 ".$width.",0
M0,".$height.",".$width.",".$height." M0,".$height.",".$width.",".$height."
"; ";
// Top and bottom grid labels
$gridText = $gridText =
'<text x="-4" y="4">'.labelFormat($yMax).'</text>' . '<text x="-4" y="4">'.labelFormat($yMax).'</text>' .
'<text x="-4" y="'.($height + 4).'">'.labelFormat($yMin).'</text>'; '<text x="-4" y="'.($height + 4).'">'.labelFormat($yMin).'</text>';
// 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 ( for (
$labelY = $yMin + 0.5 * $labelInterval - fmod($yMin + 0.5 * $labelInterval , $labelInterval) + $labelInterval; $labelY = $yMin - fmod($yMin, $labelInterval) + $labelInterval;
$labelY < $yMax - 0.5 * $labelInterval; $labelY < $yMax;
$labelY += $labelInterval $labelY += $labelInterval
) { ) {
$labelHeight = transformY($labelY); $labelHeight = transformY($labelY);
$gridLines .= "M0,".$labelHeight." ".$width.",".$labelHeight." $gridLines .= "M0,".$labelHeight." ".$width.",".$labelHeight."
"; ";
if (
$labelY < $yMax - 0.4 * $labelInterval &&
$labelY > $yMin + 0.4 * $labelInterval
) {
$gridText .= '<text x="-4" y="'.($labelHeight + 4).'">'.labelFormat($labelY).'</text>'; $gridText .= '<text x="-4" y="'.($labelHeight + 4).'">'.labelFormat($labelY).'</text>';
}
} }
// in case some dingbat has PHP short tags enabled // in case some dingbat has PHP short tags enabled
@ -133,8 +142,8 @@ echo '<'.'?xml version="1.0" standalone="no"?'.'>';
<circle cx="1" cy="1" r="1" style="stroke: none; fill:#000000;"/> <circle cx="1" cy="1" r="1" style="stroke: none; fill:#000000;"/>
</marker> </marker>
<linearGradient id="fadeFromNothing" x1="0%" y1="0%" x2="100%" y2="0%"> <linearGradient id="fadeFromNothing" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stop-color="#1C75BC" stop-opacity="0"></stop> <stop offset="0.5%" stop-color="#1C75BC" stop-opacity="0"></stop>
<stop offset="2.5%" stop-color="#1C75BC" stop-opacity="1"></stop> <stop offset="5%" stop-color="#1C75BC" stop-opacity="1"></stop>
<stop offset="100%" stop-color="#1C75BC" stop-opacity="1"></stop> <stop offset="100%" stop-color="#1C75BC" stop-opacity="1"></stop>
</linearGradient> </linearGradient>
<style type="text/css"><![CDATA[ <style type="text/css"><![CDATA[