summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--tests/chart_test.php30
-rw-r--r--tests/data/compare/ezcGraphRenderer2dTest_testRenderPieChartWithBackgroundBottomRight.pngbin0 -> 87091 bytes
-rw-r--r--tests/data/compare/ezcGraphRenderer2dTest_testRenderPieChartWithTextureBackground.pngbin0 -> 77027 bytes
-rw-r--r--tests/data/compare/ezcGraphRenderer3dTest_testRenderPieChartWithBackgroundBottomCenter.pngbin0 -> 87097 bytes
-rw-r--r--tests/data/compare/ezcGraphRenderer3dTest_testRenderPieChartWithHorizontalTextureBackground.pngbin0 -> 83769 bytes
-rw-r--r--tests/data/ez.pngbin0 -> 1291 bytes
-rw-r--r--tests/data/texture.pngbin0 -> 277 bytes
-rw-r--r--tests/palette_test.php2
-rw-r--r--tests/renderer_2d_test.php58
-rw-r--r--tests/renderer_3d_test.php302
19 files changed, 451 insertions, 163 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,
diff --git a/tests/chart_test.php b/tests/chart_test.php
index 10a9183..a906eeb 100644
--- a/tests/chart_test.php
+++ b/tests/chart_test.php
@@ -64,26 +64,12 @@ class ezcGraphChartTest extends ezcTestCase
);
}
- public function testSetOptionsValidBackgroundImage()
- {
- $pieChart = new ezcGraphPieChart();
- $pieChart->options->backgroundImage = $this->basePath . $this->testFiles['jpeg'];
-
- $background = $this->getNonPublicProperty( $pieChart->options, 'backgroundImage' );
- $this->assertTrue(
- $background instanceof ezcGraphChartElementBackgroundImage,
- 'Background is not an ezcGraphChartElementBackgroundImage.'
- );
-
- $this->assertSame( $this->basePath . $this->testFiles['jpeg'], $this->getNonPublicProperty( $background, 'source' ) );
- }
-
public function testSetOptionsInvalidBackgroundImage()
{
try
{
$pieChart = new ezcGraphPieChart();
- $pieChart->options->backgroundImage = $this->basePath . $this->testFiles['invalid'];
+ $pieChart->background->image = $this->basePath . $this->testFiles['invalid'];
}
catch ( ezcGraphInvalidImageFileException $e )
{
@@ -98,7 +84,7 @@ class ezcGraphChartTest extends ezcTestCase
try
{
$pieChart = new ezcGraphPieChart();
- $pieChart->options->backgroundImage = $this->basePath . $this->testFiles['nonexistant'];
+ $pieChart->background->image = $this->basePath . $this->testFiles['nonexistant'];
}
catch ( ezcBaseFileNotFoundException $e )
{
@@ -111,31 +97,31 @@ class ezcGraphChartTest extends ezcTestCase
public function testSetOptionsBackground()
{
$pieChart = new ezcGraphPieChart();
- $pieChart->options->background = '#FF0000';
+ $pieChart->background->color = '#FF0000';
$this->assertEquals(
ezcGraphColor::fromHex( 'FF0000' ),
- $this->getNonPublicProperty( $pieChart->options, 'background' )
+ $this->getNonPublicProperty( $pieChart->background, 'background' )
);
}
public function testSetOptionsBorder()
{
$pieChart = new ezcGraphPieChart();
- $pieChart->options->border = '#FF0000';
+ $pieChart->background->border = '#FF0000';
$this->assertEquals(
ezcGraphColor::fromHex( 'FF0000' ),
- $this->getNonPublicProperty( $pieChart->options, 'border' )
+ $this->getNonPublicProperty( $pieChart->background, 'border' )
);
}
public function testSetOptionsBorderWidth()
{
$pieChart = new ezcGraphPieChart();
- $pieChart->options->borderWidth = 3;
+ $pieChart->background->borderWidth = 3;
- $this->assertSame( 3, $this->getNonPublicProperty( $pieChart->options, 'borderWidth' ) );
+ $this->assertSame( 3, $this->getNonPublicProperty( $pieChart->background, 'borderWidth' ) );
}
public function testSetOptionsUnknown()
diff --git a/tests/data/compare/ezcGraphRenderer2dTest_testRenderPieChartWithBackgroundBottomRight.png b/tests/data/compare/ezcGraphRenderer2dTest_testRenderPieChartWithBackgroundBottomRight.png
new file mode 100644
index 0000000..b57b378
--- /dev/null
+++ b/tests/data/compare/ezcGraphRenderer2dTest_testRenderPieChartWithBackgroundBottomRight.png
Binary files differ
diff --git a/tests/data/compare/ezcGraphRenderer2dTest_testRenderPieChartWithTextureBackground.png b/tests/data/compare/ezcGraphRenderer2dTest_testRenderPieChartWithTextureBackground.png
new file mode 100644
index 0000000..91c1b66
--- /dev/null
+++ b/tests/data/compare/ezcGraphRenderer2dTest_testRenderPieChartWithTextureBackground.png
Binary files differ
diff --git a/tests/data/compare/ezcGraphRenderer3dTest_testRenderPieChartWithBackgroundBottomCenter.png b/tests/data/compare/ezcGraphRenderer3dTest_testRenderPieChartWithBackgroundBottomCenter.png
new file mode 100644
index 0000000..6744087
--- /dev/null
+++ b/tests/data/compare/ezcGraphRenderer3dTest_testRenderPieChartWithBackgroundBottomCenter.png
Binary files differ
diff --git a/tests/data/compare/ezcGraphRenderer3dTest_testRenderPieChartWithHorizontalTextureBackground.png b/tests/data/compare/ezcGraphRenderer3dTest_testRenderPieChartWithHorizontalTextureBackground.png
new file mode 100644
index 0000000..923830f
--- /dev/null
+++ b/tests/data/compare/ezcGraphRenderer3dTest_testRenderPieChartWithHorizontalTextureBackground.png
Binary files differ
diff --git a/tests/data/ez.png b/tests/data/ez.png
new file mode 100644
index 0000000..42f4799
--- /dev/null
+++ b/tests/data/ez.png
Binary files differ
diff --git a/tests/data/texture.png b/tests/data/texture.png
new file mode 100644
index 0000000..13edfe8
--- /dev/null
+++ b/tests/data/texture.png
Binary files differ
diff --git a/tests/palette_test.php b/tests/palette_test.php
index 1223653..59e6c8d 100644
--- a/tests/palette_test.php
+++ b/tests/palette_test.php
@@ -313,7 +313,7 @@ class ezcGraphPaletteTest extends ezcTestCase
$this->assertEquals(
ezcGraphColor::fromHex( '#EEEEEC' ),
- $chart->options->background,
+ $chart->background->background,
'Chart background not set from pallet.'
);
}
diff --git a/tests/renderer_2d_test.php b/tests/renderer_2d_test.php
index cc2da38..81f4b96 100644
--- a/tests/renderer_2d_test.php
+++ b/tests/renderer_2d_test.php
@@ -1570,6 +1570,64 @@ class ezcGraphRenderer2dTest extends ezcImageTestCase
10
);
}
+
+ public function testRenderPieChartWithBackgroundBottomRight()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.png';
+
+ $chart = new ezcGraphPieChart();
+ $chart['sample'] = array(
+ 'Mozilla' => 4375,
+ 'IE' => 345,
+ 'Opera' => 1204,
+ 'wget' => 231,
+ 'Safari' => 987,
+ );
+
+ $chart->background->color = '#FFFFFFDD';
+ $chart->background->image = dirname( __FILE__ ) . '/data/ez.png';
+ $chart->background->position = ezcGraph::BOTTOM | ezcGraph::RIGHT;
+
+ $chart->driver = new ezcGraphGdDriver();
+ $chart->options->font = $this->basePath . 'font.ttf';
+ $chart->render( 500, 200, $filename );
+
+ $this->assertImageSimilar(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png',
+ 'Image does not look as expected.',
+ 10
+ );
+ }
+
+ public function testRenderPieChartWithTextureBackground()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.png';
+
+ $chart = new ezcGraphPieChart();
+ $chart['sample'] = array(
+ 'Mozilla' => 4375,
+ 'IE' => 345,
+ 'Opera' => 1204,
+ 'wget' => 231,
+ 'Safari' => 987,
+ );
+
+ $chart->background->color = '#FFFFFFDD';
+ $chart->background->image = dirname( __FILE__ ) . '/data/texture.png';
+ $chart->background->repeat = ezcGraph::HORIZONTAL | ezcGraph::VERTICAL;
+
+ $chart->driver = new ezcGraphGdDriver();
+ $chart->options->font = $this->basePath . 'font.ttf';
+ $chart->render( 500, 200, $filename );
+
+ $this->assertImageSimilar(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png',
+ 'Image does not look as expected.',
+ 10
+ );
+ }
}
?>
diff --git a/tests/renderer_3d_test.php b/tests/renderer_3d_test.php
index b9c5588..1cb25e1 100644
--- a/tests/renderer_3d_test.php
+++ b/tests/renderer_3d_test.php
@@ -49,6 +49,249 @@ class ezcGraphRenderer3dTest extends ezcImageTestCase
$this->removeTempDir();
}
+ public function testRenderBackgroundImage()
+ {
+ $driver = $this->getMock( 'ezcGraphGdDriver', array(
+ 'drawImage',
+ ) );
+
+ $driver->options->width = 400;
+ $driver->options->height = 200;
+
+ $driver
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 125., 43.5 ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+
+ $renderer = new ezcGraphRenderer3d();
+ $renderer->setDriver( $driver );
+ $renderer->drawBackgroundImage(
+ new ezcGraphBoundings( 0, 0, 400, 200 ),
+ dirname( __FILE__ ) . '/data/jpeg.jpg'
+ );
+ }
+
+ public function testRenderTopLeftBackgroundImage()
+ {
+ $driver = $this->getMock( 'ezcGraphGdDriver', array(
+ 'drawImage',
+ ) );
+
+ $driver->options->width = 400;
+ $driver->options->height = 200;
+
+ $driver
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 0., 0. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+
+ $renderer = new ezcGraphRenderer3d();
+ $renderer->setDriver( $driver );
+ $renderer->drawBackgroundImage(
+ new ezcGraphBoundings( 0, 0, 400, 200 ),
+ dirname( __FILE__ ) . '/data/jpeg.jpg',
+ ezcGraph::TOP | ezcGraph::LEFT
+ );
+ }
+
+ public function testRenderBottomRightBackgroundImage()
+ {
+ $driver = $this->getMock( 'ezcGraphGdDriver', array(
+ 'drawImage',
+ ) );
+
+ $driver->options->width = 400;
+ $driver->options->height = 200;
+
+ $driver
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 250., 87. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+
+ $renderer = new ezcGraphRenderer3d();
+ $renderer->setDriver( $driver );
+ $renderer->drawBackgroundImage(
+ new ezcGraphBoundings( 0, 0, 400, 200 ),
+ dirname( __FILE__ ) . '/data/jpeg.jpg',
+ ezcGraph::BOTTOM | ezcGraph::RIGHT
+ );
+ }
+
+ public function testRenderToBigBackgroundImage()
+ {
+ $driver = $this->getMock( 'ezcGraphGdDriver', array(
+ 'drawImage',
+ ) );
+
+ $driver->options->width = 400;
+ $driver->options->height = 200;
+
+ $driver
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 0., 0. ), 1. ),
+ $this->equalTo( 100., 1. ),
+ $this->equalTo( 100., 1. )
+ );
+
+ $renderer = new ezcGraphRenderer3d();
+ $renderer->setDriver( $driver );
+ $renderer->drawBackgroundImage(
+ new ezcGraphBoundings( 0, 0, 100, 100 ),
+ dirname( __FILE__ ) . '/data/jpeg.jpg',
+ ezcGraph::BOTTOM | ezcGraph::RIGHT
+ );
+ }
+
+ public function testRenderBackgroundImageRepeatX()
+ {
+ $driver = $this->getMock( 'ezcGraphGdDriver', array(
+ 'drawImage',
+ ) );
+
+ $driver->options->width = 400;
+ $driver->options->height = 200;
+
+ $driver
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 0., 87. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+ $driver
+ ->expects( $this->at( 1 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 150., 87. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+ $driver
+ ->expects( $this->at( 2 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 300., 87. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+
+ $renderer = new ezcGraphRenderer3d();
+ $renderer->setDriver( $driver );
+ $renderer->drawBackgroundImage(
+ new ezcGraphBoundings( 0, 0, 400, 200 ),
+ dirname( __FILE__ ) . '/data/jpeg.jpg',
+ ezcGraph::BOTTOM | ezcGraph::RIGHT,
+ ezcGraph::HORIZONTAL
+ );
+ }
+
+ public function testRenderBackgroundImageRepeatY()
+ {
+ $driver = $this->getMock( 'ezcGraphGdDriver', array(
+ 'drawImage',
+ ) );
+
+ $driver->options->width = 400;
+ $driver->options->height = 200;
+
+ $driver
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 250., 0. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+ $driver
+ ->expects( $this->at( 1 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 250., 113. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+
+ $renderer = new ezcGraphRenderer3d();
+ $renderer->setDriver( $driver );
+ $renderer->drawBackgroundImage(
+ new ezcGraphBoundings( 0, 0, 400, 200 ),
+ dirname( __FILE__ ) . '/data/jpeg.jpg',
+ ezcGraph::BOTTOM | ezcGraph::RIGHT,
+ ezcGraph::VERTICAL
+ );
+ }
+
+ public function testRenderBackgroundImageRepeatBoth()
+ {
+ $driver = $this->getMock( 'ezcGraphGdDriver', array(
+ 'drawImage',
+ ) );
+
+ $driver->options->width = 400;
+ $driver->options->height = 200;
+
+ $driver
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 0., 0. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+ $driver
+ ->expects( $this->at( 3 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 150., 113. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+ $driver
+ ->expects( $this->at( 5 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 300., 113. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+
+ $renderer = new ezcGraphRenderer3d();
+ $renderer->setDriver( $driver );
+ $renderer->drawBackgroundImage(
+ new ezcGraphBoundings( 0, 0, 400, 200 ),
+ dirname( __FILE__ ) . '/data/jpeg.jpg',
+ ezcGraph::BOTTOM | ezcGraph::RIGHT,
+ ezcGraph::VERTICAL | ezcGraph::HORIZONTAL
+ );
+ }
+
public function testRenderLabeledPieSegment()
{
$filename = $this->tempDir . __FUNCTION__ . '.png';
@@ -516,6 +759,65 @@ class ezcGraphRenderer3dTest extends ezcImageTestCase
10
);
}
+
+ public function testRenderPieChartWithBackgroundBottomCenter()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.png';
+
+ $chart = new ezcGraphPieChart();
+ $chart['sample'] = array(
+ 'Mozilla' => 4375,
+ 'IE' => 345,
+ 'Opera' => 1204,
+ 'wget' => 231,
+ 'Safari' => 987,
+ );
+
+ $chart->background->color = '#FFFFFFDD';
+ $chart->background->image = dirname( __FILE__ ) . '/data/ez.png';
+ $chart->background->position = ezcGraph::BOTTOM | ezcGraph::CENTER;
+
+ $chart->driver = new ezcGraphGdDriver();
+ $chart->options->font = $this->basePath . 'font.ttf';
+ $chart->render( 500, 200, $filename );
+
+ $this->assertImageSimilar(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png',
+ 'Image does not look as expected.',
+ 10
+ );
+ }
+
+ public function testRenderPieChartWithHorizontalTextureBackground()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.png';
+
+ $chart = new ezcGraphPieChart();
+ $chart['sample'] = array(
+ 'Mozilla' => 4375,
+ 'IE' => 345,
+ 'Opera' => 1204,
+ 'wget' => 231,
+ 'Safari' => 987,
+ );
+
+ $chart->background->color = '#FFFFFFDD';
+ $chart->background->image = dirname( __FILE__ ) . '/data/texture.png';
+ $chart->background->repeat = ezcGraph::HORIZONTAL;
+ $chart->background->position = ezcGraph::BOTTOM;
+
+ $chart->driver = new ezcGraphGdDriver();
+ $chart->options->font = $this->basePath . 'font.ttf';
+ $chart->render( 500, 200, $filename );
+
+ $this->assertImageSimilar(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png',
+ 'Image does not look as expected.',
+ 10
+ );
+ }
}
?>
OpenPOWER on IntegriCloud