diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2006-06-06 12:22:35 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2006-06-06 12:22:35 +0000 |
commit | c925b7cbd916a294e96d361585c396cd107a827e (patch) | |
tree | 6ceee293182e603f560fda96b6177f9ac0b20751 /src | |
parent | a1cf00931ec31b6c7c45ecd182b410c6e7cf4781 (diff) | |
download | zetacomponents-graph-c925b7cbd916a294e96d361585c396cd107a827e.zip zetacomponents-graph-c925b7cbd916a294e96d361585c396cd107a827e.tar.gz |
- Added test for palettes
- Added basic implementatoin of palettes
# Not used for automatic colorization yet
Diffstat (limited to 'src')
-rw-r--r-- | src/driver/gd.php | 1 | ||||
-rw-r--r-- | src/exceptions/unknown_palette.php | 21 | ||||
-rw-r--r-- | src/graph.php | 13 | ||||
-rw-r--r-- | src/graph_autoload.php | 5 | ||||
-rw-r--r-- | src/interfaces/chart.php | 23 | ||||
-rw-r--r-- | src/interfaces/palette.php | 159 | ||||
-rw-r--r-- | src/palette/black.php | 100 | ||||
-rw-r--r-- | src/palette/tango.php | 101 |
8 files changed, 421 insertions, 2 deletions
diff --git a/src/driver/gd.php b/src/driver/gd.php index 95c48a4..4c6c607 100644 --- a/src/driver/gd.php +++ b/src/driver/gd.php @@ -233,6 +233,7 @@ class ezcGraphGdDriver extends ezcGraphDriver public function drawTextBox( $string, ezcGraphCoordinate $position, $width, $height, $align ) { // Test font + // @TODO: try to find font at standard locations if no path was provided if ( !is_file( $this->options->font->font ) || !is_readable( $this->options->font->font ) ) { throw new ezcGraphGdDriverInvalidFontException( $this->options->font->font ); diff --git a/src/exceptions/unknown_palette.php b/src/exceptions/unknown_palette.php new file mode 100644 index 0000000..970c45b --- /dev/null +++ b/src/exceptions/unknown_palette.php @@ -0,0 +1,21 @@ +<?php +/** + * File containing the ezcGraphUnknownPaletteException class + * + * @package Graph + * @version //autogen// + * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ +/** + * ezcGraphUnknownPaletteException is the exception which is thrown when the + * factory method tries to return an instance of an unknown chart type + * + * @package Graph + * @version //autogen// + */ +class ezcGraphUnknownPaletteException extends ezcBaseException +{ +} + +?> diff --git a/src/graph.php b/src/graph.php index 03ee3fe..dd868cd 100644 --- a/src/graph.php +++ b/src/graph.php @@ -53,6 +53,19 @@ class ezcGraph throw new ezcGraphUnknownChartTypeException($type); } } + + static public function createPalette( $name ) + { + $className = 'ezcGraphPalette' . $name; + if ( class_exists( $className ) ) + { + return new $className(); + } + else + { + throw new ezcGraphUnknownPaletteException( $name ); + } + } } ?> diff --git a/src/graph_autoload.php b/src/graph_autoload.php index 20fdbc1..677eb99 100644 --- a/src/graph_autoload.php +++ b/src/graph_autoload.php @@ -36,6 +36,11 @@ return array( 'ezcGraphSvgDriverOptions' => 'Graph/options/svg_driver.php', 'ezcGraphInvalidDriverException' => 'Graph/exceptions/invalid_driver.php', + 'ezcGraphPalette' => 'Graph/interfaces/palette.php', + 'ezcGraphPaletteTango' => 'Graph/palette/tango.php', + 'ezcGraphPaletteBlack' => 'Graph/palette/black.php', + 'ezcGraphUnknownPaletteException' => 'Graph/exceptions/unknown_palette.php', + 'ezcGraphChartElement' => 'Graph/interfaces/element.php', 'ezcGraphFontOptions' => 'Graph/options/font.php', 'ezcGraphChartElementText' => 'Graph/element/text.php', diff --git a/src/interfaces/chart.php b/src/interfaces/chart.php index b862916..980ab8c 100644 --- a/src/interfaces/chart.php +++ b/src/interfaces/chart.php @@ -50,10 +50,19 @@ abstract class ezcGraphChart */ protected $driver; + /** + * Palette for default colorization + * + * @var ezcGraphPalette + */ + protected $palette; + public function __construct( array $options = array() ) { $this->options = new ezcGraphChartOptions( $options ); + $this->palette = ezcGraph::createPalette( 'Tango' ); + // Add standard elements $this->elements['title'] = new ezcGraphChartElementText(); $this->elements['title']->font = $this->options->font; @@ -106,9 +115,19 @@ abstract class ezcGraphChart return $this->driver; } else - { + { throw new ezcGraphInvalidDriverException( $propertyValue ); - } + } + break; + case 'palette': + if ( $propertyValue instanceof ezcGraphPalette ) + { + $this->palette = $propertyValue; + } + else + { + $this->palette = ezcGraph::createPalette( $propertyValue ); + } break; case 'options': if ( $propertyValue instanceof ezcGraphChartOptions ) diff --git a/src/interfaces/palette.php b/src/interfaces/palette.php new file mode 100644 index 0000000..a93bd65 --- /dev/null +++ b/src/interfaces/palette.php @@ -0,0 +1,159 @@ +<?php +/** + * File containing the abstract ezcGraphPalette class + * + * @package Graph + * @version //autogentag// + * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ +/** + * Abstract class to contain pallet definitions + * + * @package Graph + */ +abstract class ezcGraphPalette +{ + /** + * Indicates which color should be used for the next dataset + * + * @var integer + */ + protected $colorIndex = -1; + + /** + * Indicates which symbol should be used for the nect dataset + * + * @var integer + */ + protected $symbolIndex = -1; + + /** + * Backgroundcolor + * + * @var ezcGraphColor + */ + protected $background; + + /** + * Axiscolor + * + * @var ezcGraphColor + */ + protected $axisColor; + + /** + * Array with colors for datasets + * + * @var array + */ + protected $dataSetColor; + + /** + * Array with symbols for datasets + * + * @var array + */ + protected $dataSetSymbol; + + /** + * Fontface + * + * @var string + */ + protected $fontFace; + + /** + * Fontcolor + * + * @var ezcGraphColor + */ + protected $fontColor; + + /** + * Bordercolor + * + * @var ezcGraphColor + */ + protected $borderColor; + + /** + * Borderwidth + * + * @var integer + * @access protected + */ + protected $borderWidth = 0; + + /** + * Padding in elements + * + * @var integer + */ + protected $padding = 1; + + /** + * Margin of elements + * + * @var integer + */ + protected $margin = 0; + + /** + * Ensure value to be a color + * + * @param mixed $color Color to transform into a ezcGraphColor object + * @return ezcGraphColor + */ + protected function checkColor( &$color ) + { + if ( !( $color instanceof ezcGraphColor ) ) + { + $color = ezcGraphColor::create( $color ); + } + + return $color; + } + + /** + * Returns the requested property + * + * @param string $propertyName Name of property + * @return mixed + */ + public function __get( $propertyName ) + { + switch ( $propertyName ) + { + case 'background': + return $this->checkColor( $this->background ); + + case 'axisColor': + return $this->checkColor( $this->axisColor ); + + case 'dataSetColor': + $this->colorIndex = ( ( $this->colorIndex + 1 ) % count( $this->dataSetColor ) ); + return $this->checkColor( $this->dataSetColor[ $this->colorIndex ] ); + case 'dataSetSymbol': + $this->symbolIndex = ( ( $this->symbolIndex + 1 ) % count( $this->dataSetSymbol ) ); + return $this->dataSetSymbol[ $this->symbolIndex ]; + + case 'fontColor': + return $this->checkColor( $this->fontColor ); + case 'fontFace': + return $this->fontFace; + + case 'borderColor': + return $this->checkColor( $this->borderColor ); + case 'borderWidth': + return $this->borderWidth; + + case 'padding': + return $this->padding; + case 'margin': + return $this->margin; + } + } +} + +?> diff --git a/src/palette/black.php b/src/palette/black.php new file mode 100644 index 0000000..3c97294 --- /dev/null +++ b/src/palette/black.php @@ -0,0 +1,100 @@ +<?php +/** + * File containing the abstract ezcGraphPaletteBlack class + * + * @package Graph + * @version //autogentag// + * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ +/** + * Color pallet for ezcGraph based on Tango style guidelines at + * http://tango-project.org/Generic_Icon_Theme_Guidelines + * + * @package Graph + */ +class ezcGraphPaletteBlack extends ezcGraphPalette +{ + /** + * Backgroundcolor + * + * @var ezcGraphColor + */ + protected $background = '#000000'; + + /** + * Axiscolor + * + * @var ezcGraphColor + */ + protected $axisColor = '#EEEEEC'; + + /** + * Array with colors for datasets + * + * @var array + */ + protected $dataSetColor = array( + '#729FCF', + '#EF2929', + '#FCE94F', + '#8AE234', + '#F57900', + '#AD7FA8', + + ); + + /** + * Array with symbols for datasets + * + * @var array + */ + protected $dataSetSymbol = array( + ezcGraph::BULLET, + ); + + /** + * Fontface + * + * @var string + */ + protected $fontFace = 'Vera.ttf'; + + /** + * Fontcolor + * + * @var ezcGraphColor + */ + protected $fontColor = '#D3D7CF'; + + /** + * Bordercolor + * + * @var ezcGraphColor + */ + protected $borderColor = '#555753'; + + /** + * Borderwidth + * + * @var integer + * @access protected + */ + protected $borderWidth = 0; + + /** + * Padding in elements + * + * @var integer + */ + protected $padding = 1; + + /** + * Margin of elements + * + * @var integer + */ + protected $margin = 1; +} + +?> diff --git a/src/palette/tango.php b/src/palette/tango.php new file mode 100644 index 0000000..08f6746 --- /dev/null +++ b/src/palette/tango.php @@ -0,0 +1,101 @@ +<?php +/** + * File containing the abstract ezcGraphPaletteTango class + * + * @package Graph + * @version //autogentag// + * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ +/** + * Color pallet for ezcGraph based on Tango style guidelines at + * http://tango-project.org/Generic_Icon_Theme_Guidelines + * + * @package Graph + */ +class ezcGraphPaletteTango extends ezcGraphPalette +{ + /** + * Backgroundcolor + * + * @var ezcGraphColor + */ + protected $background = '#EEEEEC'; + + /** + * Axiscolor + * + * @var ezcGraphColor + */ + protected $axisColor = '#2E3436'; + + /** + * Array with colors for datasets + * + * @var array + */ + protected $dataSetColor = array( + '#3465A4', + '#4E9A06', + '#CC0000', + '#EDD400', + '#75505B', + '#F57900', + '#204A87', + '#C17D11', + ); + + /** + * Array with symbols for datasets + * + * @var array + */ + protected $dataSetSymbol = array( + ezcGraph::BULLET, + ); + + /** + * Fontface + * + * @var string + */ + protected $fontFace = 'Vera.ttf'; + + /** + * Fontcolor + * + * @var ezcGraphColor + */ + protected $fontColor = '#888A85'; + + /** + * Bordercolor + * + * @var ezcGraphColor + */ + protected $borderColor = '#BABDB6'; + + /** + * Borderwidth + * + * @var integer + * @access protected + */ + protected $borderWidth = 0; + + /** + * Padding in elements + * + * @var integer + */ + protected $padding = 1; + + /** + * Margin of elements + * + * @var integer + */ + protected $margin = 1; +} + +?> |