summaryrefslogtreecommitdiffstats
path: root/src/charts/line.php
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-06-14 15:34:12 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-06-14 15:34:12 +0000
commitccd7c75ecbaa8f13af316b14d7a4162b6a54819d (patch)
tree3617484fa52c3552aad97845f787c5ffbc43f487 /src/charts/line.php
parent67864e582b01d121626bb3f9b60b45b7181bb1b7 (diff)
downloadzetacomponents-graph-ccd7c75ecbaa8f13af316b14d7a4162b6a54819d.zip
zetacomponents-graph-ccd7c75ecbaa8f13af316b14d7a4162b6a54819d.tar.gz
- Add possibility to use filled line charts
Diffstat (limited to 'src/charts/line.php')
-rw-r--r--src/charts/line.php75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/charts/line.php b/src/charts/line.php
index 9d3d499..60935de 100644
--- a/src/charts/line.php
+++ b/src/charts/line.php
@@ -73,7 +73,15 @@ class ezcGraphLineChart extends ezcGraphChart
{
foreach ( $this->data as $data )
{
+ if ( $this->options->fillLines !== false )
+ {
+ $fillColor = clone $data->color->default;
+ $fillColor->alpha = (int) round( ( 255 - $fillColor->alpha ) * ( $this->options->fillLines / 255 ) );
+ }
+
$lastPoint = false;
+ $lastKey = false;
+ $lastValue = false;
foreach ( $data as $key => $value )
{
$point = new ezcGraphCoordinate(
@@ -81,6 +89,71 @@ class ezcGraphLineChart extends ezcGraphChart
(int) round( $this->elements['Y_axis']->getCoordinate( $boundings, $value ) )
);
+ // Fill the line
+ if ( $lastPoint !== false && $this->options->fillLines !== false )
+ {
+ $axisPosition = (int) round( $this->elements['Y_axis']->getCoordinate( $boundings, false ) );
+
+ $lastAxisPoint = new ezcGraphCoordinate(
+ (int) round( $this->elements['X_axis']->getCoordinate( $boundings, $lastKey ) ),
+ $axisPosition
+ );
+ $axisPoint = new ezcGraphCoordinate(
+ (int) round( $this->elements['X_axis']->getCoordinate( $boundings, $key ) ),
+ $axisPosition
+ );
+
+ if ( $value / abs( $value ) == $lastValue / abs( $lastValue ) )
+ {
+ // Values have the same sign, so that the line do not cross any axes
+ $renderer->drawPolygon(
+ array(
+ $lastPoint,
+ $point,
+ $axisPoint,
+ $lastAxisPoint,
+ ),
+ $fillColor,
+ true
+ );
+ }
+ else
+ {
+ // Draw two polygones to consider cutting point with axis
+ $diffOne = abs( $axisPosition - $lastPoint->y );
+ $diffTwo = abs( $axisPosition - $point->y );
+
+ // Switch values, if first is greater then second
+ $cuttingPosition = $diffOne / ( $diffTwo + $diffOne );
+
+ // Calculate cutting point
+ $cuttingPoint = new ezcGraphCoordinate(
+ (int) round( $lastAxisPoint->x + ( $axisPoint->x - $lastAxisPoint->x ) * $cuttingPosition ),
+ $axisPosition
+ );
+
+ // Finally draw polygons
+ $renderer->drawPolygon(
+ array(
+ $lastPoint,
+ $cuttingPoint,
+ $lastAxisPoint,
+ ),
+ $fillColor,
+ true
+ );
+ $renderer->drawPolygon(
+ array(
+ $point,
+ $cuttingPoint,
+ $axisPoint,
+ ),
+ $fillColor,
+ true
+ );
+ }
+ }
+
// Draw line
if ( $lastPoint !== false )
{
@@ -113,6 +186,8 @@ class ezcGraphLineChart extends ezcGraphChart
}
$lastPoint = $point;
+ $lastValue = $value;
+ $lastKey = $key;
}
}
}
OpenPOWER on IntegriCloud