summaryrefslogtreecommitdiffstats
path: root/src/axis
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-06-08 13:17:08 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-06-08 13:17:08 +0000
commitcb55e4811f591b3db7f85519d500b4a0cfd88bf5 (patch)
tree7c9d08c3c03362565889b2f3d9548eb1a544f255 /src/axis
parent2a50296ac7f6ff7c615baf8cbbf667b1ed509106 (diff)
downloadzetacomponents-graph-cb55e4811f591b3db7f85519d500b4a0cfd88bf5.zip
zetacomponents-graph-cb55e4811f591b3db7f85519d500b4a0cfd88bf5.tar.gz
- Handle Much data points with labeled axis
Diffstat (limited to 'src/axis')
-rw-r--r--src/axis/labeled.php43
1 files changed, 39 insertions, 4 deletions
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
{
OpenPOWER on IntegriCloud