diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2009-01-15 09:48:12 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2009-01-15 09:48:12 +0000 |
commit | d23dd4b60242ffb23dbd0d294e7cef3bcdac6aff (patch) | |
tree | 7be32c8a8bc9e30cd740b9db86ca0ea5d143bbbe | |
parent | b55f6d4f3303dc7c123939207f28297906c92e88 (diff) | |
download | zetacomponents-graph-d23dd4b60242ffb23dbd0d294e7cef3bcdac6aff.zip zetacomponents-graph-d23dd4b60242ffb23dbd0d294e7cef3bcdac6aff.tar.gz |
- Implemented feature #12897: Add the possibility to have a subtitle for
Graphs.
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | src/interfaces/chart.php | 9 | ||||
-rw-r--r-- | tests/text_test.php | 98 |
3 files changed, 107 insertions, 2 deletions
@@ -3,6 +3,8 @@ - Resolved task #14219: Refactor grid drawing to be less susceptible to floating point inaccuracies +- Implemented feature #12897: Add the possibility to have a subtitle for + Graphs. 1.4 - Monday 05 January 2009 diff --git a/src/interfaces/chart.php b/src/interfaces/chart.php index 1e6492f..4b76d5a 100644 --- a/src/interfaces/chart.php +++ b/src/interfaces/chart.php @@ -80,6 +80,10 @@ abstract class ezcGraphChart $this->elements['title']->position = ezcGraph::TOP; $this->renderElement['title'] = false; + $this->addElement( 'subtitle', new ezcGraphChartElementText() ); + $this->elements['subtitle']->position = ezcGraph::TOP; + $this->renderElement['subtitle'] = false; + $this->addElement( 'legend', new ezcGraphChartElementLegend() ); $this->elements['legend']->position = ezcGraph::LEFT; @@ -128,8 +132,9 @@ abstract class ezcGraphChart { switch ( $propertyName ) { case 'title': - $this->elements['title']->title = $propertyValue; - $this->renderElement['title'] = true; + case 'subtitle': + $this->elements[$propertyName]->title = $propertyValue; + $this->renderElement[$propertyName] = true; break; case 'legend': if ( !is_bool( $propertyValue ) ) diff --git a/tests/text_test.php b/tests/text_test.php index 1a74f7c..6f8b655 100644 --- a/tests/text_test.php +++ b/tests/text_test.php @@ -110,6 +110,104 @@ class ezcGraphTextTest extends ezcTestCase $chart->render( 500, 200 ); } + + public function testRenderSubtitleOnly() + { + $chart = new ezcGraphLineChart(); + $chart->data['sample'] = new ezcGraphArrayDataSet( array( 'foo' => 1, 'bar' => 10 ) ); + + $chart->subtitle = 'Subtitle of a chart'; + $chart->subtitle->margin = 5; + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2d', array( + 'drawText', + ) ); + + // Y-Axis + $mockedRenderer + ->expects( $this->at( 0 ) ) + ->method( 'drawText' ) + ->with( + $this->equalTo( new ezcGraphBoundings( 6, 6, 494, 14 ) ), + $this->equalTo( 'Subtitle of a chart' ), + $this->equalTo( ezcGraph::CENTER | ezcGraph::MIDDLE ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); + } + + public function testRenderTitleAndSubtitle() + { + $chart = new ezcGraphLineChart(); + $chart->data['sample'] = new ezcGraphArrayDataSet( array( 'foo' => 1, 'bar' => 10 ) ); + + $chart->title = 'Title of a chart'; + $chart->subtitle = 'Subtitle of a chart'; + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2d', array( + 'drawText', + ) ); + + // Y-Axis + $mockedRenderer + ->expects( $this->at( 0 ) ) + ->method( 'drawText' ) + ->with( + $this->equalTo( new ezcGraphBoundings( 1, 1, 499, 19 ) ), + $this->equalTo( 'Title of a chart' ), + $this->equalTo( ezcGraph::CENTER | ezcGraph::MIDDLE ) + ); + $mockedRenderer + ->expects( $this->at( 1 ) ) + ->method( 'drawText' ) + ->with( + $this->equalTo( new ezcGraphBoundings( 1, 21, 499, 37 ) ), + $this->equalTo( 'Subtitle of a chart' ), + $this->equalTo( ezcGraph::CENTER | ezcGraph::MIDDLE ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); + } + + public function testRenderTitleAndBottomSubtitle() + { + $chart = new ezcGraphLineChart(); + $chart->data['sample'] = new ezcGraphArrayDataSet( array( 'foo' => 1, 'bar' => 10 ) ); + + $chart->title = 'Title of a chart'; + $chart->subtitle = 'Subtitle of a chart'; + $chart->subtitle->position = ezcGraph::BOTTOM; + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2d', array( + 'drawText', + ) ); + + // Y-Axis + $mockedRenderer + ->expects( $this->at( 0 ) ) + ->method( 'drawText' ) + ->with( + $this->equalTo( new ezcGraphBoundings( 1, 1, 499, 19 ) ), + $this->equalTo( 'Title of a chart' ), + $this->equalTo( ezcGraph::CENTER | ezcGraph::MIDDLE ) + ); + $mockedRenderer + ->expects( $this->at( 1 ) ) + ->method( 'drawText' ) + ->with( + $this->equalTo( new ezcGraphBoundings( 1, 183, 499, 199 ) ), + $this->equalTo( 'Subtitle of a chart' ), + $this->equalTo( ezcGraph::CENTER | ezcGraph::MIDDLE ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); + } } ?> |