diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | src/interfaces/chart.php | 77 | ||||
-rw-r--r-- | tests/chart_test.php | 34 | ||||
-rw-r--r-- | tests/custom_chart.php | 24 | ||||
-rw-r--r-- | tests/data/compare/ezcGraphChartTest_testCustomChartClass.svg | 2 |
5 files changed, 99 insertions, 45 deletions
@@ -1,3 +1,10 @@ +1.1beta3 - [releasedate] +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- Fixed issue #10828: PHP error when overwriting renderer in extended + ezGraphPieChart + + 1.1beta2 - Thursday 31 May 2007 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/interfaces/chart.php b/src/interfaces/chart.php index 96a44b1..1974bc0 100644 --- a/src/interfaces/chart.php +++ b/src/interfaces/chart.php @@ -10,6 +10,15 @@ /** * Class to represent a complete chart. * + * @property ezcGraphRenderer $renderer + * Renderer used to render chart + * @property ezcGraphDriver $driver + * Output driver used for chart + * @property ezcGraphPalette $palette + * Palette used for colorization of chart + * @property-read mixed $renderedFile + * Contains the filename of the rendered file, if rendered. + * * @package Graph * @version //autogentag// */ @@ -38,25 +47,11 @@ abstract class ezcGraphChart protected $data; /** - * Renderer for the chart - * - * @var ezcGraphRenderer - */ - protected $renderer; - - /** - * Driver for the chart + * Array containing chart properties * - * @var ezcGraphDriver - */ - protected $driver; - - /** - * Palette for default colorization - * - * @var ezcGraphPalette + * @var array */ - protected $palette; + protected $properties; /** * Contains the status wheather an element should be rendered @@ -66,13 +61,6 @@ abstract class ezcGraphChart protected $renderElement; /** - * Contains the filename of the rendered file, if rendered. - * - * @var mixed - */ - protected $renderedFile; - - /** * Constructor * * @param array $options Default option array @@ -81,8 +69,7 @@ abstract class ezcGraphChart */ public function __construct( array $options = array() ) { - $this->__set( 'palette', new ezcGraphPaletteTango() ); - + $this->palette = new ezcGraphPaletteTango(); $this->data = new ezcGraphChartDataContainer( $this ); // Add standard elements @@ -97,9 +84,12 @@ abstract class ezcGraphChart $this->elements['legend']->position = ezcGraph::LEFT; // Define standard renderer and driver - $this->driver = new ezcGraphSvgDriver(); - $this->renderer = new ezcGraphRenderer2d(); - $this->renderer->setDriver( $this->driver ); + $this->properties['driver'] = new ezcGraphSvgDriver(); + $this->properties['renderer'] = new ezcGraphRenderer2d(); + $this->properties['renderer']->setDriver( $this->driver ); + + // Initialize other properties + $this->properties['renderedFile'] = null; } /** @@ -152,9 +142,9 @@ abstract class ezcGraphChart case 'renderer': if ( $propertyValue instanceof ezcGraphRenderer ) { - $this->renderer = $propertyValue; - $this->renderer->setDriver( $this->driver ); - return $this->renderer; + $this->properties['renderer'] = $propertyValue; + $this->properties['renderer']->setDriver( $this->driver ); + return $this->properties['renderer']; } else { @@ -164,9 +154,9 @@ abstract class ezcGraphChart case 'driver': if ( $propertyValue instanceof ezcGraphDriver ) { - $this->driver = $propertyValue; - $this->renderer->setDriver( $this->driver ); - return $this->driver; + $this->properties['driver'] = $propertyValue; + $this->properties['renderer']->setDriver( $this->driver ); + return $this->properties['driver']; } else { @@ -176,15 +166,17 @@ abstract class ezcGraphChart case 'palette': if ( $propertyValue instanceof ezcGraphPalette ) { - $this->palette = $propertyValue; + $this->properties['palette'] = $propertyValue; + $this->setFromPalette( $this->palette ); } else { throw new ezcBaseValueException( "palette", $propertyValue, "instanceof ezcGraphPalette" ); } - $this->setFromPalette( $this->palette ); - + break; + case 'renderedFile': + $this->properties['renderedFile'] = (string) $propertyValue; break; case 'options': if ( $propertyValue instanceof ezcGraphChartOptions ) @@ -229,9 +221,9 @@ abstract class ezcGraphChart */ public function __get( $propertyName ) { - if ( isset( $this->$propertyName ) ) + if ( array_key_exists( $propertyName, $this->properties ) ) { - return $this->$propertyName; + return $this->properties[$propertyName]; } if ( isset( $this->elements[$propertyName] ) ) @@ -239,9 +231,10 @@ abstract class ezcGraphChart return $this->elements[$propertyName]; } - if ( $propertyName === 'options' ) + if ( ( $propertyName === 'options' ) || + ( $propertyName === 'data' ) ) { - return $this->options; + return $this->$propertyName; } else { diff --git a/tests/chart_test.php b/tests/chart_test.php index 02b6cac..436087b 100644 --- a/tests/chart_test.php +++ b/tests/chart_test.php @@ -9,13 +9,16 @@ * @license http://ez.no/licenses/new_bsd New BSD License */ +require_once dirname( __FILE__ ) . '/test_case.php'; +require_once dirname( __FILE__ ) . '/custom_chart.php'; + /** * Tests for ezcGraph class. * * @package ImageAnalysis * @subpackage Tests */ -class ezcGraphChartTest extends ezcTestCase +class ezcGraphChartTest extends ezcGraphTestCase { protected $testFiles = array( 'jpeg' => 'jpeg.jpg', @@ -23,6 +26,7 @@ class ezcGraphChartTest extends ezcTestCase 'invalid' => 'text.txt', ); + protected $tempDir; protected $basePath; public static function suite() @@ -32,9 +36,20 @@ class ezcGraphChartTest extends ezcTestCase protected function setUp() { + static $i = 0; + + $this->tempDir = $this->createTempDir( __CLASS__ . sprintf( '_%03d_', ++$i ) ) . '/'; $this->basePath = dirname( __FILE__ ) . '/data/'; } + protected function tearDown() + { + if ( !$this->hasFailed() ) + { + $this->removeTempDir(); + } + } + public function testSetTitle() { $pieChart = new ezcGraphPieChart(); @@ -72,7 +87,7 @@ class ezcGraphChartTest extends ezcTestCase $this->assertSame( $renderer, - $this->getAttribute( $pieChart, 'renderer' ) + $pieChart->renderer ); } @@ -104,7 +119,7 @@ class ezcGraphChartTest extends ezcTestCase $this->assertSame( $driver, - $this->getAttribute( $pieChart, 'driver' ) + $pieChart->driver ); } @@ -148,5 +163,18 @@ class ezcGraphChartTest extends ezcTestCase return true; } } + + public function testCustomChartClass() + { + $filename = $this->tempDir . __FUNCTION__ . '.svg'; + + $chart = new ezcCustomTestChart(); + $chart->render( 400, 200, $filename ); + + $this->compare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' + ); + } } ?> diff --git a/tests/custom_chart.php b/tests/custom_chart.php new file mode 100644 index 0000000..e7760bc --- /dev/null +++ b/tests/custom_chart.php @@ -0,0 +1,24 @@ +<?php + +class ezcCustomTestChart extends ezcGraphPieChart +{ + public function __construct( array $options = array() ) + { + parent::__construct( $options ); + + $this->driver = new ezcGraphSvgDriver(); + $this->renderer = new ezcGraphRenderer3d(); + + $this->palette = new ezcGraphPaletteEzBlue(); + + $this->title = 'Test chart'; + + $this->data['testdata'] = new ezcGraphArrayDataSet( array( + 'foo' => 123, + 'bar' => 43, + 'blubb' => 453, + ) ); + } +} + +?> diff --git a/tests/data/compare/ezcGraphChartTest_testCustomChartClass.svg b/tests/data/compare/ezcGraphChartTest_testCustomChartClass.svg new file mode 100644 index 0000000..3ad044a --- /dev/null +++ b/tests/data/compare/ezcGraphChartTest_testCustomChartClass.svg @@ -0,0 +1,2 @@ +<?xml version="1.0"?> +<svg xmlns="http://www.w3.org/2000/svg" width="400" height="200" version="1.0" id="ezcGraph"><defs><linearGradient id="Definition_LinearGradient_168_105_312_105_ffffffbf_0000007f"><stop offset="0" style="stop-color: #ffffff; stop-opacity: 0.25;"/><stop offset="1" style="stop-color: #000000; stop-opacity: 0.50;"/></linearGradient><linearGradient xmlns:xlink="http://www.w3.org/1999/xlink" id="LinearGradient_168_105_312_105_ffffffbf_0000007f" x1="168.0000" y1="105.0000" x2="312.0000" y2="105.0000" gradientUnits="userSpaceOnUse" xlink:href="#Definition_LinearGradient_168_105_312_105_ffffffbf_0000007f"/></defs><g id="ezcGraphChart" color-rendering="optimizeQuality" shape-rendering="geometricPrecision" text-rendering="optimizeLegibility"><path d=" M 0.0000,200.0000 L 0.0000,0.0000 L 400.0000,0.0000 L 400.0000,200.0000 L 0.0000,200.0000 z " style="fill: #ffffff; fill-opacity: 1.00; stroke: none;" id="ezcGraphPolygon_1"/><path d=" M 0.0000,20.0000 L 0.0000,0.0000 L 400.0000,0.0000 L 400.0000,20.0000 L 0.0000,20.0000 z " style="fill: #000000; fill-opacity: 0.00; stroke: none;" id="ezcGraphPolygon_2"/><path d=" M 0.0000,200.0000 L 0.0000,20.0000 L 80.0000,20.0000 L 80.0000,200.0000 L 0.0000,200.0000 z " style="fill: #000000; fill-opacity: 0.00; stroke: none;" id="ezcGraphPolygon_4"/><ellipse cx="9.0000" cy="29.0000" rx="7.0000" ry="7.0000" style="fill: #699bff; fill-opacity: 1.00; stroke: none;" id="ezcGraphCircle_5"/><ellipse cx="9.0000" cy="47.0000" rx="7.0000" ry="7.0000" style="fill: #85aeff; fill-opacity: 1.00; stroke: none;" id="ezcGraphCircle_7"/><ellipse cx="9.0000" cy="65.0000" rx="7.0000" ry="7.0000" style="fill: #a3c2ff; fill-opacity: 1.00; stroke: none;" id="ezcGraphCircle_9"/><path d="M 168.00,115.00 A 72.00,38.20 0 0,0 231.80,152.95 L 231.80,142.95 A 72.00,38.200000 0 0,1 168.00,105.00 z" style="fill: #a3c2ff; fill-opacity: 1.00; stroke: none;" id="ezcGraphCircularArc_11"/><path d="M 168.00,115.00 A 72.00,38.20 0 0,0 231.80,152.95 L 231.80,142.95 A 72.00,38.200000 0 0,1 168.00,105.00 z" style="fill: url(#LinearGradient_168_105_312_105_ffffffbf_0000007f); stroke: none;"/><path d="M 312.00,115.00 A 72.00,38.20 0 0,0 168.00,115.00 L 168.00,105.00 A 72.00,38.200000 0 0,1 312.00,105.00 z" style="fill: #a3c2ff; fill-opacity: 1.00; stroke: none;" id="ezcGraphCircularArc_12"/><path d="M 312.00,115.00 A 72.00,38.20 0 0,0 168.00,115.00 L 168.00,105.00 A 72.00,38.200000 0 0,1 312.00,105.00 z" style="fill: url(#LinearGradient_168_105_312_105_ffffffbf_0000007f); stroke: none;"/><path d=" M 312.0000,105.0000 L 240.0000,105.0000 L 240.0000,115.0000 L 312.0000,115.0000 L 312.0000,105.0000 z " style="fill: #699bff; fill-opacity: 1.00; stroke: none;" id="ezcGraphPolygon_13"/><path d=" M 240.5000,105.5000 L 240.5000,114.5000 L 311.5000,114.5000 L 311.5000,105.5000 L 240.5000,105.5000 z " style="fill: none; stroke: #354e80; stroke-width: 1; stroke-opacity: 1.00; stroke-linecap: round; stroke-linejoin: round;" id="ezcGraphPolygon_14"/><path d=" M 312.0000,105.0000 L 240.0000,105.0000 L 240.0000,115.0000 L 312.0000,115.0000 L 312.0000,105.0000 z " style="fill: #a3c2ff; fill-opacity: 1.00; stroke: none;" id="ezcGraphPolygon_15"/><path d=" M 240.5000,105.5000 L 240.5000,114.5000 L 311.5000,114.5000 L 311.5000,105.5000 L 240.5000,105.5000 z " style="fill: none; stroke: #526180; stroke-width: 1; stroke-opacity: 1.00; stroke-linecap: round; stroke-linejoin: round;" id="ezcGraphPolygon_16"/><path d=" M 262.8045,141.2333 L 240.0000,105.0000 L 240.0000,115.0000 L 262.8045,151.2333 L 262.8045,141.2333 z " style="fill: #699bff; fill-opacity: 1.00; stroke: none;" id="ezcGraphPolygon_17"/><path d=" M 240.5000,106.7331 L 240.5000,114.8558 L 262.3045,149.5002 L 262.3045,141.3776 L 240.5000,106.7331 z " style="fill: none; stroke: #354e80; stroke-width: 1; stroke-opacity: 1.00; stroke-linecap: round; stroke-linejoin: round;" id="ezcGraphPolygon_18"/><path d=" M 262.8045,141.2333 L 240.0000,105.0000 L 240.0000,115.0000 L 262.8045,151.2333 L 262.8045,141.2333 z " style="fill: #85aeff; fill-opacity: 1.00; stroke: none;" id="ezcGraphPolygon_19"/><path d=" M 240.5000,106.7331 L 240.5000,114.8558 L 262.3045,149.5002 L 262.3045,141.3776 L 240.5000,106.7331 z " style="fill: none; stroke: #435780; stroke-width: 1; stroke-opacity: 1.00; stroke-linecap: round; stroke-linejoin: round;" id="ezcGraphPolygon_20"/><path d=" M 231.7959,142.9512 L 240.0000,105.0000 L 240.0000,115.0000 L 231.7959,152.9512 L 231.7959,142.9512 z " style="fill: #85aeff; fill-opacity: 1.00; stroke: none;" id="ezcGraphPolygon_21"/><path d=" M 239.5000,109.6793 L 239.5000,114.9466 L 232.2959,148.2719 L 232.2959,143.0046 L 239.5000,109.6793 z " style="fill: none; stroke: #435780; stroke-width: 1; stroke-opacity: 1.00; stroke-linecap: round; stroke-linejoin: round;" id="ezcGraphPolygon_22"/><path d=" M 231.7959,142.9512 L 240.0000,105.0000 L 240.0000,115.0000 L 231.7959,152.9512 L 231.7959,142.9512 z " style="fill: #a3c2ff; fill-opacity: 1.00; stroke: none;" id="ezcGraphPolygon_23"/><path d=" M 239.5000,109.6793 L 239.5000,114.9466 L 232.2959,148.2719 L 232.2959,143.0046 L 239.5000,109.6793 z " style="fill: none; stroke: #526180; stroke-width: 1; stroke-opacity: 1.00; stroke-linecap: round; stroke-linejoin: round;" id="ezcGraphPolygon_24"/><path d="M 262.80,151.23 A 72.00,38.20 0 0,0 312.00,115.00 L 312.00,105.00 A 72.00,38.200000 0 0,1 262.80,141.23 z" style="fill: #699bff; fill-opacity: 1.00; stroke: none;" id="ezcGraphCircularArc_25"/><path d="M 262.80,151.23 A 72.00,38.20 0 0,0 312.00,115.00 L 312.00,105.00 A 72.00,38.200000 0 0,1 262.80,141.23 z" style="fill: url(#LinearGradient_168_105_312_105_ffffffbf_0000007f); stroke: none;"/><path d="M 231.80,152.95 A 72.00,38.20 0 0,0 262.80,151.23 L 262.80,141.23 A 72.00,38.200000 0 0,1 231.80,142.95 z" style="fill: #85aeff; fill-opacity: 1.00; stroke: none;" id="ezcGraphCircularArc_26"/><path d="M 231.80,152.95 A 72.00,38.20 0 0,0 262.80,151.23 L 262.80,141.23 A 72.00,38.200000 0 0,1 231.80,142.95 z" style="fill: url(#LinearGradient_168_105_312_105_ffffffbf_0000007f); stroke: none;"/><path d="M 240.00,105.00 L 312.00,105.00 A 72.00,38.20 0 0,1 262.80,141.23 z" style="fill: #699bff; fill-opacity: 1.00; stroke: none;" id="ezcGraphCircleSector_27"/><path d="M 240.69,105.50 L 311.50,105.50 A 71.50,37.70 0 0,1 263.03,140.72 z" style="fill: none; stroke: #354e80; stroke-width: 1; stroke-opacity: 1.00; stroke-linecap: round; stroke-linejoin: round;" id="ezcGraphCircleSector_28"/><path d="M 240.00,105.00 L 262.80,141.23 A 72.00,38.20 0 0,1 231.80,142.95 z" style="fill: #85aeff; fill-opacity: 1.00; stroke: none;" id="ezcGraphCircleSector_29"/><path d="M 240.78,107.17 L 262.05,140.90 A 71.50,37.70 0 0,1 232.40,142.49 z" style="fill: none; stroke: #435780; stroke-width: 1; stroke-opacity: 1.00; stroke-linecap: round; stroke-linejoin: round;" id="ezcGraphCircleSector_30"/><path d="M 240.00,105.00 L 231.80,142.95 A 72.00,38.20 0 1,1 312.00,105.00 z" style="fill: #a3c2ff; fill-opacity: 1.00; stroke: none;" id="ezcGraphCircleSector_31"/><path d="M 239.61,104.46 L 231.40,142.43 A 71.50,37.70 0 1,1 311.50,104.50 z" style="fill: none; stroke: #526180; stroke-width: 1; stroke-opacity: 1.00; stroke-linecap: round; stroke-linejoin: round;" id="ezcGraphCircleSector_32"/><path d=" M 208.0511,86.1931 L 165.3050,69.0000" style="fill: none; stroke: #000000; stroke-width: 1; stroke-opacity: 1.00; stroke-linecap: round; stroke-linejoin: round;" id="ezcGraphLine_33"/><ellipse cx="208.0511" cy="86.1931" rx="3.0000" ry="3.0000" style="fill: #000000; fill-opacity: 1.00; stroke: none;" id="ezcGraphCircle_34"/><ellipse cx="165.3050" cy="69.0000" rx="3.0000" ry="3.0000" style="fill: #000000; fill-opacity: 1.00; stroke: none;" id="ezcGraphCircle_35"/><path d=" M 278.9470,119.7293 L 322.6225,133.0000" style="fill: none; stroke: #000000; stroke-width: 1; stroke-opacity: 1.00; stroke-linecap: round; stroke-linejoin: round;" id="ezcGraphLine_37"/><ellipse cx="278.9470" cy="119.7293" rx="3.0000" ry="3.0000" style="fill: #000000; fill-opacity: 1.00; stroke: none;" id="ezcGraphCircle_38"/><ellipse cx="322.6225" cy="133.0000" rx="3.0000" ry="3.0000" style="fill: #000000; fill-opacity: 1.00; stroke: none;" id="ezcGraphCircle_39"/><path d=" M 244.9851,130.0637 L 314.0882,152.0000" style="fill: none; stroke: #000000; stroke-width: 1; stroke-opacity: 1.00; stroke-linecap: round; stroke-linejoin: round;" id="ezcGraphLine_41"/><ellipse cx="244.9851" cy="130.0637" rx="3.0000" ry="3.0000" style="fill: #000000; fill-opacity: 1.00; stroke: none;" id="ezcGraphCircle_42"/><ellipse cx="314.0882" cy="152.0000" rx="3.0000" ry="3.0000" style="fill: #000000; fill-opacity: 1.00; stroke: none;" id="ezcGraphCircle_43"/><g id="ezcGraphTextBox_3"><path d=" M 151.8000,20.0000 L 151.8000,0.5000 L 248.7000,0.5000 L 248.7000,20.0000 L 151.8000,20.0000 z " style="fill: #ffffff; fill-opacity: 0.00; stroke: none;" id="ezcGraphPolygon_45"/><text id="ezcGraphTextBox_3_text" x="152.3000" text-length="95.4000px" y="16.3000" style="font-size: 18px; font-family: sans-serif; fill: #2e3436; fill-opacity: 1.00; stroke: none;">Test chart</text></g><g id="ezcGraphTextBox_6"><path d=" M 16.5000,37.0000 L 16.5000,21.5000 L 40.2600,21.5000 L 40.2600,37.0000 L 16.5000,37.0000 z " style="fill: #ffffff; fill-opacity: 0.00; stroke: none;" id="ezcGraphPolygon_46"/><text id="ezcGraphTextBox_6_text" x="17.0000" text-length="22.2600px" y="33.9000" style="font-size: 14px; font-family: sans-serif; fill: #2e3436; fill-opacity: 1.00; stroke: none;">foo</text></g><g id="ezcGraphTextBox_8"><path d=" M 16.5000,55.0000 L 16.5000,39.5000 L 40.2600,39.5000 L 40.2600,55.0000 L 16.5000,55.0000 z " style="fill: #ffffff; fill-opacity: 0.00; stroke: none;" id="ezcGraphPolygon_47"/><text id="ezcGraphTextBox_8_text" x="17.0000" text-length="22.2600px" y="51.9000" style="font-size: 14px; font-family: sans-serif; fill: #2e3436; fill-opacity: 1.00; stroke: none;">bar</text></g><g id="ezcGraphTextBox_10"><path d=" M 16.5000,73.0000 L 16.5000,57.5000 L 55.1000,57.5000 L 55.1000,73.0000 L 16.5000,73.0000 z " style="fill: #ffffff; fill-opacity: 0.00; stroke: none;" id="ezcGraphPolygon_48"/><text id="ezcGraphTextBox_10_text" x="17.0000" text-length="37.1000px" y="69.9000" style="font-size: 14px; font-family: sans-serif; fill: #2e3436; fill-opacity: 1.00; stroke: none;">blubb</text></g><g id="ezcGraphTextBox_36"><path d=" M 82.4850,74.0000 L 82.4850,64.5000 L 160.3050,64.5000 L 160.3050,74.0000 L 82.4850,74.0000 z " style="fill: #ffffff; fill-opacity: 0.00; stroke: none;" id="ezcGraphPolygon_49"/><text id="ezcGraphTextBox_36_text" x="82.9850" text-length="76.3200px" y="71.8000" style="font-size: 8px; font-family: sans-serif; fill: #2e3436; fill-opacity: 1.00; stroke: none;">blubb: 453 (73.2%)</text></g><g id="ezcGraphTextBox_40"><path d=" M 328.1225,138.0000 L 328.1225,128.5000 L 397.4625,128.5000 L 397.4625,138.0000 L 328.1225,138.0000 z " style="fill: #ffffff; fill-opacity: 0.00; stroke: none;" id="ezcGraphPolygon_50"/><text id="ezcGraphTextBox_40_text" x="328.6225" text-length="67.8400px" y="135.8000" style="font-size: 8px; font-family: sans-serif; fill: #2e3436; fill-opacity: 1.00; stroke: none;">foo: 123 (19.9%)</text></g><g id="ezcGraphTextBox_44"><path d=" M 319.5882,157.0000 L 319.5882,147.5000 L 380.4482,147.5000 L 380.4482,157.0000 L 319.5882,157.0000 z " style="fill: #ffffff; fill-opacity: 0.00; stroke: none;" id="ezcGraphPolygon_51"/><text id="ezcGraphTextBox_44_text" x="320.0882" text-length="59.3600px" y="154.8000" style="font-size: 8px; font-family: sans-serif; fill: #2e3436; fill-opacity: 1.00; stroke: none;">bar: 43 (6.9%)</text></g></g></svg> |