Author: Kore Nordmann
Date: 2007-04-12 16:54:35 +0200 (Thu, 12 Apr 2007)
New Revision: 4872

Log:
- Added feature #10017: Plot whole months on date axis respecting their
  different length

Modified:
   trunk/Graph/ChangeLog
   trunk/Graph/src/axis/date.php
   trunk/Graph/tests/data/compare/ezcGraphDateAxisTest_testMonthInterval1.svg
   trunk/Graph/tests/data/compare/ezcGraphDateAxisTest_testMonthInterval2.svg
   trunk/Graph/tests/data/compare/ezcGraphDateAxisTest_testMonthInterval3.svg

Modified: trunk/Graph/ChangeLog
===================================================================
--- trunk/Graph/ChangeLog       2007-04-12 12:45:42 UTC (rev 4871)
+++ trunk/Graph/ChangeLog       2007-04-12 14:54:35 UTC (rev 4872)
@@ -29,6 +29,8 @@
 - Fixed issue #10599: Pie chart label formattig callback only accepts callback
   functions but neither static nor non static methods.
 - Added feature #10470: Add support for format callback functions on all axis
+- Added feature #10017: Plot whole months on date axis respecting their
+  different length
 
 1.0 - Monday 18 December 2006
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Modified: trunk/Graph/src/axis/date.php
===================================================================
--- trunk/Graph/src/axis/date.php       2007-04-12 12:45:42 UTC (rev 4871)
+++ trunk/Graph/src/axis/date.php       2007-04-12 14:54:35 UTC (rev 4872)
@@ -309,7 +309,32 @@
      */
     public function calculateMinimum( $min, $max )
     {
-        $this->properties['startDate'] = $this->calculateLowerNiceDate( $min, 
$this->interval );
+        if ( $this->properties['endDate'] === false )
+        {
+            $this->properties['startDate'] = $this->calculateLowerNiceDate( 
$min, $this->interval );
+        }
+        else
+        {
+            $this->properties['startDate'] = $this->properties['endDate'];
+
+            while ( $this->properties['startDate'] > $min )
+            {
+                switch ( $this->interval )
+                {
+                    case self::MONTH:
+                        $this->properties['startDate'] = strtotime( '-1 
month', $this->properties['startDate'] );
+                        break;
+                    case self::YEAR:
+                        $this->properties['startDate'] = strtotime( '-1 year', 
$this->properties['startDate'] );
+                        break;
+                    case self::DECADE:
+                        $this->properties['startDate'] = strtotime( '-10 
years', $this->properties['startDate'] );
+                        break;
+                    default:
+                        $this->properties['startDate'] -= $this->interval;
+                }
+            }
+        }
     }
 
     /**
@@ -329,7 +354,20 @@
 
         while ( $this->properties['endDate'] < $max )
         {
-            $this->properties['endDate'] += $this->interval;
+            switch ( $this->interval )
+            {
+                case self::MONTH:
+                    $this->properties['endDate'] = strtotime( '+1 month', 
$this->properties['endDate'] );
+                    break;
+                case self::YEAR:
+                    $this->properties['endDate'] = strtotime( '+1 year', 
$this->properties['endDate'] );
+                    break;
+                case self::DECADE:
+                    $this->properties['endDate'] = strtotime( '+10 years', 
$this->properties['endDate'] );
+                    break;
+                default:
+                    $this->properties['endDate'] += $this->interval;
+            }
         }
     }
 
@@ -471,6 +509,51 @@
     }
 
     /**
+     * Return array of steps on this axis
+     * 
+     * @return array( ezcGraphAxisStep )
+     */
+    public function getSteps()
+    {
+        $steps = array();
+
+        $start = $this->properties['startDate'];
+        $end = $this->properties['endDate'];
+        $distance = $end - $start;
+
+        $step = 0;
+        for ( $time = $start; $time <= $end; )
+        {
+            $steps[] = new ezcGraphAxisStep(
+                ( $time - $start ) / $distance,
+                $this->interval / $distance,
+                $this->getLabel( $step++ ),
+                array(),
+                $step === 1,
+                $time >= $end
+            );
+
+            switch ( $this->interval )
+            {
+                case self::MONTH:
+                    $time = strtotime( '+1 month', $time );
+                    break;
+                case self::YEAR:
+                    $time = strtotime( '+1 year', $time );
+                    break;
+                case self::DECADE:
+                    $time = strtotime( '+10 years', $time );
+                    break;
+                default:
+                    $time += $this->interval;
+                    break;
+            }
+        }
+
+        return $steps;
+    }
+
+    /**
      * Is zero step
      *
      * Returns true if the given step is the one on the initial axis position

Modified: 
trunk/Graph/tests/data/compare/ezcGraphDateAxisTest_testMonthInterval1.svg
===================================================================
(Binary files differ)

Modified: 
trunk/Graph/tests/data/compare/ezcGraphDateAxisTest_testMonthInterval2.svg
===================================================================
(Binary files differ)

Modified: 
trunk/Graph/tests/data/compare/ezcGraphDateAxisTest_testMonthInterval3.svg
===================================================================
(Binary files differ)

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

Reply via email to