summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-07-24 13:18:08 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-07-24 13:18:08 +0000
commit71789ffa110bba70d34bf937b315b10ee8c17aad (patch)
tree9ad6d196ac175c9e9562b90d6bd00396a428cde4
parentff849eb9f302289b044b9f98eadc02cca4ed2130 (diff)
downloadzetacomponents-graph-71789ffa110bba70d34bf937b315b10ee8c17aad.zip
zetacomponents-graph-71789ffa110bba70d34bf937b315b10ee8c17aad.tar.gz
- Added axis label renderer for centered labels
- Fixed: Do not draw grids and steps on other axis
-rw-r--r--src/axis/labeled.php13
-rw-r--r--src/axis/numeric.php13
-rw-r--r--src/element/axis.php17
-rw-r--r--src/renderer/axis_label_centered.php96
-rw-r--r--src/renderer/axis_label_exact.php19
-rw-r--r--tests/axis_centered_renderer_test.php532
-rw-r--r--tests/axis_exact_renderer_test.php86
-rw-r--r--tests/data/compare/ezcGraphCompleteRenderingTest_testRenderLineChart.pngbin85969 -> 87449 bytes
-rw-r--r--tests/data/compare/ezcGraphCompleteRenderingTest_testRenderLineChartReverse.pngbin85900 -> 87392 bytes
-rw-r--r--tests/suite.php2
10 files changed, 681 insertions, 97 deletions
diff --git a/src/axis/labeled.php b/src/axis/labeled.php
index cf1277f..7b1225c 100644
--- a/src/axis/labeled.php
+++ b/src/axis/labeled.php
@@ -204,6 +204,19 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis
return false;
}
}
+
+ /**
+ * Is zero step
+ *
+ * Returns true if the given step is the one on the initial axis position
+ *
+ * @param int $step Number of step
+ * @return bool Status If given step is initial axis position
+ */
+ public function isZeroStep( $step )
+ {
+ return !$step;
+ }
}
?>
diff --git a/src/axis/numeric.php b/src/axis/numeric.php
index 8713f1c..5a478e1 100644
--- a/src/axis/numeric.php
+++ b/src/axis/numeric.php
@@ -326,6 +326,19 @@ class ezcGraphChartElementNumericAxis extends ezcGraphChartElementAxis
{
return $this->min + ( $step * $this->majorStep );
}
+
+ /**
+ * Is zero step
+ *
+ * Returns true if the given step is the one on the initial axis position
+ *
+ * @param int $step Number of step
+ * @return bool Status If given step is initial axis position
+ */
+ public function isZeroStep( $step )
+ {
+ return ( $this->getLabel( $step ) == 0 );
+ }
}
?>
diff --git a/src/element/axis.php b/src/element/axis.php
index 7fb051a..b4805fa 100644
--- a/src/element/axis.php
+++ b/src/element/axis.php
@@ -82,9 +82,12 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement
public function __construct( array $options = array() )
{
- $this->axisLabelRenderer = new ezcGraphAxisExactLabelRenderer();
-
parent::__construct( $options );
+
+ if ( !isset( $this->axisLabelRenderer ) )
+ {
+ $this->axisLabelRenderer = new ezcGraphAxisExactLabelRenderer();
+ }
}
/**
@@ -210,6 +213,16 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement
abstract public function getLabel( $step );
/**
+ * Is zero step
+ *
+ * Returns true if the given step is the one on the initial axis position
+ *
+ * @param int $step Number of step
+ * @return bool Status If given step is initial axis position
+ */
+ abstract public function isZeroStep( $step );
+
+ /**
* Add data for this axis
*
* @param mixed $value Value which will be displayed on this axis
diff --git a/src/renderer/axis_label_centered.php b/src/renderer/axis_label_centered.php
index 23813b1..1744052 100644
--- a/src/renderer/axis_label_centered.php
+++ b/src/renderer/axis_label_centered.php
@@ -17,12 +17,24 @@ class ezcGraphAxisCenteredLabelRenderer extends ezcGraphAxisLabelRenderer
{
/**
- * Show the last value on the axis, which will be aligned different than
- * all other values, to not interfere with the arrow head of the axis.
- *
+ * Show the value at the zero point of an axis. This value might be
+ * crossed by the other axis which would result in an unreadable label.
+ *
* @var boolean
*/
- protected $showLastValue = true;
+ protected $showZeroValue = false;
+
+ public function __set( $propertyName, $propertyValue )
+ {
+ switch ( $propertyName )
+ {
+ case 'showZeroValue':
+ $this->showZeroValue = (bool) $propertyValue;
+ break;
+ default:
+ return parent::__set( $propertyName, $propertyValue );
+ }
+ }
/**
* Render Axis labels
@@ -43,7 +55,6 @@ class ezcGraphAxisCenteredLabelRenderer extends ezcGraphAxisLabelRenderer
ezcGraphCoordinate $end,
ezcGraphChartElementAxis $axis )
{
- /*
// receive rendering parameters from axis
$this->majorStepCount = $axis->getMajorStepCount();
$this->minorStepCount = $axis->getMinorStepCount();
@@ -85,21 +96,77 @@ class ezcGraphAxisCenteredLabelRenderer extends ezcGraphAxisLabelRenderer
);
}
+ // Determine size of labels
+ switch ( $axis->position )
+ {
+ case ezcGraph::RIGHT:
+ case ezcGraph::LEFT:
+ $labelWidth = min(
+ abs( $majorStep->x ),
+ ( $boundings->x1 - $boundings->x0 ) * $axis->axisSpace * 2
+ );
+ $labelHeight = ( $boundings->y1 - $boundings->y0 ) * $axis->axisSpace;
+ break;
+ case ezcGraph::BOTTOM:
+ case ezcGraph::TOP:
+ $labelWidth = ( $boundings->x1 - $boundings->x0 ) * $axis->axisSpace;
+ $labelHeight = min(
+ abs( $majorStep->y ),
+ ( $boundings->y1 - $boundings->y0 ) * $axis->axisSpace * 2
+ );
+ break;
+ }
+
// Draw steps and grid
$step = 0;
while ( $step <= $this->majorStepCount )
{
- // major grid
- if ( $axis->majorGrid )
+ if ( ! $axis->isZeroStep( $step ) )
{
- $this->drawGrid( $renderer, $gridBoundings, $start, $majorStep, $axis->majorGrid );
+ // major grid
+ if ( $axis->majorGrid )
+ {
+ $this->drawGrid( $renderer, $gridBoundings, $start, $majorStep, $axis->majorGrid );
+ }
+
+ // major step
+ $this->drawStep( $renderer, $start, $direction, $axis->position, $this->majorStepSize, $axis->border );
}
- // major step
- $this->drawStep( $renderer, $start, $direction, $axis->position, $this->majorStepSize, $axis->border );
-
-
- ++$step;
+ // draw label
+ if ( $this->showZeroValue || ! $axis->isZeroStep( $step ) )
+ {
+ $label = $axis->getLabel( $step );
+ switch ( $axis->position )
+ {
+ case ezcGraph::TOP:
+ case ezcGraph::BOTTOM:
+ $renderer->drawText(
+ new ezcGraphBoundings(
+ $start->x - $labelWidth + $this->labelPadding,
+ $start->y - $labelHeight / 2 + $this->labelPadding,
+ $start->x - $this->labelPadding,
+ $start->y + $labelHeight / 2 - $this->labelPadding
+ ),
+ $label,
+ ezcGraph::MIDDLE | ezcGraph::RIGHT
+ );
+ break;
+ case ezcGraph::LEFT:
+ case ezcGraph::RIGHT:
+ $renderer->drawText(
+ new ezcGraphBoundings(
+ $start->x - $labelWidth / 2 + $this->labelPadding,
+ $start->y + $this->labelPadding,
+ $start->x + $labelWidth / 2 - $this->labelPadding,
+ $start->y + $labelHeight - $this->labelPadding
+ ),
+ $label,
+ ezcGraph::CENTER | ezcGraph::TOP
+ );
+ break;
+ }
+ }
// second iteration for minor steps, if wanted
if ( $this->minorStepCount )
@@ -127,7 +194,8 @@ class ezcGraphAxisCenteredLabelRenderer extends ezcGraphAxisLabelRenderer
$start->x += $majorStep->x;
$start->y += $majorStep->y;
- } */
+ ++$step;
+ }
}
}
?>
diff --git a/src/renderer/axis_label_exact.php b/src/renderer/axis_label_exact.php
index f0f7977..b4f6f21 100644
--- a/src/renderer/axis_label_exact.php
+++ b/src/renderer/axis_label_exact.php
@@ -133,19 +133,26 @@ class ezcGraphAxisExactLabelRenderer extends ezcGraphAxisLabelRenderer
$step = 0;
while ( $step <= $this->majorStepCount )
{
- // major grid
- if ( $axis->majorGrid )
+ if ( ! $axis->isZeroStep( $step ) )
{
- $this->drawGrid( $renderer, $gridBoundings, $start, $majorStep, $axis->majorGrid );
+ // major grid
+ if ( $axis->majorGrid )
+ {
+ $this->drawGrid( $renderer, $gridBoundings, $start, $majorStep, $axis->majorGrid );
+ }
+
+ // major step
+ $this->drawStep( $renderer, $start, $direction, $axis->position, $this->majorStepSize, $axis->border );
}
-
- // major step
- $this->drawStep( $renderer, $start, $direction, $axis->position, $this->majorStepSize, $axis->border );
// draw label
$label = $axis->getLabel( $step );
switch ( true )
{
+ case ( !$this->showLastValue &&
+ ( $step == $this->majorStepCount ) ):
+ // Skip last step if showLastValue is false
+ break;
// Draw label at top left of step
case ( ( $axis->position === ezcGraph::BOTTOM ) &&
( $step < $this->majorStepCount ) ) ||
diff --git a/tests/axis_centered_renderer_test.php b/tests/axis_centered_renderer_test.php
new file mode 100644
index 0000000..94b2204
--- /dev/null
+++ b/tests/axis_centered_renderer_test.php
@@ -0,0 +1,532 @@
+<?php
+/**
+ * ezcGraphAxisCenteredRendererTest
+ *
+ * @package Graph
+ * @version //autogen//
+ * @subpackage Tests
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Tests for ezcGraph class.
+ *
+ * @package ImageAnalysis
+ * @subpackage Tests
+ */
+class ezcGraphAxisCenteredRendererTest extends ezcTestCase
+{
+
+ protected $renderer;
+
+ protected $driver;
+
+ public static function suite()
+ {
+ return new ezcTestSuite( "ezcGraphAxisCenteredRendererTest" );
+ }
+
+ /**
+ * setUp
+ *
+ * @access public
+ */
+ public function setUp()
+ {
+ }
+
+ /**
+ * tearDown
+ *
+ * @access public
+ */
+ public function tearDown()
+ {
+ }
+
+ public function testRenderAxisGrid()
+ {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->palette = 'Black';
+ $chart->xAxis->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer();
+ $chart->yAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
+ $chart['sampleData'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1);
+
+ $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+ 'drawGridLine',
+ ) );
+
+ $mockedRenderer
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawGridLine' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 220., 20. ), 1. ),
+ $this->equalTo( new ezcGraphCoordinate( 220., 180. ), 1. ),
+ $this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 3 ) )
+ ->method( 'drawGridLine' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 460., 20. ), 1. ),
+ $this->equalTo( new ezcGraphCoordinate( 460., 180. ), 1. ),
+ $this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
+ );
+
+ $chart->renderer = $mockedRenderer;
+
+ $chart->render( 500, 200 );
+ }
+
+ public function testRenderAxisOuterGrid()
+ {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->palette = 'Black';
+ $chart->xAxis->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer();
+ $chart->yAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
+ $chart->xAxis->axisLabelRenderer->outerGrid = true;
+ $chart['sampleData'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1);
+
+ $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+ 'drawGridLine',
+ ) );
+
+ $mockedRenderer
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawGridLine' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 220., 0. ), 1. ),
+ $this->equalTo( new ezcGraphCoordinate( 220., 200. ), 1. ),
+ $this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 3 ) )
+ ->method( 'drawGridLine' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 460., 0. ), 1. ),
+ $this->equalTo( new ezcGraphCoordinate( 460., 200. ), 1. ),
+ $this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
+ );
+
+ $chart->renderer = $mockedRenderer;
+
+ $chart->render( 500, 200 );
+ }
+
+ public function testRenderAxisSteps()
+ {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->palette = 'Black';
+ $chart->xAxis->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer();
+ $chart->yAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
+ $chart['sampleData'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1);
+
+ $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+ 'drawStepLine',
+ ) );
+
+ $mockedRenderer
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawStepLine' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 220, 177. ), 1. ),
+ $this->equalTo( new ezcGraphCoordinate( 220, 180. ), 1. ),
+ $this->equalTo( ezcGraphColor::fromHex( '#EEEEEC' ) )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 3 ) )
+ ->method( 'drawStepLine' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 460., 177. ), 1. ),
+ $this->equalTo( new ezcGraphCoordinate( 460., 180. ), 1. ),
+ $this->equalTo( ezcGraphColor::fromHex( '#EEEEEC' ) )
+ );
+
+ $chart->renderer = $mockedRenderer;
+
+ $chart->render( 500, 200 );
+ }
+
+ public function testRenderAxisOuterSteps()
+ {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->palette = 'Black';
+ $chart->xAxis->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer();
+ $chart->yAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
+ $chart->xAxis->axisLabelRenderer->outerStep = true;
+ $chart['sampleData'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1);
+
+ $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+ 'drawStepLine',
+ ) );
+
+ $mockedRenderer
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawStepLine' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 220., 177. ), 1. ),
+ $this->equalTo( new ezcGraphCoordinate( 220., 183. ), 1. ),
+ $this->equalTo( ezcGraphColor::fromHex( '#EEEEEC' ) )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 3 ) )
+ ->method( 'drawStepLine' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 460., 177. ), 1. ),
+ $this->equalTo( new ezcGraphCoordinate( 460., 183. ), 1. ),
+ $this->equalTo( ezcGraphColor::fromHex( '#EEEEEC' ) )
+ );
+
+ $chart->renderer = $mockedRenderer;
+
+ $chart->render( 500, 200 );
+ }
+
+ public function testRenderAxisNoInnerSteps()
+ {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->palette = 'Black';
+ $chart->xAxis->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer();
+ $chart->yAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
+ $chart->xAxis->axisLabelRenderer->innerStep = false;
+ $chart->xAxis->axisLabelRenderer->outerStep = true;
+ $chart['sampleData'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1);
+
+ $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+ 'drawStepLine',
+ ) );
+
+ $mockedRenderer
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawStepLine' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 220., 180. ), 1. ),
+ $this->equalTo( new ezcGraphCoordinate( 220., 183. ), 1. ),
+ $this->equalTo( ezcGraphColor::fromHex( '#EEEEEC' ) )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 3 ) )
+ ->method( 'drawStepLine' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 460., 180. ), 1. ),
+ $this->equalTo( new ezcGraphCoordinate( 460., 183. ), 1. ),
+ $this->equalTo( ezcGraphColor::fromHex( '#EEEEEC' ) )
+ );
+
+ $chart->renderer = $mockedRenderer;
+
+ $chart->render( 500, 200 );
+ }
+
+ public function testRenderAxisNoSteps()
+ {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->palette = 'Black';
+ $chart->xAxis->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer();
+ $chart->yAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
+ $chart->xAxis->axisLabelRenderer->innerStep = false;
+ $chart->yAxis->axisLabelRenderer->innerStep = false;
+ $chart['sampleData'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1);
+
+ $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+ 'drawStepLine',
+ ) );
+
+ $mockedRenderer
+ ->expects( $this->exactly( 0 ) )
+ ->method( 'drawStepLine' );
+
+ $chart->renderer = $mockedRenderer;
+
+ $chart->render( 500, 200 );
+ }
+
+ public function testRenderTextBoxes()
+ {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->palette = 'Black';
+ $chart->xAxis->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer();
+ $chart->yAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
+ $chart['sampleData'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1);
+
+ $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+ 'drawText',
+ ) );
+
+ $mockedRenderer
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawText' )
+ ->with(
+ $this->equalTo( new ezcGraphBoundings( 182., 182., 258., 198. ), 1. ),
+ $this->equalTo( 'sample 2' ),
+ $this->equalTo( ezcGraph::TOP | ezcGraph::CENTER )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 3 ) )
+ ->method( 'drawText' )
+ ->with(
+ $this->equalTo( new ezcGraphBoundings( 422., 182., 498., 198. ), 1. ),
+ $this->equalTo( 'sample 5' ),
+ $this->equalTo( ezcGraph::TOP | ezcGraph::CENTER )
+ );
+
+ $chart->renderer = $mockedRenderer;
+
+ $chart->render( 500, 200 );
+ }
+
+ public function testRenderTextBoxesWithZeroValue()
+ {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->palette = 'Black';
+ $chart->xAxis->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer();
+ $chart->yAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
+ $chart->xAxis->axisLabelRenderer->showZeroValue = true;
+ $chart['sampleData'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1);
+
+ $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+ 'drawText',
+ ) );
+
+ $mockedRenderer
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawText' )
+ ->with(
+ $this->equalTo( new ezcGraphBoundings( 102., 182., 178., 198. ), 1. ),
+ $this->equalTo( 'sample 1' ),
+ $this->equalTo( ezcGraph::TOP | ezcGraph::CENTER )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 1 ) )
+ ->method( 'drawText' )
+ ->with(
+ $this->equalTo( new ezcGraphBoundings( 182., 182., 258., 198. ), 1. ),
+ $this->equalTo( 'sample 2' ),
+ $this->equalTo( ezcGraph::TOP | ezcGraph::CENTER )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 4 ) )
+ ->method( 'drawText' )
+ ->with(
+ $this->equalTo( new ezcGraphBoundings( 422., 182., 498., 198. ), 1. ),
+ $this->equalTo( 'sample 5' ),
+ $this->equalTo( ezcGraph::TOP | ezcGraph::CENTER )
+ );
+
+ $chart->renderer = $mockedRenderer;
+
+ $chart->render( 500, 200 );
+ }
+
+ public function testRenderAxisGridFromRight()
+ {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->palette = 'Black';
+ $chart->xAxis->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer();
+ $chart->yAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
+ $chart->xAxis->position = ezcGraph::RIGHT;
+ $chart['sampleData'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1);
+
+ $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+ 'drawGridLine',
+ ) );
+
+ $mockedRenderer
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawGridLine' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 380., 20. ), 1. ),
+ $this->equalTo( new ezcGraphCoordinate( 380., 180. ), 1. ),
+ $this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 3 ) )
+ ->method( 'drawGridLine' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 140., 20. ), 1. ),
+ $this->equalTo( new ezcGraphCoordinate( 140., 180. ), 1. ),
+ $this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
+ );
+
+ $chart->renderer = $mockedRenderer;
+
+ $chart->render( 500, 200 );
+ }
+
+ public function testRenderAxisGridFromTop()
+ {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->palette = 'Black';
+ $chart->xAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
+ $chart->yAxis->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer();
+ $chart->yAxis->position = ezcGraph::TOP;
+ $chart['sampleData'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1);
+
+ $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+ 'drawGridLine',
+ ) );
+
+ $mockedRenderer
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawGridLine' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 140., 60. ), 1. ),
+ $this->equalTo( new ezcGraphCoordinate( 460., 60. ), 1. ),
+ $this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 3 ) )
+ ->method( 'drawGridLine' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 140., 180. ), 1. ),
+ $this->equalTo( new ezcGraphCoordinate( 460., 180. ), 1. ),
+ $this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
+ );
+
+ $chart->renderer = $mockedRenderer;
+
+ $chart->render( 500, 200 );
+ }
+
+ public function testRenderAxisGridFromBottom()
+ {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->palette = 'Black';
+ $chart->xAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
+ $chart->yAxis->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer();
+ $chart->yAxis->position = ezcGraph::BOTTOM;
+ $chart['sampleData'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1);
+
+ $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+ 'drawGridLine',
+ ) );
+
+ $mockedRenderer
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawGridLine' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 140., 140. ), 1. ),
+ $this->equalTo( new ezcGraphCoordinate( 460., 140. ), 1. ),
+ $this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 3 ) )
+ ->method( 'drawGridLine' )
+ ->with(
+ $this->equalTo( new ezcGraphCoordinate( 140., 20. ), 1. ),
+ $this->equalTo( new ezcGraphCoordinate( 460., 20. ), 1. ),
+ $this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
+ );
+
+ $chart->renderer = $mockedRenderer;
+
+ $chart->render( 500, 200 );
+ }
+
+ public function testRenderTextBoxesFromRight()
+ {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->palette = 'Black';
+ $chart->xAxis->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer();
+ $chart->xAxis->position = ezcGraph::RIGHT;
+ $chart->yAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
+ $chart['sampleData'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1);
+
+ $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+ 'drawText',
+ ) );
+
+ $mockedRenderer
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawText' )
+ ->with(
+ $this->equalTo( new ezcGraphBoundings( 342., 182., 418., 198. ), 1. ),
+ $this->equalTo( 'sample 2' ),
+ $this->equalTo( ezcGraph::TOP | ezcGraph::CENTER )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 3 ) )
+ ->method( 'drawText' )
+ ->with(
+ $this->equalTo( new ezcGraphBoundings( 102., 182., 178., 198. ), 1. ),
+ $this->equalTo( 'sample 5' ),
+ $this->equalTo( ezcGraph::TOP | ezcGraph::CENTER )
+ );
+
+ $chart->renderer = $mockedRenderer;
+
+ $chart->render( 500, 200 );
+ }
+
+ public function testRenderTextBoxesFromTop()
+ {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->palette = 'Black';
+ $chart->xAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
+ $chart->yAxis->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer();
+ $chart->yAxis->position = ezcGraph::TOP;
+ $chart['sampleData'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1);
+
+ $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+ 'drawText',
+ ) );
+
+ $mockedRenderer
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawText' )
+ ->with(
+ $this->equalTo( new ezcGraphBoundings( 102., 42., 138., 78. ), 1. ),
+ $this->equalTo( '100' ),
+ $this->equalTo( ezcGraph::MIDDLE | ezcGraph::RIGHT )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 3 ) )
+ ->method( 'drawText' )
+ ->with(
+ $this->equalTo( new ezcGraphBoundings( 102., 162., 138., 198. ), 1. ),
+ $this->equalTo( '400' ),
+ $this->equalTo( ezcGraph::MIDDLE | ezcGraph::RIGHT )
+ );
+
+ $chart->renderer = $mockedRenderer;
+
+ $chart->render( 500, 200 );
+ }
+
+ public function testRenderTextBoxesFromBottom()
+ {
+ $chart = ezcGraph::create( 'Line' );
+ $chart->palette = 'Black';
+ $chart->xAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
+ $chart->yAxis->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer();
+ $chart->yAxis->position = ezcGraph::BOTTOM;
+ $chart['sampleData'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1);
+
+ $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array(
+ 'drawText',
+ ) );
+
+ $mockedRenderer
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawText' )
+ ->with(
+ $this->equalTo( new ezcGraphBoundings( 102., 122., 138., 158. ), 1. ),
+ $this->equalTo( '100' ),
+ $this->equalTo( ezcGraph::MIDDLE | ezcGraph::RIGHT )
+ );
+ $mockedRenderer
+ ->expects( $this->at( 3 ) )
+ ->method( 'drawText' )
+ ->with(
+ $this->equalTo( new ezcGraphBoundings( 102., 2., 138., 38. ), 1. ),
+ $this->equalTo( '400' ),
+ $this->equalTo( ezcGraph::MIDDLE | ezcGraph::RIGHT )
+ );
+
+ $chart->renderer = $mockedRenderer;
+
+ $chart->render( 500, 200 );
+ }
+}
+?>
diff --git a/tests/axis_exact_renderer_test.php b/tests/axis_exact_renderer_test.php
index 93c35d4..0084311 100644
--- a/tests/axis_exact_renderer_test.php
+++ b/tests/axis_exact_renderer_test.php
@@ -141,20 +141,12 @@ class ezcGraphAxisExactRendererTest extends ezcTestCase
->expects( $this->at( 0 ) )
->method( 'drawGridLine' )
->with(
- $this->equalTo( new ezcGraphCoordinate( 140., 20. ), 1. ),
- $this->equalTo( new ezcGraphCoordinate( 140., 180. ), 1. ),
- $this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
- );
- $mockedRenderer
- ->expects( $this->at( 1 ) )
- ->method( 'drawGridLine' )
- ->with(
$this->equalTo( new ezcGraphCoordinate( 220., 20. ), 1. ),
$this->equalTo( new ezcGraphCoordinate( 220., 180. ), 1. ),
$this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
);
$mockedRenderer
- ->expects( $this->at( 4 ) )
+ ->expects( $this->at( 3 ) )
->method( 'drawGridLine' )
->with(
$this->equalTo( new ezcGraphCoordinate( 460., 20. ), 1. ),
@@ -184,20 +176,12 @@ class ezcGraphAxisExactRendererTest extends ezcTestCase
->expects( $this->at( 0 ) )
->method( 'drawGridLine' )
->with(
- $this->equalTo( new ezcGraphCoordinate( 140., 0. ), 1. ),
- $this->equalTo( new ezcGraphCoordinate( 140., 200. ), 1. ),
- $this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
- );
- $mockedRenderer
- ->expects( $this->at( 1 ) )
- ->method( 'drawGridLine' )
- ->with(
$this->equalTo( new ezcGraphCoordinate( 220., 0. ), 1. ),
$this->equalTo( new ezcGraphCoordinate( 220., 200. ), 1. ),
$this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
);
$mockedRenderer
- ->expects( $this->at( 4 ) )
+ ->expects( $this->at( 3 ) )
->method( 'drawGridLine' )
->with(
$this->equalTo( new ezcGraphCoordinate( 460., 0. ), 1. ),
@@ -226,20 +210,12 @@ class ezcGraphAxisExactRendererTest extends ezcTestCase
->expects( $this->at( 0 ) )
->method( 'drawStepLine' )
->with(
- $this->equalTo( new ezcGraphCoordinate( 140., 177. ), 1. ),
- $this->equalTo( new ezcGraphCoordinate( 140., 180. ), 1. ),
- $this->equalTo( ezcGraphColor::fromHex( '#EEEEEC' ) )
- );
- $mockedRenderer
- ->expects( $this->at( 1 ) )
- ->method( 'drawStepLine' )
- ->with(
$this->equalTo( new ezcGraphCoordinate( 220, 177. ), 1. ),
$this->equalTo( new ezcGraphCoordinate( 220, 180. ), 1. ),
$this->equalTo( ezcGraphColor::fromHex( '#EEEEEC' ) )
);
$mockedRenderer
- ->expects( $this->at( 4 ) )
+ ->expects( $this->at( 3 ) )
->method( 'drawStepLine' )
->with(
$this->equalTo( new ezcGraphCoordinate( 460., 177. ), 1. ),
@@ -269,20 +245,12 @@ class ezcGraphAxisExactRendererTest extends ezcTestCase
->expects( $this->at( 0 ) )
->method( 'drawStepLine' )
->with(
- $this->equalTo( new ezcGraphCoordinate( 140., 177. ), 1. ),
- $this->equalTo( new ezcGraphCoordinate( 140., 183. ), 1. ),
- $this->equalTo( ezcGraphColor::fromHex( '#EEEEEC' ) )
- );
- $mockedRenderer
- ->expects( $this->at( 1 ) )
- ->method( 'drawStepLine' )
- ->with(
$this->equalTo( new ezcGraphCoordinate( 220., 177. ), 1. ),
$this->equalTo( new ezcGraphCoordinate( 220., 183. ), 1. ),
$this->equalTo( ezcGraphColor::fromHex( '#EEEEEC' ) )
);
$mockedRenderer
- ->expects( $this->at( 4 ) )
+ ->expects( $this->at( 3 ) )
->method( 'drawStepLine' )
->with(
$this->equalTo( new ezcGraphCoordinate( 460., 177. ), 1. ),
@@ -313,20 +281,12 @@ class ezcGraphAxisExactRendererTest extends ezcTestCase
->expects( $this->at( 0 ) )
->method( 'drawStepLine' )
->with(
- $this->equalTo( new ezcGraphCoordinate( 140., 180. ), 1. ),
- $this->equalTo( new ezcGraphCoordinate( 140., 183. ), 1. ),
- $this->equalTo( ezcGraphColor::fromHex( '#EEEEEC' ) )
- );
- $mockedRenderer
- ->expects( $this->at( 1 ) )
- ->method( 'drawStepLine' )
- ->with(
$this->equalTo( new ezcGraphCoordinate( 220., 180. ), 1. ),
$this->equalTo( new ezcGraphCoordinate( 220., 183. ), 1. ),
$this->equalTo( ezcGraphColor::fromHex( '#EEEEEC' ) )
);
$mockedRenderer
- ->expects( $this->at( 4 ) )
+ ->expects( $this->at( 3 ) )
->method( 'drawStepLine' )
->with(
$this->equalTo( new ezcGraphCoordinate( 460., 180. ), 1. ),
@@ -434,12 +394,12 @@ class ezcGraphAxisExactRendererTest extends ezcTestCase
$this->equalTo( ezcGraph::TOP | ezcGraph::LEFT )
);
$mockedRenderer
- ->expects( $this->at( 4 ) )
+ ->expects( $this->at( 3 ) )
->method( 'drawText' )
->with(
$this->equalTo( new ezcGraphBoundings( 382., 182., 458., 198. ), 1. ),
- $this->equalTo( 'sample 5' ),
- $this->equalTo( ezcGraph::TOP | ezcGraph::RIGHT )
+ $this->equalTo( 'sample 4' ),
+ $this->equalTo( ezcGraph::TOP | ezcGraph::LEFT )
);
$chart->renderer = $mockedRenderer;
@@ -464,20 +424,12 @@ class ezcGraphAxisExactRendererTest extends ezcTestCase
->expects( $this->at( 0 ) )
->method( 'drawGridLine' )
->with(
- $this->equalTo( new ezcGraphCoordinate( 460., 20. ), 1. ),
- $this->equalTo( new ezcGraphCoordinate( 460., 180. ), 1. ),
- $this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
- );
- $mockedRenderer
- ->expects( $this->at( 1 ) )
- ->method( 'drawGridLine' )
- ->with(
$this->equalTo( new ezcGraphCoordinate( 380., 20. ), 1. ),
$this->equalTo( new ezcGraphCoordinate( 380., 180. ), 1. ),
$this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
);
$mockedRenderer
- ->expects( $this->at( 4 ) )
+ ->expects( $this->at( 3 ) )
->method( 'drawGridLine' )
->with(
$this->equalTo( new ezcGraphCoordinate( 140., 20. ), 1. ),
@@ -507,20 +459,12 @@ class ezcGraphAxisExactRendererTest extends ezcTestCase
->expects( $this->at( 0 ) )
->method( 'drawGridLine' )
->with(
- $this->equalTo( new ezcGraphCoordinate( 140., 20. ), 1. ),
- $this->equalTo( new ezcGraphCoordinate( 460., 20. ), 1. ),
- $this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
- );
- $mockedRenderer
- ->expects( $this->at( 1 ) )
- ->method( 'drawGridLine' )
- ->with(
$this->equalTo( new ezcGraphCoordinate( 140., 60. ), 1. ),
$this->equalTo( new ezcGraphCoordinate( 460., 60. ), 1. ),
$this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
);
$mockedRenderer
- ->expects( $this->at( 4 ) )
+ ->expects( $this->at( 3 ) )
->method( 'drawGridLine' )
->with(
$this->equalTo( new ezcGraphCoordinate( 140., 180. ), 1. ),
@@ -550,20 +494,12 @@ class ezcGraphAxisExactRendererTest extends ezcTestCase
->expects( $this->at( 0 ) )
->method( 'drawGridLine' )
->with(
- $this->equalTo( new ezcGraphCoordinate( 140., 180. ), 1. ),
- $this->equalTo( new ezcGraphCoordinate( 460., 180. ), 1. ),
- $this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
- );
- $mockedRenderer
- ->expects( $this->at( 1 ) )
- ->method( 'drawGridLine' )
- ->with(
$this->equalTo( new ezcGraphCoordinate( 140., 140. ), 1. ),
$this->equalTo( new ezcGraphCoordinate( 460., 140. ), 1. ),
$this->equalTo( ezcGraphColor::fromHex( '#888A85' ) )
);
$mockedRenderer
- ->expects( $this->at( 4 ) )
+ ->expects( $this->at( 3 ) )
->method( 'drawGridLine' )
->with(
$this->equalTo( new ezcGraphCoordinate( 140., 20. ), 1. ),
diff --git a/tests/data/compare/ezcGraphCompleteRenderingTest_testRenderLineChart.png b/tests/data/compare/ezcGraphCompleteRenderingTest_testRenderLineChart.png
index 85b0b87..33f5f92 100644
--- a/tests/data/compare/ezcGraphCompleteRenderingTest_testRenderLineChart.png
+++ b/tests/data/compare/ezcGraphCompleteRenderingTest_testRenderLineChart.png
Binary files differ
diff --git a/tests/data/compare/ezcGraphCompleteRenderingTest_testRenderLineChartReverse.png b/tests/data/compare/ezcGraphCompleteRenderingTest_testRenderLineChartReverse.png
index 0fe0091..a82b88c 100644
--- a/tests/data/compare/ezcGraphCompleteRenderingTest_testRenderLineChartReverse.png
+++ b/tests/data/compare/ezcGraphCompleteRenderingTest_testRenderLineChartReverse.png
Binary files differ
diff --git a/tests/suite.php b/tests/suite.php
index 99d5f7f..a7b7527 100644
--- a/tests/suite.php
+++ b/tests/suite.php
@@ -28,6 +28,7 @@ require_once 'numeric_axis_test.php';
require_once 'labeled_axis_test.php';
require_once 'renderer_2d_test.php';
require_once 'axis_exact_renderer_test.php';
+require_once 'axis_centered_renderer_test.php';
require_once 'driver_gd_test.php';
require_once 'driver_svg_test.php';
require_once 'font_test.php';
@@ -58,6 +59,7 @@ class ezcGraphSuite extends ezcTestSuite
$this->addTest( ezcGraphLabeledAxisTest::suite() );
$this->addTest( ezcGraphRenderer2dTest::suite() );
$this->addTest( ezcGraphAxisExactRendererTest::suite() );
+ $this->addTest( ezcGraphAxisCenteredRendererTest::suite() );
$this->addTest( ezcGraphGdDriverTest::suite() );
$this->addTest( ezcGraphSvgDriverTest::suite() );
$this->addTest( ezcGraphFontTest::suite() );
OpenPOWER on IntegriCloud