summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2008-09-10 08:11:05 +0000
committerKore Nordmann <github@kore-nordmann.de>2008-09-10 08:11:05 +0000
commit0c5ab3e9bb12968e8b594f7144732bdc2b0236ed (patch)
treef2d640e08698616ea3c4f1bebc9062a03ebc868a
parent9a594470d0d84f5a06c6a5aec21152a34382c45e (diff)
downloadzetacomponents-graph-0c5ab3e9bb12968e8b594f7144732bdc2b0236ed.zip
zetacomponents-graph-0c5ab3e9bb12968e8b594f7144732bdc2b0236ed.tar.gz
- Fixed issue #13595: majorStep overridden if min and max are both set
-rw-r--r--ChangeLog1
-rw-r--r--design/class_diagram.pngbin2154549 -> 2148273 bytes
-rw-r--r--src/axis/numeric.php17
-rw-r--r--src/exceptions/invalid_step_size.php32
-rw-r--r--src/graph_autoload.php1
-rw-r--r--tests/numeric_axis_test.php70
6 files changed, 120 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index b9350b1..722470e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@
- Fixed issue #13253: Division by zero when trying to render stacked bars.
- Fixed issue #13361: Provided workaround for ext/GD bug:
http://bugs.php.net/45552
+- Fixed issue #13595: majorStep overridden if min and max are both set
1.3 - Monday 16 June 2008
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/design/class_diagram.png b/design/class_diagram.png
index fd20235..92be845 100644
--- a/design/class_diagram.png
+++ b/design/class_diagram.png
Binary files differ
diff --git a/src/axis/numeric.php b/src/axis/numeric.php
index ab709db..11e0877 100644
--- a/src/axis/numeric.php
+++ b/src/axis/numeric.php
@@ -345,7 +345,8 @@ class ezcGraphChartElementNumericAxis extends ezcGraphChartElementAxis
// "nice" number for the steps. Try to find such a nice step size, or
// fall back to a step size, which is just the span divided by 5.
if ( ( $this->properties['min'] !== null ) &&
- ( $this->properties['max'] !== null ) )
+ ( $this->properties['max'] !== null ) &&
+ ( $this->properties['majorStep'] === null ) )
{
$diff = $this->properties['max'] - $this->properties['min'];
$this->calculateMajorStep( $this->properties['minValue'], $this->properties['maxValue'] );
@@ -379,6 +380,20 @@ class ezcGraphChartElementNumericAxis extends ezcGraphChartElementAxis
{
$this->calculateMaximum( $this->properties['minValue'], $this->properties['maxValue'] );
}
+
+ // Check that the major step size matches up with the min and max
+ // values on the axis.
+ if ( ( ( $quotient = ( $this->properties['max'] - $this->properties['min'] ) / $this->properties['majorStep'] ) - floor( $quotient ) ) > .00001 )
+ {
+ throw new ezcGraphInvalidStepSizeException( "The difference between minimum and maximum value is not a multiplier of the major step size." );
+ }
+
+ // Check that the minor step size matches up with major step size on
+ // the axis.
+ if ( ( ( $quotient = $this->properties['majorStep'] / $this->properties['minorStep'] ) - floor( $quotient ) ) > .00001 )
+ {
+ throw new ezcGraphInvalidStepSizeException( "The major step size value is not a multiplier of the minor step size." );
+ }
}
/**
diff --git a/src/exceptions/invalid_step_size.php b/src/exceptions/invalid_step_size.php
new file mode 100644
index 0000000..b7cd855
--- /dev/null
+++ b/src/exceptions/invalid_step_size.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * File containing the ezcGraphInvalidStepSizeException class
+ *
+ * @package Graph
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Exception thrown when the major or minor step size does not divide cleanly
+ * the value span it should be used for.
+ *
+ * @package Graph
+ * @version //autogentag//
+ */
+class ezcGraphInvalidStepSizeException extends ezcGraphException
+{
+ /**
+ * Constructor
+ *
+ * @param string $message
+ * @return void
+ * @ignore
+ */
+ public function __construct( $message )
+ {
+ parent::__construct( "Invalid step size on numeric axis: {$message}." );
+ }
+}
+
+?>
diff --git a/src/graph_autoload.php b/src/graph_autoload.php
index 9f35ccd..5c8ac35 100644
--- a/src/graph_autoload.php
+++ b/src/graph_autoload.php
@@ -21,6 +21,7 @@ return array(
'ezcGraphInvalidDataException' => 'Graph/exceptions/invalid_data.php',
'ezcGraphInvalidDisplayTypeException' => 'Graph/exceptions/invalid_display_type.php',
'ezcGraphInvalidImageFileException' => 'Graph/exceptions/invalid_image_file.php',
+ 'ezcGraphInvalidStepSizeException' => 'Graph/exceptions/invalid_step_size.php',
'ezcGraphMatrixInvalidDimensionsException' => 'Graph/exceptions/invalid_dimensions.php',
'ezcGraphMatrixOutOfBoundingsException' => 'Graph/exceptions/out_of_boundings.php',
'ezcGraphNoDataException' => 'Graph/exceptions/no_data.php',
diff --git a/tests/numeric_axis_test.php b/tests/numeric_axis_test.php
index bfbd123..2e34f3d 100644
--- a/tests/numeric_axis_test.php
+++ b/tests/numeric_axis_test.php
@@ -603,6 +603,75 @@ class ezcGraphNumericAxisTest extends ezcTestCase
);
}
+ public function testMixedAutomagicAndManualScaling10()
+ {
+ $chart = new ezcGraphLineChart();
+ $chart->data['sample'] = new ezcGraphArrayDataSet( array( 2000 => 1045, 1300, 1012, 1450 ) );
+ $chart->yAxis->min = 0;
+ $chart->yAxis->max = 2000;
+ $chart->yAxis->majorStep = 250;
+ $chart->render( 500, 200 );
+
+ $this->assertEquals(
+ 0.,
+ $chart->yAxis->min,
+ 'As value for: min; '
+ );
+
+ $this->assertEquals(
+ 2000.,
+ $chart->yAxis->max,
+ 'As value for: max; '
+ );
+
+ $this->assertEquals(
+ 250.,
+ $chart->yAxis->majorStep,
+ 'As value for: majorStep; '
+ );
+
+ $this->assertEquals(
+ 50.,
+ $chart->yAxis->minorStep,
+ 'As value for: minorStep; '
+ );
+ }
+
+ public function testMixedAutomagicAndManualScalingStepSizeFailure1()
+ {
+ $chart = new ezcGraphLineChart();
+ $chart->data['sample'] = new ezcGraphArrayDataSet( array( 2000 => 1045, 1300, 1012, 1450 ) );
+ $chart->yAxis->min = 0;
+ $chart->yAxis->max = 2000;
+ $chart->yAxis->majorStep = 300;
+
+ try
+ {
+ $chart->render( 500, 200 );
+ $this->fail( 'Expected ezcGraphInvalidStepSizeException.' );
+ }
+ catch ( ezcGraphInvalidStepSizeException $e )
+ { /* Expected */ }
+ }
+
+ public function testMixedAutomagicAndManualScalingStepSizeFailure2()
+ {
+ $chart = new ezcGraphLineChart();
+ $chart->data['sample'] = new ezcGraphArrayDataSet( array( 2000 => 1045, 1300, 1012, 1450 ) );
+ $chart->yAxis->min = 0;
+ $chart->yAxis->max = 2000;
+ $chart->yAxis->majorStep = 250;
+ $chart->yAxis->minorStep = 100;
+
+ try
+ {
+ $chart->render( 500, 200 );
+ $this->fail( 'Expected ezcGraphInvalidStepSizeException.' );
+ }
+ catch ( ezcGraphInvalidStepSizeException $e )
+ { /* Expected */ }
+ }
+
public function testPositionLeft()
{
$chart = new ezcGraphLineChart();
@@ -922,4 +991,5 @@ class ezcGraphNumericAxisTest extends ezcTestCase
}
}
}
+
?>
OpenPOWER on IntegriCloud