Author: Kore Nordmann
Date: 2006-06-13 19:30:30 +0200 (Tue, 13 Jun 2006)
New Revision: 3128

Log:
- Added test and implementation for exclusive zero values

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 16:27:22 UTC (rev 3127)
+++ trunk/Graph/src/axis/numeric.php    2006-06-13 17:30:30 UTC (rev 3128)
@@ -213,8 +213,15 @@
         // Prevent division by zero, when min == max
         if ( $this->minValue == $this->maxValue )
         {
-            $this->minValue -= ( $this->minValue / 10 );
-            $this->maxValue += ( $this->maxValue / 10 );
+            if ( $this->minValue == 0 )
+            {
+                $this->maxValue = 1;
+            }
+            else
+            {
+                $this->minValue -= ( $this->minValue * .1 );
+                $this->maxValue += ( $this->maxValue * .1 );
+            }
         }
 
         // Calculate "nice" values for scaling parameters

Modified: trunk/Graph/tests/numeric_axis_test.php
===================================================================
--- trunk/Graph/tests/numeric_axis_test.php     2006-06-13 16:27:22 UTC (rev 
3127)
+++ trunk/Graph/tests/numeric_axis_test.php     2006-06-13 17:30:30 UTC (rev 
3128)
@@ -906,6 +906,36 @@
             'As value for: minorStep; '
         );
     }
+
+    public function testValueAllZero() {
+        $chart = ezcGraph::create( 'Line' );
+        $chart->sample = array( 2000 => 0, 0 );
+        $chart->render( 500, 200 );
+
+        $this->assertEquals(
+            0.,
+            $chart->Y_axis->min,
+            'As value for: min; '
+        );
+
+        $this->assertEquals(
+            1.,
+            $chart->Y_axis->max,
+            'As value for: max; '
+        );
+
+        $this->assertEquals(
+            .25,
+            $chart->Y_axis->majorStep,
+            'As value for: majorStep; '
+        );
+
+        $this->assertEquals(
+            .05,
+            $chart->Y_axis->minorStep,
+            'As value for: minorStep; '
+        );
+    }
 }
 
 ?>

-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to