summaryrefslogtreecommitdiffstats
path: root/src/charts/pie.php
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-10-26 08:58:18 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-10-26 08:58:18 +0000
commit7e56dbbe610469d173133cc6f2d19da5039079bb (patch)
tree8b76dbc4ef79ebc2ec3081fb8efe96c8a462672a /src/charts/pie.php
parent6a1c516e3bd0ecfc6a3597f38f7a27abd0023d09 (diff)
downloadzetacomponents-graph-7e56dbbe610469d173133cc6f2d19da5039079bb.zip
zetacomponents-graph-7e56dbbe610469d173133cc6f2d19da5039079bb.tar.gz
- Added tresh hold for pie charts
- Added test for custom sum in pie charts
Diffstat (limited to 'src/charts/pie.php')
-rw-r--r--src/charts/pie.php53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/charts/pie.php b/src/charts/pie.php
index cf30137..8396492 100644
--- a/src/charts/pie.php
+++ b/src/charts/pie.php
@@ -115,6 +115,56 @@ class ezcGraphPieChart extends ezcGraphChart
}
/**
+ * Apply tresh hold
+ *
+ * Iterates over the dataset and applies the configured tresh hold to
+ * the datasets data.
+ *
+ * @return void
+ */
+ protected function applyTreshHold()
+ {
+ if ( $this->options->percentTreshHold || $this->options->absoluteTreshHold )
+ {
+ $dataset = $this->data->rewind();
+
+ $sum = 0;
+ foreach ( $dataset as $value )
+ {
+ $sum += $value;
+ }
+ if ( $this->options->sum !== false )
+ {
+ $sum = max( $sum, $this->options->sum );
+ }
+
+ $unset = array();
+ foreach ( $dataset as $label => $value )
+ {
+ if ( ( $value <= $this->options->absoluteTreshHold ) ||
+ ( ( $value / $sum ) <= $this->options->percentTreshHold ) )
+ {
+ if ( !isset( $dataset[$this->options->summarizeCaption] ) )
+ {
+ $dataset[$this->options->summarizeCaption] = $value;
+ }
+ else
+ {
+ $dataset[$this->options->summarizeCaption] += $value;
+ }
+
+ $unset[] = $label;
+ }
+ }
+
+ foreach ( $unset as $label )
+ {
+ unset( $dataset[$label] );
+ }
+ }
+ }
+
+ /**
* Render the pie chart
*
* Renders the chart into a file or stream. The width and height are
@@ -132,6 +182,9 @@ class ezcGraphPieChart extends ezcGraphChart
$this->driver->options->width = $width;
$this->driver->options->height = $height;
+ // Apply tresh hold
+ $this->applyTreshHold();
+
// Generate legend
$this->elements['legend']->generateFromDataSet( $this->data->rewind() );
OpenPOWER on IntegriCloud