diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2006-08-09 13:03:53 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2006-08-09 13:03:53 +0000 |
commit | 17b8e89991a4eee0944168aa10e0c43d2753db25 (patch) | |
tree | 773c0968c3b108bf77bb66e9be56e8c066616a9e /src/element | |
parent | 3c5cb5cd65c6954f78ba0bd1ccbba44cb2ae4a9a (diff) | |
download | zetacomponents-graph-17b8e89991a4eee0944168aa10e0c43d2753db25.zip zetacomponents-graph-17b8e89991a4eee0944168aa10e0c43d2753db25.tar.gz |
- Added option to gd driver to set an external image as background
- Got chart background images working again
- Post process images in gd driver to not apply supersampling for images
Diffstat (limited to 'src/element')
-rw-r--r-- | src/element/background.php | 107 |
1 files changed, 63 insertions, 44 deletions
diff --git a/src/element/background.php b/src/element/background.php index a1a4f19..269b520 100644 --- a/src/element/background.php +++ b/src/element/background.php @@ -1,6 +1,6 @@ <?php /** - * File containing the abstract ezcGraphChartElementText class + * File containing the abstract ezcGraphChartElementBackground class * * @package Graph * @version //autogentag// @@ -12,7 +12,7 @@ * * @package Graph */ -class ezcGraphChartElementBackgroundImage extends ezcGraphChartElement +class ezcGraphChartElementBackground extends ezcGraphChartElement { /** @@ -20,7 +20,14 @@ class ezcGraphChartElementBackgroundImage extends ezcGraphChartElement * * @var string */ - protected $source = ''; + protected $image = false; + + /** + * Defines how the background image gets repeated + * + * @var int + */ + protected $repeat = ezcGraph::NO_REPEAT; /** * __set @@ -37,7 +44,7 @@ class ezcGraphChartElementBackgroundImage extends ezcGraphChartElement { switch ( $propertyName ) { - case 'source': + case 'image': // Check for existance of file if ( !is_file( $propertyValue ) || !is_readable( $propertyValue ) ) { @@ -57,10 +64,31 @@ class ezcGraphChartElementBackgroundImage extends ezcGraphChartElement throw new ezcGraphInvalidImageFileException( 'We cant use SWF files like <' . $propertyValue . '>.' ); } - $this->source = $propertyValue; + $this->image = $propertyValue; + break; + case 'repeat': + if ( ( $propertyValue >= 0 ) && ( $propertyValue <= 3 ) ) + { + $this->repeat = (int) $propertyValue; + } + else + { + throw new ezcBaseValeException( $propertyName, $propertyValue, '0 <= int <= 3' ); + } break; case 'position': - $this->position = (int) $propertyValue; + if ( is_int( $propertyValue ) ) + { + $this->position = $propertyValue; + } + else + { + throw new ezcBaseValueException( $propertyName, $propertyValue, 'integer' ); + } + break; + case 'color': + // Use color as an alias to set background color for background + $this->__set( 'background', $propertyValue ); break; default: return parent::__set( $propertyName, $propertyValue ); @@ -68,6 +96,21 @@ class ezcGraphChartElementBackgroundImage extends ezcGraphChartElement } /** + * Set colors and border fro this element + * + * @param ezcGraphPalette $palette Palette + * @return void + */ + public function setFromPalette( ezcGraphPalette $palette ) + { + $this->border = $palette->chartBorderColor; + $this->borderWidth = $palette->chartBorderWidth; + $this->background = $palette->chartBackground; + $this->padding = 0; + $this->margin = 0; + } + + /** * Render a legend * * @param ezcGraphRenderer $renderer @@ -76,49 +119,25 @@ class ezcGraphChartElementBackgroundImage extends ezcGraphChartElement */ public function render( ezcGraphRenderer $renderer, ezcGraphBoundings $boundings ) { - if ( empty( $this->source ) ) - { - return $boundings; - } - - // Get background image boundings - $data = getimagesize( $this->source ); - - // Determine x position - switch ( true ) - { - case ( $this->position & ezcGraph::LEFT ): - $xPosition = 0; - break; - case ( $this->position & ezcGraph::RIGHT ): - $xPosition = $boundings->x1 - $data[0]; - break; - case ( $this->position & ezcGraph::CENTER ): - default: - $xPosition = (int) round( ( $boundings->x1 - $data[0] ) / 2 ); - break; - } + $boundings = $renderer->drawBox( + $boundings, + $this->background, + $this->border, + $this->borderWidth, + $this->margin, + $this->padding + ); - // Determine y position - switch ( true ) + if ( $this->image === false ) { - case ( $this->position & ezcGraph::TOP ): - $yPosition = 0; - break; - case ( $this->position & ezcGraph::BOTTOM ): - $yPosition = $boundings->y1 - $data[1]; - break; - case ( $this->position & ezcGraph::MIDDLE ): - default: - $yPosition = (int) round( ( $boundings->y1 - $data[1] ) / 2 ); - break; + return $boundings; } $renderer->drawBackgroundImage( - $this->source, - new ezcGraphCoordinate( $xPosition, $yPosition ), - $data[0], - $data[1] + $boundings, + $this->image, + $this->position, + $this->repeat ); return $boundings; |