summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2007-04-12 12:45:42 +0000
committerKore Nordmann <github@kore-nordmann.de>2007-04-12 12:45:42 +0000
commite3c691c66bc360caae052a7387a258ac8af0c2a1 (patch)
treeeda7c4184d615f590e20bf142b7dcd24bbe7f20c /src
parent40b5444276af768209c8a6b0df633b150da86ac8 (diff)
downloadzetacomponents-graph-e3c691c66bc360caae052a7387a258ac8af0c2a1.zip
zetacomponents-graph-e3c691c66bc360caae052a7387a258ac8af0c2a1.tar.gz
- Added feature #10470: Add support for format callback functions on all axis
Diffstat (limited to 'src')
-rw-r--r--src/axis/date.php15
-rw-r--r--src/axis/labeled.php15
-rw-r--r--src/axis/logarithmic.php27
-rw-r--r--src/axis/numeric.php15
-rw-r--r--src/element/axis.php16
5 files changed, 81 insertions, 7 deletions
diff --git a/src/axis/date.php b/src/axis/date.php
index bbf2bd4..9f72306 100644
--- a/src/axis/date.php
+++ b/src/axis/date.php
@@ -454,7 +454,20 @@ class ezcGraphChartElementDateAxis extends ezcGraphChartElementAxis
*/
public function getLabel( $step )
{
- return date( $this->properties['dateFormat'], $this->startDate + ( $step * $this->interval ) );
+ if ( $this->properties['labelCallback'] !== null )
+ {
+ return call_user_func_array(
+ $this->properties['labelCallback'],
+ array(
+ date( $this->properties['dateFormat'], $this->startDate + ( $step * $this->interval ) ),
+ $step,
+ )
+ );
+ }
+ else
+ {
+ return date( $this->properties['dateFormat'], $this->startDate + ( $step * $this->interval ) );
+ }
}
/**
diff --git a/src/axis/labeled.php b/src/axis/labeled.php
index d169d1e..131e302 100644
--- a/src/axis/labeled.php
+++ b/src/axis/labeled.php
@@ -167,6 +167,21 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis
{
$this->steps = array();
+ // Apply label format callback function
+ if ( $this->properties['labelCallback'] !== null )
+ {
+ foreach ( $this->labels as $nr => $label )
+ {
+ $this->labels[$nr] = call_user_func_array(
+ $this->properties['labelCallback'],
+ array(
+ $label,
+ $nr
+ )
+ );
+ }
+ }
+
$labelCount = count( $this->labels ) - 1;
if ( $labelCount === 0 )
diff --git a/src/axis/logarithmic.php b/src/axis/logarithmic.php
index 370057d..a697a2d 100644
--- a/src/axis/logarithmic.php
+++ b/src/axis/logarithmic.php
@@ -259,11 +259,28 @@ class ezcGraphChartElementLogarithmicalAxis extends ezcGraphChartElementAxis
*/
public function getLabel( $step )
{
- return sprintf(
- $this->properties['logarithmicalFormatString'],
- $this->properties['base'],
- $this->properties['min'] + ( $step * $this->properties['majorStep'] )
- );
+ if ( $this->properties['labelCallback'] !== null )
+ {
+ return call_user_func_array(
+ $this->properties['labelCallback'],
+ array(
+ sprintf(
+ $this->properties['logarithmicalFormatString'],
+ $this->properties['base'],
+ $this->properties['min'] + ( $step * $this->properties['majorStep'] )
+ ),
+ $step,
+ )
+ );
+ }
+ else
+ {
+ return sprintf(
+ $this->properties['logarithmicalFormatString'],
+ $this->properties['base'],
+ $this->properties['min'] + ( $step * $this->properties['majorStep'] )
+ );
+ }
}
/**
diff --git a/src/axis/numeric.php b/src/axis/numeric.php
index 9dd594c..563bb1d 100644
--- a/src/axis/numeric.php
+++ b/src/axis/numeric.php
@@ -348,7 +348,20 @@ class ezcGraphChartElementNumericAxis extends ezcGraphChartElementAxis
*/
public function getLabel( $step )
{
- return $this->properties['min'] + ( $step * $this->properties['majorStep'] );
+ if ( $this->properties['labelCallback'] !== null )
+ {
+ return call_user_func_array(
+ $this->properties['labelCallback'],
+ array(
+ $this->properties['min'] + ( $step * $this->properties['majorStep'] ),
+ $step,
+ )
+ );
+ }
+ else
+ {
+ return $this->properties['min'] + ( $step * $this->properties['majorStep'] );
+ }
}
/**
diff --git a/src/element/axis.php b/src/element/axis.php
index c3cab21..b57c75d 100644
--- a/src/element/axis.php
+++ b/src/element/axis.php
@@ -35,6 +35,11 @@
* Maximum Size used to draw arrow heads.
* @property ezcGraphAxisLabelRenderer $axisLabelRenderer
* AxisLabelRenderer used to render labels and grid on this axis.
+ * @property callback $labelCallback
+ * Callback function to format pie chart labels.
+ * Function will receive two parameters and should return a
+ * reformatted label.
+ * string function( label, step )
*
* @package Graph
*/
@@ -67,6 +72,7 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement
$this->properties['labelSize'] = 14;
$this->properties['labelMargin'] = 2;
$this->properties['maxArrowHeadSize'] = 8;
+ $this->properties['labelCallback'] = null;
parent::__construct( $options );
@@ -186,6 +192,16 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement
throw new ezcBaseValueException( $propertyName, $propertyValue, 'ezcGraphAxisLabelRenderer' );
}
break;
+ case 'labelCallback':
+ if ( is_callable( $propertyValue ) )
+ {
+ $this->properties['labelCallback'] = $propertyValue;
+ }
+ else
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'callback function' );
+ }
+ break;
default:
parent::__set( $propertyName, $propertyValue );
break;
OpenPOWER on IntegriCloud