summaryrefslogtreecommitdiffstats
path: root/src/charts
diff options
context:
space:
mode:
authorTimothy Pearson <tpearson@raptorengineeringinc.com>2015-12-11 16:17:39 -0600
committerTimothy Pearson <tpearson@raptorengineeringinc.com>2015-12-11 16:17:39 -0600
commit825295b8ae3979aff902f485edf00e8e513fb067 (patch)
treea98f438fcfee9b83e4694818384aa34fdc6fe1a2 /src/charts
parent551ab952471befef109c76177ebc0ffa76dbed5e (diff)
downloadzetacomponents-graph-825295b8ae3979aff902f485edf00e8e513fb067.zip
zetacomponents-graph-825295b8ae3979aff902f485edf00e8e513fb067.tar.gz
Enable stacked rendering for horizontal bar chartshoriz-stacked-render
Diffstat (limited to 'src/charts')
-rw-r--r--src/charts/horizontal_bar.php89
1 files changed, 86 insertions, 3 deletions
diff --git a/src/charts/horizontal_bar.php b/src/charts/horizontal_bar.php
index feb9122..9fe700e 100644
--- a/src/charts/horizontal_bar.php
+++ b/src/charts/horizontal_bar.php
@@ -121,7 +121,7 @@ class ezcGraphHorizontalBarChart extends ezcGraphBarChart
// Use inner boundings for drawning chart data
$boundings = $innerBoundings;
- $yAxisNullPosition = $this->elements['xAxis']->getCoordinate( false );
+ $xAxisNullPosition = $this->elements['xAxis']->getCoordinate( false );
// Initialize counters
$nr = array();
@@ -188,6 +188,81 @@ class ezcGraphHorizontalBarChart extends ezcGraphBarChart
// Render depending on display type of dataset
switch ( true )
{
+ case ( $data->displayType->default === ezcGraph::BAR ) &&
+ $this->options->stackBars :
+ // Check if a bar has already been stacked
+ if ( !isset( $stackedValue[(int) ( $point->y * 10000 )][(int) $value > 0] ) )
+ {
+ $start = new ezcGraphCoordinate(
+ $xAxisNullPosition,
+ $point->y
+ );
+
+ $stackedValue[(int) ( $point->y * 10000 )][(int) $value > 0] = $value;
+ }
+ else
+ {
+ $start = $yAxis->axisLabelRenderer->modifyChartDataPosition(
+ $xAxis->axisLabelRenderer->modifyChartDataPosition(
+ new ezcGraphCoordinate(
+ $xAxis->getCoordinate( $stackedValue[(int) ( $point->y * 10000 )][(int) $value > 0] ),
+ $yAxis->getCoordinate( $key )
+ )
+ )
+ );
+
+ $point = $yAxis->axisLabelRenderer->modifyChartDataPosition(
+ $xAxis->axisLabelRenderer->modifyChartDataPosition(
+ new ezcGraphCoordinate(
+ $xAxis->getCoordinate( $stackedValue[(int) ( $point->y * 10000 )][(int) $value > 0] += $value ),
+ $yAxis->getCoordinate( $key )
+ )
+ )
+ );
+ }
+
+ // Force one symbol for each stacked bar
+ if ( !isset( $stackedSymbol[(int) ( $point->y * 10000 )] ) )
+ {
+ $stackedSymbol[(int) ( $point->y * 10000 )] = $data->symbol[$key];
+ }
+
+ // Store stacked value for next iteration
+ $side = ( $point->x == 0 ? 1 : $point->x / abs( $point->x ) );
+ $stacked[(int) ( $point->y * 10000 )][$side] = $point;
+
+ $renderer->drawHorizontalStackedBar(
+ $boundings,
+ new ezcGraphContext( $datasetName, $key, $data->url[$key] ),
+ $data->color->default,
+ $start,
+ $point,
+ $height,
+ $stackedSymbol[(int) ( $point->y * 10000 )],
+ $xAxisNullPosition
+ );
+
+ // Render highlight string if requested
+ if ( $data->highlight[$key] )
+ {
+ $renderer->drawDataHighlightText(
+ $boundings,
+ new ezcGraphContext( $datasetName, $key, $data->url[$key] ),
+ $point,
+ $xAxisNullPosition,
+ $nr[$data->displayType->default],
+ $count[$data->displayType->default],
+ $this->options->highlightFont,
+ ( $data->highlightValue[$key] ? $data->highlightValue[$key] : $value ),
+ $this->options->highlightSize + $this->options->highlightFont->padding * 2,
+ ( $this->options->highlightLines ? $data->color[$key] : null ),
+ ( $this->options->highlightXOffset ? $this->options->highlightXOffset : 0 ),
+ ( $this->options->highlightYOffset ? $this->options->highlightYOffset : 0 ),
+ $height,
+ $data->displayType->default
+ );
+ }
+ break;
case $data->displayType->default === ezcGraph::BAR:
$renderer->drawHorizontalBar(
$boundings,
@@ -198,7 +273,7 @@ class ezcGraphHorizontalBarChart extends ezcGraphBarChart
$nr[$data->displayType->default],
$count[$data->displayType->default],
$data->symbol[$key],
- $yAxisNullPosition
+ $xAxisNullPosition
);
// Render highlight string if requested
@@ -208,7 +283,7 @@ class ezcGraphHorizontalBarChart extends ezcGraphBarChart
$boundings,
new ezcGraphContext( $datasetName, $key, $data->url[$key] ),
$point,
- $yAxisNullPosition,
+ $xAxisNullPosition,
$nr[$data->displayType->default],
$count[$data->displayType->default],
$this->options->highlightFont,
@@ -293,6 +368,14 @@ class ezcGraphHorizontalBarChart extends ezcGraphBarChart
}
}
+ // Also use stacked bar values as base for x axis value span
+ // calculation
+ if ( $this->options->stackBars )
+ {
+ $this->elements['xAxis']->addData( $virtualBarSumDataSet[0] );
+ $this->elements['xAxis']->addData( $virtualBarSumDataSet[1] );
+ }
+
// There should always be something assigned to the main x and y axis.
if ( !$this->elements['xAxis']->initialized ||
!$this->elements['yAxis']->initialized )
OpenPOWER on IntegriCloud