__set( 'palette', 'Tango' ); // Add standard elements $this->addElement( 'title', new ezcGraphChartElementText() ); $this->elements['title']->position = ezcGraph::TOP; $this->renderElement['title'] = false; $this->addElement( 'legend', new ezcGraphChartElementLegend() ); $this->elements['legend']->position = ezcGraph::LEFT; // Define standard renderer and driver $this->driver = new ezcGraphSvgDriver(); $this->renderer = new ezcGraphRenderer2D(); $this->renderer->setDriver( $this->driver ); } protected function addElement( $name, ezcGraphChartElement $element ) { $this->elements[$name] = $element; $this->elements[$name]->font = $this->options->font; $this->elements[$name]->setFromPalette( $this->palette ); // Render element by default $this->renderElement[$name] = true; } /** * Options write access * * @throws ezcBasePropertyNotFoundException * If Option could not be found * @throws ezcBaseValueException * If value is out of range * @param mixed $propertyName Option name * @param mixed $propertyValue Option value; * @return mixed */ public function __set( $propertyName, $propertyValue ) { switch ( $propertyName ) { case 'title': $this->elements['title']->title = $propertyValue; $this->renderElement['title'] = true; break; case 'legend': $this->renderElement['legend'] = (bool) $propertyValue; break; case 'renderer': if ( $propertyValue instanceof ezcGraphRenderer ) { $this->renderer = $propertyValue; $this->renderer->setDriver( $this->driver ); return $this->renderer; } else { throw new ezcGraphInvalidRendererException( $propertyValue ); } break; case 'driver': if ( $propertyValue instanceof ezcGraphDriver ) { $this->driver = $propertyValue; $this->renderer->setDriver( $this->driver ); return $this->driver; } else { throw new ezcGraphInvalidDriverException( $propertyValue ); } break; case 'palette': if ( $propertyValue instanceof ezcGraphPalette ) { $this->palette = $propertyValue; } else { $this->palette = ezcGraph::createPalette( $propertyValue ); } $this->setFromPalette( $this->palette ); break; case 'options': if ( $propertyValue instanceof ezcGraphChartOptions ) { $this->options = $propertyValue; } else { throw new ezcBaseValueException( "options", $propertyValue, "instanceof ezcGraphOptions" ); } default: throw new ezcBasePropertyNotFoundException( $propertyName ); break; } } /** * Set colors and border fro this element * * @param ezcGraphPalette $palette Palette * @return void */ public function setFromPalette( ezcGraphPalette $palette ) { $this->options->font->font = $palette->fontFace; $this->options->font->color = $palette->fontColor; $this->options->background = $palette->chartBackground; $this->options->border = $palette->chartBorderColor; $this->options->borderWidth = $palette->chartBorderWidth; foreach ( $this->elements as $element ) { $element->setFromPalette( $palette ); } } /** * 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 ) { $this->data[$name] = new ezcGraphDataset(); if ( is_array($values) ) { $this->data[$name]->createFromArray( $values ); $this->data[$name]->label = $name; $this->data[$name]->palette = $this->palette; } elseif ( $values instanceof PDOStatement ) { $this->data[$name]->createFromStatement( $values ); $this->data[$name]->label = $name; $this->data[$name]->palette = $this->palette; } else { throw new ezcGraphUnknownDatasetSourceException( $values ); } } /** * Returns the requested property * * @param mixed $propertyName * @return mixed */ public function __get( $propertyName ) { if ( isset( $this->$propertyName ) ) { return $this->$propertyName; } if ( isset( $this->elements[$propertyName] ) ) { return $this->elements[$propertyName]; } if ( $propertyName === "options" ) { return $this->options; } else { throw new ezcGraphNoSuchElementException( $propertyName ); } } public function offsetExists( $key ) { return isset( $this->data[$key] ); } public function offsetGet( $key ) { if ( !isset( $key ) ) { throw new ezcGraphNoSuchDatasetException( $key ); } return $this->data[$key]; } public function offsetSet( $key, $value ) { return $this->addDataset( $key, $value ); } public function offsetUnset( $key ) { if ( !isset( $key ) ) { throw new ezcGraphNoSuchDatasetException( $key ); } unset( $this->data[$key] ); } public function setOptions( $options ) { if ( is_array( $options ) ) { $this->options->merge( $options ); } else if ( $options instanceof ezcGraphOptions ) { $this->options = $options; } else { throw new ezcBaseValueException( "options", $options, "instance of ezcGraphOptions" ); } } /** * Render chart border * * @param ezcGraphBoundings $boundings Boundings * @return ezcGraphBoundings */ protected function renderBorder( ezcGraphBoundings $boundings ) { if ( ( $this->options->border instanceof ezcGraphColor ) && ( $this->options->borderWidth > 0 ) ) { // Default bordervalue to 1 $this->options->borderWidth = max( 1, $this->options->borderWidth ); // Draw border $this->renderer->drawRect( $this->options->border, new ezcGraphCoordinate( $boundings->x0, $boundings->y0 ), $boundings->x1 - $boundings->x0, $boundings->y1 - $boundings->y0, $this->options->borderWidth ); // Reduce local boundings by borderWidth $boundings->x0 += $this->options->borderWidth; $boundings->y0 += $this->options->borderWidth; $boundings->x1 -= $this->options->borderWidth; $boundings->y1 -= $this->options->borderWidth; } return $boundings; } /** * Render chart background * * @param ezcGraphBoundings $boundings Boundings * @return ezcGraphBoundings */ protected function renderBackground( ezcGraphBoundings $boundings ) { if ( $this->options->background instanceof ezcGraphColor ) { $this->renderer->drawBackground( $this->options->background, new ezcGraphCoordinate( $boundings->x0, $boundings->y0 ), $boundings->x1 - $boundings->x0, $boundings->y1 - $boundings->y0 ); } // Apply padding $boundings->x0 += $this->options->padding; $boundings->y0 += $this->options->padding; $boundings->x1 -= $this->options->padding; $boundings->y1 -= $this->options->padding; return $boundings; } /** * Renders this chart * * Creates basic visual chart elements from the chart to be processed by * the renderer. * * @return void */ abstract public function render( $widht, $height, $file = null ); } ?>