From 0c5ab3e9bb12968e8b594f7144732bdc2b0236ed Mon Sep 17 00:00:00 2001 From: Kore Nordmann Date: Wed, 10 Sep 2008 08:11:05 +0000 Subject: - Fixed issue #13595: majorStep overridden if min and max are both set --- ChangeLog | 1 + design/class_diagram.png | Bin 2154549 -> 2148273 bytes src/axis/numeric.php | 17 ++++++++- src/exceptions/invalid_step_size.php | 32 ++++++++++++++++ src/graph_autoload.php | 1 + tests/numeric_axis_test.php | 70 +++++++++++++++++++++++++++++++++++ 6 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 src/exceptions/invalid_step_size.php 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 Binary files a/design/class_diagram.png and b/design/class_diagram.png 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 @@ + 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 } } } + ?> -- cgit v1.1