options = new ezcGraphPieChartOptions( $options ); parent::__construct( $options ); } /** * Adds a dataset to the charts data * * @param string $name Name of dataset * @param mixed $values Values to create dataset with * @throws ezcGraphTooManyDatasetExceptions * If too many datasets are created * @return ezcGraphDataset */ protected function addDataSet( $name, $values ) { if ( count( $this->data ) >= 1 && !isset( $this->data[$name] ) ) { throw new ezcGraphTooManyDatasetsExceptions( $name ); } else { parent::addDataSet( $name, $values ); // Colorize each data element foreach ( $this->data[$name] as $label => $value ) { $this->data[$name]->color[$label] = $this->palette->dataSetColor; } } } protected function renderData( $renderer, $boundings ) { // Only draw the first (and only) dataset $dataset = reset( $this->data ); $this->driver->options->font = $this->options->font; // Calculate sum of all values to be able to calculate percentage $sum = 0; foreach ( $dataset as $value ) { $sum += $value; } $angle = 0; foreach ( $dataset as $label => $value ) { $renderer->drawPieSegment( $boundings, $dataset->color[$label], $angle, $angle += $value / $sum * 360, sprintf( $this->options->label, $label, $value, $sum / $value * 100 ), $dataset->highlight[$label] ); } } /** * Render a pie chart * * @param ezcGraphRenderer $renderer * @access public * @return void */ public function render( $width, $height, $file = null ) { // Set image properties in driver $this->driver->options->width = $width; $this->driver->options->height = $height; // Generate legend $this->elements['legend']->generateFromDataset( reset( $this->data ) ); // Get boundings from parameters $this->options->width = $width; $this->options->height = $height; $boundings = new ezcGraphBoundings(); $boundings->x1 = $this->options->width; $boundings->y1 = $this->options->height; // Render border and background $boundings = $this->renderer->drawBox( $boundings, $this->options->background, $this->options->border, $this->options->borderWidth, $this->options->margin, $this->options->padding ); // Render subelements foreach ( $this->elements as $name => $element ) { // Skip element, if it should not get rendered if ( $this->renderElement[$name] === false ) { continue; } $this->driver->options->font = $element->font; $boundings = $element->render( $this->renderer, $boundings ); } // Render graph $this->renderData( $this->renderer, $boundings ); if ( !empty( $file ) ) { $this->renderer->render( $file ); } } } ?>