summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/charts/line.php52
-rw-r--r--src/exceptions/unregular_steps.php25
-rw-r--r--src/graph_autoload.php1
3 files changed, 62 insertions, 16 deletions
diff --git a/src/charts/line.php b/src/charts/line.php
index f58d1c6..4ba9c52 100644
--- a/src/charts/line.php
+++ b/src/charts/line.php
@@ -162,6 +162,8 @@ class ezcGraphLineChart extends ezcGraphChart
$count[$data->displayType->default]++;
}
+ $checkedRegularSteps = false;
+
// Display data
foreach ( $this->data as $datasetName => $data )
{
@@ -227,23 +229,41 @@ class ezcGraphLineChart extends ezcGraphChart
}
break;
case ezcGraph::BAR:
- // @TODO:
- // - Use getSteps() to determine bar width
- // - throw Exception on unregular step width on x axis
- $barCount = (
- ( count ( $data ) - 1 ) > $this->elements['xAxis']->getMajorStepCount() ?
- ( $this->elements['xAxis']->getMajorStepCount() + 1 ) * ( $this->elements['xAxis']->getMinorStepCount() - 1 ) :
- $this->elements['xAxis']->getMajorStepCount()
- );
-
- $width = $this->elements['xAxis']->axisLabelRenderer->modifyChartDataPosition(
- $this->elements['yAxis']->axisLabelRenderer->modifyChartDataPosition(
- new ezcGraphCoordinate(
- ( $boundings->x1 - $boundings->x0 ) / $barCount,
- 0
+ if ( $checkedRegularSteps === false )
+ {
+ $steps = $this->elements['xAxis']->getSteps();
+
+ $stepWidth = null;
+ foreach ( $steps as $step )
+ {
+ if ( $stepWidth === null )
+ {
+ $stepWidth = $step->width;
+ }
+ elseif ( $step->width !== $stepWidth )
+ {
+ throw new ezcGraphUnregularStepsException();
+ }
+ }
+
+ $step = reset( $steps );
+ if ( count( $step->childs ) )
+ {
+ // Keep this for BC reasons
+ $barCount = ( $this->elements['xAxis']->getMajorStepCount() + 1 ) * ( $this->elements['xAxis']->getMinorStepCount() - 1 );
+ $stepWidth = 1 / $barCount;
+ }
+
+ $checkedRegularSteps = true;
+ $width = $this->elements['xAxis']->axisLabelRenderer->modifyChartDataPosition(
+ $this->elements['yAxis']->axisLabelRenderer->modifyChartDataPosition(
+ new ezcGraphCoordinate(
+ ( $boundings->x1 - $boundings->x0 ) * $stepWidth,
+ 0
+ )
)
- )
- )->x;
+ )->x;
+ }
foreach ( $data as $key => $value )
{
diff --git a/src/exceptions/unregular_steps.php b/src/exceptions/unregular_steps.php
new file mode 100644
index 0000000..12e9dad
--- /dev/null
+++ b/src/exceptions/unregular_steps.php
@@ -0,0 +1,25 @@
+<?php
+/**
+ * File containing the ezcGraphUnregularStepsException class
+ *
+ * @package Graph
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Exception thrown when a bar chart shouls be rendered on an axis using
+ * unregular step sizes.
+ *
+ * @package Graph
+ * @version //autogen//
+ */
+class ezcGraphUnregularStepsException extends ezcGraphException
+{
+ public function __construct()
+ {
+ parent::__construct( "Bar charts do not support axis with unregualr steps sizes." );
+ }
+}
+
+?>
diff --git a/src/graph_autoload.php b/src/graph_autoload.php
index 7fbb6aa..e7af02a 100644
--- a/src/graph_autoload.php
+++ b/src/graph_autoload.php
@@ -24,6 +24,7 @@ return array(
'ezcGraphPieChartOptions' => 'Graph/options/pie_chart.php',
'ezcGraphLineChartOptions' => 'Graph/options/line_chart.php',
'ezcGraphInvalidImageFileException' => 'Graph/exceptions/invalid_image_file.php',
+ 'ezcGraphUnregularStepsException' => 'Graph/exceptions/unregular_steps.php',
'ezcGraphChartDataContainer' => 'Graph/data_container/base.php',
'ezcGraphChartSingleDataContainer' => 'Graph/data_container/single.php',
OpenPOWER on IntegriCloud