Author: kn
Date: Mon Jan  7 10:05:00 2008
New Revision: 7082

Log:
- Fixed issue #12295: Broken automatic scaling with manually set min value,
  not divisible by major step

Modified:
    trunk/Graph/ChangeLog
    trunk/Graph/src/axis/numeric.php
    trunk/Graph/tests/numeric_axis_test.php

Modified: trunk/Graph/ChangeLog
==============================================================================
--- trunk/Graph/ChangeLog [iso-8859-1] (original)
+++ trunk/Graph/ChangeLog [iso-8859-1] Mon Jan  7 10:05:00 2008
@@ -3,6 +3,8 @@
 
 - Implemented feature #9407: Cairo driver
 - Fixed issue #12254: Bad property-check for strokeLineJoin in SVG driver
+- Fixed issue #12295: Broken automatic scaling with manually set min value,
+  not divisible by major step
 
 1.2 - Monday 17 December 2007
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Modified: trunk/Graph/src/axis/numeric.php
==============================================================================
--- trunk/Graph/src/axis/numeric.php [iso-8859-1] (original)
+++ trunk/Graph/src/axis/numeric.php [iso-8859-1] Mon Jan  7 10:05:00 2008
@@ -152,7 +152,20 @@
      */
     protected function calculateMinimum( $min, $max )
     {
-        $this->properties['min'] = floor( $min / 
$this->properties['majorStep'] ) * $this->properties['majorStep'];
+        if ( $this->properties['max'] === null )
+        {
+            $this->properties['min'] = floor( $min / 
$this->properties['majorStep'] ) * $this->properties['majorStep'];
+        }
+        else
+        {
+            $calculatedMin = $this->properties['max'];
+            
+            do {
+                $calculatedMin -= $this->properties['majorStep'];
+            } while ( $calculatedMin > $min );
+
+            $this->properties['min'] = $calculatedMin;
+        }
     }
 
     /**
@@ -165,7 +178,13 @@
      */
     protected function calculateMaximum( $min, $max )
     {
-        $this->properties['max'] = ceil( $max / $this->properties['majorStep'] 
) * $this->properties['majorStep'];
+        $calculatedMax = $this->properties['min'];
+        
+        do {
+            $calculatedMax += $this->properties['majorStep'];
+        } while ( $calculatedMax < $max );
+
+        $this->properties['max'] = $calculatedMax;
     }
 
     /**

Modified: trunk/Graph/tests/numeric_axis_test.php
==============================================================================
--- trunk/Graph/tests/numeric_axis_test.php [iso-8859-1] (original)
+++ trunk/Graph/tests/numeric_axis_test.php [iso-8859-1] Mon Jan  7 10:05:00 
2008
@@ -488,6 +488,72 @@
         );
     }
 
+    public function testMixedAutomagicAndManualScaling7()
+    {
+        $chart = new ezcGraphLineChart();
+        $chart->data['sample'] = new ezcGraphArrayDataSet( array( 113.5, 1800, 
-45 ) );
+        $chart->yAxis->majorStep = 500;
+        $chart->yAxis->min = -100;
+        $chart->render( 500, 200 );
+
+        $this->assertEquals(
+            -100,
+            $chart->yAxis->min,
+            'As value for: min; '
+        );
+
+        $this->assertEquals(
+            1900,
+            $chart->yAxis->max,
+            'As value for: max; '
+        );
+
+        $this->assertEquals(
+            500,
+            $chart->yAxis->majorStep,
+            'As value for: majorStep; '
+        );
+
+        $this->assertEquals(
+            100,
+            $chart->yAxis->minorStep,
+            'As value for: minorStep; '
+        );
+    }
+
+    public function testMixedAutomagicAndManualScaling8()
+    {
+        $chart = new ezcGraphLineChart();
+        $chart->data['sample'] = new ezcGraphArrayDataSet( array( 113.5, 1800, 
-45 ) );
+        $chart->yAxis->majorStep = 500;
+        $chart->yAxis->max = 1900;
+        $chart->render( 500, 200 );
+
+        $this->assertEquals(
+            -100,
+            $chart->yAxis->min,
+            'As value for: min; '
+        );
+
+        $this->assertEquals(
+            1900,
+            $chart->yAxis->max,
+            'As value for: max; '
+        );
+
+        $this->assertEquals(
+            500,
+            $chart->yAxis->majorStep,
+            'As value for: majorStep; '
+        );
+
+        $this->assertEquals(
+            100,
+            $chart->yAxis->minorStep,
+            'As value for: minorStep; '
+        );
+    }
+
     public function testPositionLeft()
     {
         $chart = new ezcGraphLineChart();


-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to