/** * Render the assigned data * * Will renderer all charts data in the remaining boundings after drawing * all other chart elements. The data will be rendered depending on the * settings in the dataset. * * @param ezcGraphRenderer $renderer Renderer * @param ezcGraphBoundings $boundings Remaining boundings * @return void */ protected function renderData(ezcGraphRenderer $renderer, ezcGraphBoundings $boundings) { // Only draw the first (and only) dataset $dataset = $this->data->rewind(); $datasetName = $this->data->key(); $this->driver->options->font = $this->options->font; // Calculate sum of all values to be able to calculate percentage $sum = 0; foreach ($dataset as $name => $value) { if ($value < 0) { throw new ezcGraphInvalidDataException("Values >= 0 required, '{$name}' => '{$value}'."); } $sum += $value; } if ($this->options->sum !== false) { $sum = max($sum, $this->options->sum); } if ($sum <= 0) { throw new ezcGraphInvalidDataException("Pie charts require a value sum > 0, your value: '{$sum}'."); } $angle = 0; foreach ($dataset as $label => $value) { // Skip rendering values which equals 0 if ($value <= 0) { continue; } 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->url[$label]), $dataset->color[$label], $angle, $angle += $value / $sum * 360, $displayLabel, $dataset->highlight[$label]); break; default: throw new ezcGraphInvalidDisplayTypeException($dataset->displayType->default); break; } } }