From cb55e4811f591b3db7f85519d500b4a0cfd88bf5 Mon Sep 17 00:00:00 2001 From: Kore Nordmann Date: Thu, 8 Jun 2006 13:17:08 +0000 Subject: - Handle Much data points with labeled axis --- src/axis/labeled.php | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'src/axis') diff --git a/src/axis/labeled.php b/src/axis/labeled.php index b6e0960..5a4f742 100644 --- a/src/axis/labeled.php +++ b/src/axis/labeled.php @@ -22,6 +22,19 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis */ protected $labels = array(); + /** + * Reduced amount of labels which will be displayed in the chart + * + * @var array + */ + protected $displayedLabels = array(); + + /** + * Maximum count of labels which can be displayed on one axis + * @TODO: Perhaps base this on the chart size + */ + const MAX_LABEL_COUNT = 10; + protected function increaseKeys( $array, $startKey ) { foreach ( $array as $key => $value ) @@ -85,7 +98,29 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis */ public function calculateAxisBoundings() { - return true; + $labelCount = count( $this->labels ) - 1; + if ( $labelCount <= self::MAX_LABEL_COUNT ) + { + $this->displayedLabels = $this->labels; + return true; + } + + for ( $div = self::MAX_LABEL_COUNT; $div > 0; --$div ) + { + if ( ( $labelCount % $div ) === 0 ) + { + $step = $labelCount / $div; + foreach ( $this->labels as $nr => $label ) + { + if ( ( $nr % $step ) === 0 ) + { + $this->displayedLabels[] = $label; + } + } + + return true; + } + } } /** @@ -158,7 +193,7 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis */ protected function getMajorStepCount() { - return count( $this->labels ) - 1; + return count( $this->displayedLabels ) - 1; } /** @@ -301,9 +336,9 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis */ protected function getLabel( $step ) { - if ( isset( $this->labels[$step] ) ) + if ( isset( $this->displayedLabels[$step] ) ) { - return $this->labels[$step]; + return $this->displayedLabels[$step]; } else { -- cgit v1.1