Author: Kore Nordmann
Date: 2006-06-14 15:12:24 +0200 (Wed, 14 Jun 2006)
New Revision: 3130
Log:
- Disable rendering of selected chart elements
Modified:
trunk/Graph/src/charts/line.php
trunk/Graph/src/charts/pie.php
trunk/Graph/src/interfaces/chart.php
trunk/Graph/tests/line_test.php
trunk/Graph/tests/pie_test.php
Modified: trunk/Graph/src/charts/line.php
===================================================================
--- trunk/Graph/src/charts/line.php 2006-06-14 13:03:43 UTC (rev 3129)
+++ trunk/Graph/src/charts/line.php 2006-06-14 13:12:24 UTC (rev 3130)
@@ -168,6 +168,12 @@
// 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 )
{
Modified: trunk/Graph/src/charts/pie.php
===================================================================
--- trunk/Graph/src/charts/pie.php 2006-06-14 13:03:43 UTC (rev 3129)
+++ trunk/Graph/src/charts/pie.php 2006-06-14 13:12:24 UTC (rev 3130)
@@ -212,6 +212,12 @@
// 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 );
}
Modified: trunk/Graph/src/interfaces/chart.php
===================================================================
--- trunk/Graph/src/interfaces/chart.php 2006-06-14 13:03:43 UTC (rev
3129)
+++ trunk/Graph/src/interfaces/chart.php 2006-06-14 13:12:24 UTC (rev
3130)
@@ -57,6 +57,14 @@
*/
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 @@
// 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 @@
$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,7 +109,11 @@
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 )
{
Modified: trunk/Graph/tests/line_test.php
===================================================================
--- trunk/Graph/tests/line_test.php 2006-06-14 13:03:43 UTC (rev 3129)
+++ trunk/Graph/tests/line_test.php 2006-06-14 13:12:24 UTC (rev 3130)
@@ -242,5 +242,33 @@
'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.'
+ );
+ }
}
?>
Modified: trunk/Graph/tests/pie_test.php
===================================================================
--- trunk/Graph/tests/pie_test.php 2006-06-14 13:03:43 UTC (rev 3129)
+++ trunk/Graph/tests/pie_test.php 2006-06-14 13:12:24 UTC (rev 3130)
@@ -307,6 +307,37 @@
);
}
+ 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';
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components