summaryrefslogtreecommitdiffstats
path: root/src/axis/labeled.php
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2007-03-05 11:03:43 +0000
committerKore Nordmann <github@kore-nordmann.de>2007-03-05 11:03:43 +0000
commitc47be4e29322e2319f33229dd054fb0c24c6b44f (patch)
tree1e2625970b4abcc9882145943f05fbac3e4a88fc /src/axis/labeled.php
parent3565724f24ef7d6989756ee2a3ee70cc37d97a88 (diff)
downloadzetacomponents-graph-c47be4e29322e2319f33229dd054fb0c24c6b44f.zip
zetacomponents-graph-c47be4e29322e2319f33229dd054fb0c24c6b44f.tar.gz
- Implemented #10375: Manually reduce or increase the label count on labeled axis
Diffstat (limited to 'src/axis/labeled.php')
-rw-r--r--src/axis/labeled.php115
1 files changed, 83 insertions, 32 deletions
diff --git a/src/axis/labeled.php b/src/axis/labeled.php
index 9d09ed0..d169d1e 100644
--- a/src/axis/labeled.php
+++ b/src/axis/labeled.php
@@ -11,6 +11,9 @@
* Class to represent a labeled axis. Values on the x axis are considered as
* strings and used in the given order.
*
+ * @property float $labelCount
+ * Define count of displayed labels on the axis
+ *
* @package Graph
* @mainclass
*/
@@ -53,12 +56,45 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis
*/
public function __construct( array $options = array() )
{
+ $this->properties['labelCount'] = null;
+
$this->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer();
parent::__construct( $options );
}
/**
+ * __set
+ *
+ * @param mixed $propertyName
+ * @param mixed $propertyValue
+ * @throws ezcBaseValueException
+ * If a submitted parameter was out of range or type.
+ * @throws ezcBasePropertyNotFoundException
+ * If a the value for the property options is not an instance of
+ * @return void
+ * @ignore
+ */
+ public function __set( $propertyName, $propertyValue )
+ {
+ switch ( $propertyName )
+ {
+ case 'labelCount':
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue <= 1 ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'int > 1' );
+ }
+
+ $this->properties['labelCount'] = (int) $propertyValue;
+ break;
+ default:
+ parent::__set( $propertyName, $propertyValue );
+ break;
+ }
+ }
+
+ /**
* Increase the keys of all elements in the array up from the start key, to
* insert an additional element at the correct position.
*
@@ -138,49 +174,56 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis
return true;
}
- if ( $labelCount <= self::MAX_LABEL_COUNT )
+ if ( $this->properties['labelCount'] === null )
{
- $stepSize = 1 / $labelCount;
-
- foreach ( $this->labels as $nr => $label )
+ if ( $labelCount <= self::MAX_LABEL_COUNT )
{
- $this->steps[] = new ezcGraphAxisStep(
- $stepSize * $nr,
- $stepSize,
- $label,
- array(),
- $nr === 0,
- $nr === $labelCount
- );
- }
+ $stepSize = 1 / $labelCount;
- // @TODO: This line is deprecated and only build for
- // deprecated getLabel()
- $this->displayedLabels = $this->labels;
-
- return true;
- }
+ foreach ( $this->labels as $nr => $label )
+ {
+ $this->steps[] = new ezcGraphAxisStep(
+ $stepSize * $nr,
+ $stepSize,
+ $label,
+ array(),
+ $nr === 0,
+ $nr === $labelCount
+ );
+ }
- for ( $div = self::MAX_LABEL_COUNT; $div > 1; --$div )
- {
- if ( ( $labelCount % $div ) === 0 )
- {
- // @TODO: This part is deprecated and only build for
+ // @TODO: This line is deprecated and only build for
// deprecated getLabel()
- $step = $labelCount / $div;
+ $this->displayedLabels = $this->labels;
- foreach ( $this->labels as $nr => $label )
+ return true;
+ }
+
+ for ( $div = self::MAX_LABEL_COUNT; $div > 1; --$div )
+ {
+ if ( ( $labelCount % $div ) === 0 )
{
- if ( ( $nr % $step ) === 0 )
+ // @TODO: This part is deprecated and only build for
+ // deprecated getLabel()
+ $step = $labelCount / $div;
+
+ foreach ( $this->labels as $nr => $label )
{
- $this->displayedLabels[] = $label;
+ if ( ( $nr % $step ) === 0 )
+ {
+ $this->displayedLabels[] = $label;
+ }
}
- }
- // End of deprecated part
+ // End of deprecated part
- break;
+ break;
+ }
}
}
+ else
+ {
+ $div = false;
+ }
// Build up step array
if ( $div > 2 )
@@ -215,7 +258,15 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis
}
else
{
- $floatStep = $labelCount / ( self::MAX_LABEL_COUNT - 1 );
+ if ( $this->properties['labelCount'] === null )
+ {
+ $floatStep = $labelCount / ( self::MAX_LABEL_COUNT - 1 );
+ }
+ else
+ {
+ $floatStep = $labelCount / min( $labelCount, $this->properties['labelCount'] - 1 );
+ }
+
$position = 0;
$minorStepSize = 1 / $labelCount;
OpenPOWER on IntegriCloud