summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-11-02 09:05:43 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-11-02 09:05:43 +0000
commit39d55ef60b9074920a1a3fc3d0c0f8d51f303760 (patch)
treed6a24afb29f1448f051e2446f87143a8b844dc6f /src
parent5532c0542f6a370378102f34ec9b10e8d9533915 (diff)
downloadzetacomponents-graph-39d55ef60b9074920a1a3fc3d0c0f8d51f303760.zip
zetacomponents-graph-39d55ef60b9074920a1a3fc3d0c0f8d51f303760.tar.gz
- Implemented #009304: Possibility to format labels via callback
Diffstat (limited to 'src')
-rw-r--r--src/charts/pie.php6
-rw-r--r--src/options/pie_chart.php15
2 files changed, 20 insertions, 1 deletions
diff --git a/src/charts/pie.php b/src/charts/pie.php
index 8396492..85bf7a2 100644
--- a/src/charts/pie.php
+++ b/src/charts/pie.php
@@ -87,13 +87,17 @@ class ezcGraphPieChart extends ezcGraphChart
switch ( $dataset->displayType->default )
{
case ezcGraph::PIE:
+ $displayLabel = ( $this->options->labelCallback !== null
+ ? call_user_func( $this->options->labelCallback, $label, $value, $value / $sum )
+ : sprintf( $this->options->label, $label, $value, $value / $sum * 100 ) );
+
$renderer->drawPieSegment(
$boundings,
new ezcGraphContext( $datasetName, $label ),
$dataset->color[$label],
$angle,
$angle += $value / $sum * 360,
- sprintf( $this->options->label, $label, $value, $value / $sum * 100 ),
+ $displayLabel,
$dataset->highlight[$label]
);
break;
diff --git a/src/options/pie_chart.php b/src/options/pie_chart.php
index 104bc5a..5974a2d 100644
--- a/src/options/pie_chart.php
+++ b/src/options/pie_chart.php
@@ -15,6 +15,10 @@
* %$1s Name of pie
* %2$d Value of pie
* %3$.1f Percentage
+ * @property callback $labelCallback
+ * Callback function to format pie chart labels.
+ * Function will receive 3 parameters:
+ * string function( label, value, percent )
* @property float $sum
* Fixed sum of values. This should be used for incomplete pie
* charts.
@@ -40,6 +44,7 @@ class ezcGraphPieChartOptions extends ezcGraphChartOptions
public function __construct( array $options = array() )
{
$this->properties['label'] = '%1$s: %2$d (%3$.1f%%)';
+ $this->properties['labelCallback'] = null;
$this->properties['sum'] = false;
$this->properties['percentTreshHold'] = .0;
@@ -66,6 +71,16 @@ class ezcGraphPieChartOptions extends ezcGraphChartOptions
case 'label':
$this->properties['label'] = (string) $propertyValue;
break;
+ case 'labelCallback':
+ if ( is_string( $propertyValue ) && function_exists( $propertyValue ) )
+ {
+ $this->properties['labelCallback'] = $propertyValue;
+ }
+ else
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'callback function' );
+ }
+ break;
case 'sum':
$this->properties['sum'] = (float) $propertyValue;
break;
OpenPOWER on IntegriCloud