diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2006-06-14 13:12:24 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2006-06-14 13:12:24 +0000 |
commit | aa0997b7670abfc7884f3f3406a56c25b675634b (patch) | |
tree | 59ef8a7af05068bc371cf962212ac17dd8f63f11 | |
parent | 815444c46accf9b5d6868daef2c5070bbf186476 (diff) | |
download | zetacomponents-graph-aa0997b7670abfc7884f3f3406a56c25b675634b.zip zetacomponents-graph-aa0997b7670abfc7884f3f3406a56c25b675634b.tar.gz |
- Disable rendering of selected chart elements
-rw-r--r-- | src/charts/line.php | 6 | ||||
-rw-r--r-- | src/charts/pie.php | 6 | ||||
-rw-r--r-- | src/interfaces/chart.php | 16 | ||||
-rw-r--r-- | tests/line_test.php | 28 | ||||
-rw-r--r-- | tests/pie_test.php | 31 |
5 files changed, 87 insertions, 0 deletions
diff --git a/src/charts/line.php b/src/charts/line.php index c86ff29..d45ec51 100644 --- a/src/charts/line.php +++ b/src/charts/line.php @@ -168,6 +168,12 @@ class ezcGraphLineChart extends ezcGraphChart // Render subelements foreach ( $this->elements as $name => $element ) { + // Skip element, if it should not get rendered + if ( $this->renderElement[$name] === false ) + { + continue; + } + // Special settings for special elements switch ( $name ) { diff --git a/src/charts/pie.php b/src/charts/pie.php index 8645c08..67a628f 100644 --- a/src/charts/pie.php +++ b/src/charts/pie.php @@ -212,6 +212,12 @@ class ezcGraphPieChart extends ezcGraphChart // Render subelements foreach ( $this->elements as $name => $element ) { + // Skip element, if it should not get rendered + if ( $this->renderElement[$name] === false ) + { + continue; + } + $this->driver->options->font = $element->font; $boundings = $element->render( $this->renderer, $boundings ); } diff --git a/src/interfaces/chart.php b/src/interfaces/chart.php index b1bf7f7..de990bd 100644 --- a/src/interfaces/chart.php +++ b/src/interfaces/chart.php @@ -57,6 +57,14 @@ abstract class ezcGraphChart */ protected $palette; + + /** + * Contains the status wheather an element should be rendered + * + * @var array + */ + protected $renderElement; + public function __construct( array $options = array() ) { $this->__set( 'palette', 'Tango' ); @@ -64,6 +72,7 @@ abstract class ezcGraphChart // Add standard elements $this->addElement( 'title', new ezcGraphChartElementText() ); $this->elements['title']->position = ezcGraph::TOP; + $this->renderElement['title'] = false; $this->addElement( 'legend', new ezcGraphChartElementLegend() ); $this->elements['legend']->position = ezcGraph::LEFT; @@ -79,6 +88,9 @@ abstract class ezcGraphChart $this->elements[$name] = $element; $this->elements[$name]->font = $this->options->font; $this->elements[$name]->setFromPalette( $this->palette ); + + // Render element by default + $this->renderElement[$name] = true; } /** @@ -97,6 +109,10 @@ abstract class ezcGraphChart switch ( $propertyName ) { case 'title': $this->elements['title']->title = $propertyValue; + $this->renderElement['title'] = true; + break; + case 'legend': + $this->renderElement['legend'] = (bool) $propertyValue; break; case 'renderer': if ( $propertyValue instanceof ezcGraphRenderer ) diff --git a/tests/line_test.php b/tests/line_test.php index d672c98..114f022 100644 --- a/tests/line_test.php +++ b/tests/line_test.php @@ -242,5 +242,33 @@ class ezcGraphLineChartTest extends ezcTestCase 'Incorrect image rendered.' ); } + + public function testCompleteRenderingWithoutLegend() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $chart = ezcGraph::create( 'Line' ); + $chart->title = 'Test graph'; + $chart->palette = 'Black'; + + $this->addSampleData( $chart ); + $chart->legend = false; + $chart->driver = new ezcGraphGdDriver(); + + $chart->options->font = $this->basePath . 'font.ttf'; + $chart->legend->font = $this->basePath . 'font2.ttf'; + $chart->render( 500, 200, $filename ); + + $this->assertTrue( + file_exists( $filename ), + 'No image was generated.' + ); + + $this->assertEquals( + '8735eff094555c48d2121c50d7359266', + md5_file( $filename ), + 'Incorrect image rendered.' + ); + } } ?> diff --git a/tests/pie_test.php b/tests/pie_test.php index 95243c6..620b77e 100644 --- a/tests/pie_test.php +++ b/tests/pie_test.php @@ -307,6 +307,37 @@ class ezcGraphPieChartTest extends ezcTestCase ); } + public function testCompleteRenderingWithoutLegend() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $chart = ezcGraph::create( 'Pie' ); + + $chart->sample = array( + 'Mozilla' => 4375, + 'IE' => 345, + 'Opera' => 1204, + 'wget' => 231, + 'Safari' => 987, + ); + + $chart->legend = false; + $chart->driver = new ezcGraphGdDriver(); + $chart->options->font = $this->basePath . 'font.ttf'; + $chart->render( 400, 200, $filename ); + + $this->assertTrue( + file_exists( $filename ), + 'No image was generated.' + ); + + $this->assertEquals( + 'd8186025828b208c2451333f22d9159c', + md5_file( $filename ), + 'Incorrect image rendered.' + ); + } + public function testCompleteRenderingWithHilight() { $filename = $this->tempDir . __FUNCTION__ . '.png'; |