diff options
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | src/axis/numeric.php | 5 | ||||
-rw-r--r-- | tests/numeric_axis_test.php | 34 |
3 files changed, 40 insertions, 1 deletions
@@ -2,6 +2,8 @@ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - Implemented feature #14400: Add shortcut to set background color +- Fixed #14651: Handle floor() floating point inaccuracies in numneric axis + step evaluation 1.4.1 - Monday 09 February 2009 diff --git a/src/axis/numeric.php b/src/axis/numeric.php index 43a4fe8..19ecf96 100644 --- a/src/axis/numeric.php +++ b/src/axis/numeric.php @@ -383,7 +383,10 @@ class ezcGraphChartElementNumericAxis extends ezcGraphChartElementAxis // 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 ) + $quotient = ( $this->properties['max'] - $this->properties['min'] ) / $this->properties['majorStep']; + $quotient = abs( $quotient - floor( $quotient ) ); + if ( ( $quotient >= .00001 ) && + ( abs( $quotient - 1 ) >= .00001 ) ) { throw new ezcGraphInvalidStepSizeException( "The difference between minimum and maximum value is not a multiplier of the major step size." ); } diff --git a/tests/numeric_axis_test.php b/tests/numeric_axis_test.php index ca594c7..e7f73e9 100644 --- a/tests/numeric_axis_test.php +++ b/tests/numeric_axis_test.php @@ -637,6 +637,40 @@ class ezcGraphNumericAxisTest extends ezcTestCase ); } + public function testMixedAutomagicAndManualScaling11() + { + $chart = new ezcGraphLineChart(); + $chart->data['sample'] = new ezcGraphArrayDataSet( array( "1.2" => 3, "1.25" => 1 ) ); + $chart->yAxis->min = 1.175; + $chart->yAxis->max = 1.275; + $chart->yAxis->majorStep = 0.025; + $chart->render( 500, 200 ); + + $this->assertEquals( + 1.175, + $chart->yAxis->min, + 'As value for: min; ' + ); + + $this->assertEquals( + 1.275, + $chart->yAxis->max, + 'As value for: max; ' + ); + + $this->assertEquals( + 0.025, + $chart->yAxis->majorStep, + 'As value for: majorStep; ' + ); + + $this->assertEquals( + .005, + $chart->yAxis->minorStep, + 'As value for: minorStep; ' + ); + } + public function testMixedAutomagicAndManualScalingStepSizeFailure1() { $chart = new ezcGraphLineChart(); |