summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-08-09 13:03:53 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-08-09 13:03:53 +0000
commit17b8e89991a4eee0944168aa10e0c43d2753db25 (patch)
tree773c0968c3b108bf77bb66e9be56e8c066616a9e /src
parent3c5cb5cd65c6954f78ba0bd1ccbba44cb2ae4a9a (diff)
downloadzetacomponents-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')
-rw-r--r--src/charts/line.php10
-rw-r--r--src/charts/pie.php10
-rw-r--r--src/driver/gd.php2
-rw-r--r--src/element/background.php107
-rw-r--r--src/graph_autoload.php2
-rw-r--r--src/interfaces/chart.php6
-rw-r--r--src/options/chart.php63
-rw-r--r--src/renderer/2d.php11
-rw-r--r--src/renderer/3d.php11
9 files changed, 82 insertions, 140 deletions
diff --git a/src/charts/line.php b/src/charts/line.php
index a4a8863..8ca290a 100644
--- a/src/charts/line.php
+++ b/src/charts/line.php
@@ -168,16 +168,6 @@ class ezcGraphLineChart extends ezcGraphChart
$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 )
{
diff --git a/src/charts/pie.php b/src/charts/pie.php
index b34915d..4a23911 100644
--- a/src/charts/pie.php
+++ b/src/charts/pie.php
@@ -102,16 +102,6 @@ class ezcGraphPieChart extends ezcGraphChart
$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 )
{
diff --git a/src/driver/gd.php b/src/driver/gd.php
index cc87824..2f8da21 100644
--- a/src/driver/gd.php
+++ b/src/driver/gd.php
@@ -603,7 +603,7 @@ class ezcGraphGdDriver extends ezcGraphDriver
{
$this->preProcessImages[] = array(
'file' => $file,
- 'position' => $position,
+ 'position' => clone $position,
'width' => $width,
'height' => $height,
);
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;
diff --git a/src/graph_autoload.php b/src/graph_autoload.php
index 80502c5..5e50522 100644
--- a/src/graph_autoload.php
+++ b/src/graph_autoload.php
@@ -58,7 +58,7 @@ return array(
'ezcGraphFontOptions' => 'Graph/options/font.php',
'ezcGraphChartElementText' => 'Graph/element/text.php',
'ezcGraphChartElementLegend' => 'Graph/element/legend.php',
- 'ezcGraphChartElementBackgroundImage' => 'Graph/element/background.php',
+ 'ezcGraphChartElementBackground' => 'Graph/element/background.php',
'ezcGraphChartElementAxis' => 'Graph/element/axis.php',
'ezcGraphChartElementDateAxis' => 'Graph/axis/date.php',
'ezcGraphChartElementNumericAxis' => 'Graph/axis/numeric.php',
diff --git a/src/interfaces/chart.php b/src/interfaces/chart.php
index ddcc184..ca9b16b 100644
--- a/src/interfaces/chart.php
+++ b/src/interfaces/chart.php
@@ -69,6 +69,9 @@ abstract class ezcGraphChart implements ArrayAccess
$this->__set( 'palette', new ezcGraphPaletteTango() );
// Add standard elements
+ $this->addElement( 'background', new ezcGraphChartElementBackground() );
+ $this->elements['background']->position = ezcGraph::CENTER | ezcGraph::MIDDLE;
+
$this->addElement( 'title', new ezcGraphChartElementText() );
$this->elements['title']->position = ezcGraph::TOP;
$this->renderElement['title'] = false;
@@ -175,9 +178,6 @@ abstract class ezcGraphChart implements ArrayAccess
{
$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 )
{
diff --git a/src/options/chart.php b/src/options/chart.php
index 18ea61c..788a03b 100644
--- a/src/options/chart.php
+++ b/src/options/chart.php
@@ -30,48 +30,6 @@ class ezcGraphChartOptions extends ezcBaseOptions
protected $height;
/**
- * Background images filename
- *
- * @var string
- */
- protected $backgroundImage;
-
- /**
- * Background color of the chart
- *
- * @var ezcGraphColor
- */
- protected $background;
-
- /**
- * Border color of the chart
- *
- * @var ezcGraphColor
- */
- protected $border;
-
- /**
- * Border width
- *
- * @var int
- */
- protected $borderWidth = 0;
-
- /**
- * Space between border and content
- *
- * @var integer
- */
- protected $padding = 0;
-
- /**
- * Distance between outer boundings and border of an element
- *
- * @var integer
- */
- protected $margin = 0;
-
- /**
* Font used in the graph
*
* @var int
@@ -82,9 +40,6 @@ class ezcGraphChartOptions extends ezcBaseOptions
{
$this->font = new ezcGraphFontOptions();
- $this->backgroundImage = new ezcGraphChartElementBackgroundImage();
- $this->backgroundImage->position = ezcGraph::CENTER | ezcGraph::MIDDLE;
-
parent::__construct( $options );
}
@@ -107,24 +62,6 @@ class ezcGraphChartOptions extends ezcBaseOptions
case 'height':
$this->height = max( 1, (int) $propertyValue );
break;
- case 'padding':
- $this->padding = max( 0, (int) $propertyValue );
- break;
- case 'margin':
- $this->margin = max( 0, (int) $propertyValue );
- break;
- case 'backgroundImage':
- $this->backgroundImage->source = $propertyValue;
- break;
- case 'background':
- $this->background = ezcGraphColor::create( $propertyValue );
- break;
- case 'border':
- $this->border = ezcGraphColor::create( $propertyValue );
- break;
- case 'borderWidth':
- $this->borderWidth = max( 0, (int) $propertyValue );
- break;
case 'font':
$this->font->font = $propertyValue;
break;
diff --git a/src/renderer/2d.php b/src/renderer/2d.php
index 193a11c..1c54de0 100644
--- a/src/renderer/2d.php
+++ b/src/renderer/2d.php
@@ -795,7 +795,13 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
$imageWidth = $imageData[0];
$imageHeight = $imageData[1];
- $imagePosition = new ezcGraphCoordinate( 0, 0 );
+ $imageWidth = min( $imageWidth, $boundings->x1 - $boundings->x0 );
+ $imageHeight = min( $imageHeight, $boundings->y1 - $boundings->y0 );
+
+ $imagePosition = new ezcGraphCoordinate(
+ $boundings->x0,
+ $boundings->y0
+ );
// Determine x position
switch ( true ) {
@@ -839,9 +845,6 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
break;
}
- $imageWidth = min( $imageWidth, $boundings->x1 - $boundings->x0 );
- $imageHeight = min( $imageHeight, $boundings->y1 - $boundings->y0 );
-
// Texturize backround based on position and repetition
$position = new ezcGraphCoordinate(
$imagePosition->x,
diff --git a/src/renderer/3d.php b/src/renderer/3d.php
index 819b6f5..1997e56 100644
--- a/src/renderer/3d.php
+++ b/src/renderer/3d.php
@@ -1189,7 +1189,13 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
$imageWidth = $imageData[0];
$imageHeight = $imageData[1];
- $imagePosition = new ezcGraphCoordinate( 0, 0 );
+ $imageWidth = min( $imageWidth, $boundings->x1 - $boundings->x0 );
+ $imageHeight = min( $imageHeight, $boundings->y1 - $boundings->y0 );
+
+ $imagePosition = new ezcGraphCoordinate(
+ $boundings->x0,
+ $boundings->y0
+ );
// Determine x position
switch ( true ) {
@@ -1233,9 +1239,6 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
break;
}
- $imageWidth = min( $imageWidth, $boundings->x1 - $boundings->x0 );
- $imageHeight = min( $imageHeight, $boundings->y1 - $boundings->y0 );
-
// Texturize backround based on position and repetition
$position = new ezcGraphCoordinate(
$imagePosition->x,
OpenPOWER on IntegriCloud