summaryrefslogtreecommitdiffstats
path: root/src/axis/date.php
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2007-04-12 14:54:35 +0000
committerKore Nordmann <github@kore-nordmann.de>2007-04-12 14:54:35 +0000
commit64efa3602ec982a051f8209aa9baa436007d8dae (patch)
treeab7fe4b30457e272f7de4d58bfaaa8bc2345d1c0 /src/axis/date.php
parente3c691c66bc360caae052a7387a258ac8af0c2a1 (diff)
downloadzetacomponents-graph-64efa3602ec982a051f8209aa9baa436007d8dae.zip
zetacomponents-graph-64efa3602ec982a051f8209aa9baa436007d8dae.tar.gz
- Added feature #10017: Plot whole months on date axis respecting their
different length
Diffstat (limited to 'src/axis/date.php')
-rw-r--r--src/axis/date.php87
1 files changed, 85 insertions, 2 deletions
diff --git a/src/axis/date.php b/src/axis/date.php
index 9f72306..38508bd 100644
--- a/src/axis/date.php
+++ b/src/axis/date.php
@@ -309,7 +309,32 @@ class ezcGraphChartElementDateAxis extends ezcGraphChartElementAxis
*/
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 @@ class ezcGraphChartElementDateAxis extends ezcGraphChartElementAxis
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 @@ class ezcGraphChartElementDateAxis extends ezcGraphChartElementAxis
}
/**
+ * 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
OpenPOWER on IntegriCloud