From a233c63b7379fe04219b5d666877e71dec3ba9e0 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 13 Dec 2015 00:09:38 -0600 Subject: Add option to bound fill between the current dataset and the previous dataset on radar plots --- src/charts/radar.php | 19 +++++++++++++++++++ src/datasets/base.php | 9 +++++++++ src/interfaces/radar_renderer.php | 2 ++ src/renderer/2d.php | 20 ++++++++++++++++---- 4 files changed, 46 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/charts/radar.php b/src/charts/radar.php index b7bd820..c1f52e1 100644 --- a/src/charts/radar.php +++ b/src/charts/radar.php @@ -296,6 +296,7 @@ class ezcGraphRadarChart extends ezcGraphChart // Display data $this->elements['axis']->position = ezcGraph::TOP; + $prevDataSetPoints = array(); foreach ( $this->data as $datasetName => $data ) { --$nr; @@ -315,8 +316,11 @@ class ezcGraphRadarChart extends ezcGraphChart $fillColor = null; } + $prevDataSetBounded = $data->boundFillToPreviousDataSet; + // Draw lines for dataset $lastPoint = false; + $lastInnerPoint = false; foreach ( $data as $key => $value ) { $point = new ezcGraphCoordinate( @@ -336,6 +340,16 @@ class ezcGraphRadarChart extends ezcGraphChart ); // */ + if ($prevDataSetBounded && array_key_exists($key, $prevDataSetPoints)) { + $innerPoint = $prevDataSetPoints[$key]; + } + else { + $innerPoint = new ezcGraphCoordinate( + 0, + 0 + ); + } + $renderer->drawRadarDataLine( $boundings, new ezcGraphContext( $datasetName, $key, $data->url[$key] ), @@ -343,6 +357,8 @@ class ezcGraphRadarChart extends ezcGraphChart clone $center, ( $lastPoint === false ? $point : $lastPoint ), $point, + $innerPoint, + ( $lastInnerPoint === false ? $innerPoint : $lastInnerPoint ), $nr, $count, $data->symbol[$key], @@ -351,7 +367,10 @@ class ezcGraphRadarChart extends ezcGraphChart $this->options->lineThickness ); + $prevDataSetPoints[$key] = $point; + $lastPoint = $point; + $lastInnerPoint = $innerPoint; } } } diff --git a/src/datasets/base.php b/src/datasets/base.php index 219b3f9..5dc9ae6 100644 --- a/src/datasets/base.php +++ b/src/datasets/base.php @@ -40,6 +40,10 @@ * @property mixed $fillLine * Interpretation depends on underlying chart type * @see chart type fillLines option for details + * @property bool $boundFillToPreviousDataSet + * Only fill the region between the current data set + * and the previous data set. Only works for radar + * plots at this time. @see $fillLine property. * @property int $displayType * Display type of chart data * @property string $url @@ -114,6 +118,7 @@ abstract class ezcGraphDataSet implements ArrayAccess, Iterator, Countable $this->properties['highlight']->default = false; $this->properties['fillLine'] = false; + $this->properties['boundFillToPreviousDataSet'] = false; } /** @@ -168,6 +173,10 @@ abstract class ezcGraphDataSet implements ArrayAccess, Iterator, Countable : (int) $propertyValue ); break; + case 'boundFillToPreviousDataSet': + $this->properties[$propertyName] = $propertyValue; + break; + default: throw new ezcBasePropertyNotFoundException( $propertyName ); break; diff --git a/src/interfaces/radar_renderer.php b/src/interfaces/radar_renderer.php index cb2697b..016c857 100644 --- a/src/interfaces/radar_renderer.php +++ b/src/interfaces/radar_renderer.php @@ -58,6 +58,8 @@ interface ezcGraphRadarRenderer ezcGraphCoordinate $center, ezcGraphCoordinate $start, ezcGraphCoordinate $end, + ezcGraphCoordinate $fillStart, + ezcGraphCoordinate $fillEnd, $dataNumber = 1, $dataCount = 1, $symbol = ezcGraph::NO_SYMBOL, diff --git a/src/renderer/2d.php b/src/renderer/2d.php index 9793e0a..3fd7812 100644 --- a/src/renderer/2d.php +++ b/src/renderer/2d.php @@ -884,6 +884,8 @@ class ezcGraphRenderer2d ezcGraphCoordinate $center, ezcGraphCoordinate $start, ezcGraphCoordinate $end, + ezcGraphCoordinate $fillStart, + ezcGraphCoordinate $fillEnd, $dataNumber = 1, $dataCount = 1, $symbol = ezcGraph::NO_SYMBOL, @@ -905,6 +907,18 @@ class ezcGraphRenderer2d $end->x * 2 * M_PI, $end->y ); + $fillStart = $this->getCoordinateFromAngleAndRadius( + $boundings, + $center, + $fillStart->x * 2 * M_PI, + $fillStart->y + ); + $fillEnd = $this->getCoordinateFromAngleAndRadius( + $boundings, + $center, + $fillEnd->x * 2 * M_PI, + $fillEnd->y + ); // Fill line if ( $fillColor !== null ) @@ -913,10 +927,8 @@ class ezcGraphRenderer2d array( $start, $end, - new ezcGraphCoordinate( - $boundings->x0 + $center->x, - $boundings->y0 + $center->y - ), + $fillStart, + $fillEnd ), $fillColor, true -- cgit v1.1