Author: Kore Nordmann
Date: 2006-06-13 18:27:22 +0200 (Tue, 13 Jun 2006)
New Revision: 3127
Log:
- Fixed division by zero caused by no amplitude in data
# Thanks to Benoit for reporting this
Modified:
trunk/Graph/src/axis/numeric.php
trunk/Graph/tests/numeric_axis_test.php
Modified: trunk/Graph/src/axis/numeric.php
===================================================================
--- trunk/Graph/src/axis/numeric.php 2006-06-13 07:33:56 UTC (rev 3126)
+++ trunk/Graph/src/axis/numeric.php 2006-06-13 16:27:22 UTC (rev 3127)
@@ -210,6 +210,13 @@
*/
public function calculateAxisBoundings()
{
+ // Prevent division by zero, when min == max
+ if ( $this->minValue == $this->maxValue )
+ {
+ $this->minValue -= ( $this->minValue / 10 );
+ $this->maxValue += ( $this->maxValue / 10 );
+ }
+
// Calculate "nice" values for scaling parameters
if ( $this->majorStep === false )
{
Modified: trunk/Graph/tests/numeric_axis_test.php
===================================================================
--- trunk/Graph/tests/numeric_axis_test.php 2006-06-13 07:33:56 UTC (rev
3126)
+++ trunk/Graph/tests/numeric_axis_test.php 2006-06-13 16:27:22 UTC (rev
3127)
@@ -876,6 +876,36 @@
$chart->renderer = $mockedRenderer;
$chart->render( 500, 200 );
}
+
+ public function testValueZeroAmplitude() {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->sample = array( 2000 => 70, 70, 70, 70 );
+ $chart->render( 500, 200 );
+
+ $this->assertEquals(
+ 60.,
+ $chart->Y_axis->min,
+ 'As value for: min; '
+ );
+
+ $this->assertEquals(
+ 80.,
+ $chart->Y_axis->max,
+ 'As value for: max; '
+ );
+
+ $this->assertEquals(
+ 5.,
+ $chart->Y_axis->majorStep,
+ 'As value for: majorStep; '
+ );
+
+ $this->assertEquals(
+ 1.,
+ $chart->Y_axis->minorStep,
+ 'As value for: minorStep; '
+ );
+ }
}
?>
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components