diff options
-rw-r--r-- | src/charts/line.php | 7 | ||||
-rw-r--r-- | src/element/axis.php | 40 | ||||
-rw-r--r-- | src/element/legend.php | 2 | ||||
-rw-r--r-- | src/renderer/2d.php | 5 | ||||
-rw-r--r-- | tests/complete_rendering_test.php | 46 | ||||
-rw-r--r-- | tests/line_test.php | 22 | ||||
-rw-r--r-- | tests/pie_test.php | 12 | ||||
-rw-r--r-- | tests/renderer_2d_test.php | 48 |
8 files changed, 121 insertions, 61 deletions
diff --git a/src/charts/line.php b/src/charts/line.php index 8983f4a..321508d 100644 --- a/src/charts/line.php +++ b/src/charts/line.php @@ -71,6 +71,13 @@ class ezcGraphLineChart extends ezcGraphChart protected function renderData( $renderer, $boundings ) { + // Apply axis space + $boundings->x0 += ( $boundings->x1 - $boundings->x0 ) * $this->xAxis->axisSpace; + $boundings->x1 -= ( $boundings->x1 - $boundings->x0 ) * $this->xAxis->axisSpace; + + $boundings->y0 += ( $boundings->y1 - $boundings->y0 ) * $this->yAxis->axisSpace; + $boundings->y1 -= ( $boundings->y1 - $boundings->y0 ) * $this->yAxis->axisSpace; + foreach ( $this->data as $data ) { // Determine fill color for dataset diff --git a/src/element/axis.php b/src/element/axis.php index 4b61bd7..ac867a7 100644 --- a/src/element/axis.php +++ b/src/element/axis.php @@ -249,42 +249,50 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement { case ezcGraph::TOP: $start = new ezcGraphCoordinate( - $this->nullPosition, - $boundings->y0 + ( $boundings->x1 - $boundings->x0 ) * $this->axisSpace + + $this->nullPosition * ( $boundings->x1 - $boundings->x0 ) * ( 1 - 2 * $this->axisSpace ), + 0 ); $end = new ezcGraphCoordinate( - $this->nullPosition, - $boundings->y1 + ( $boundings->x1 - $boundings->x0 ) * $this->axisSpace + + $this->nullPosition * ( $boundings->x1 - $boundings->x0 ) * ( 1 - 2 * $this->axisSpace ), + $boundings->y1 - $boundings->y0 ); break; case ezcGraph::BOTTOM: $start = new ezcGraphCoordinate( - (int) $this->nullPosition, - (int) $boundings->y1 + ( $boundings->x1 - $boundings->x0 ) * $this->axisSpace + + $this->nullPosition * ( $boundings->x1 - $boundings->x0 ) * ( 1 - 2 * $this->axisSpace ), + $boundings->y1 - $boundings->y0 ); $end = new ezcGraphCoordinate( - (int) $this->nullPosition, - (int) $boundings->y0 + ( $boundings->x1 - $boundings->x0 ) * $this->axisSpace + + $this->nullPosition * ( $boundings->x1 - $boundings->x0 ) * ( 1 - 2 * $this->axisSpace ), + 0 ); break; case ezcGraph::LEFT: $start = new ezcGraphCoordinate( - (int) $boundings->x0, - (int) $this->nullPosition + 0, + ( $boundings->y1 - $boundings->y0 ) * $this->axisSpace + + $this->nullPosition * ( $boundings->y1 - $boundings->y0 ) * ( 1 - 2 * $this->axisSpace ) ); $end = new ezcGraphCoordinate( - (int) $boundings->x1, - (int) $this->nullPosition + $boundings->x1 - $boundings->x0, + ( $boundings->y1 - $boundings->y0 ) * $this->axisSpace + + $this->nullPosition * ( $boundings->y1 - $boundings->y0 ) * ( 1 - 2 * $this->axisSpace ) ); break; case ezcGraph::RIGHT: $start = new ezcGraphCoordinate( - (int) $boundings->x1, - (int) $this->nullPosition + $boundings->x1 - $boundings->x0, + ( $boundings->y1 - $boundings->y0 ) * $this->axisSpace + + $this->nullPosition * ( $boundings->y1 - $boundings->y0 ) * ( 1 - 2 * $this->axisSpace ) ); $end = new ezcGraphCoordinate( - (int) $boundings->x0, - (int) $this->nullPosition + 0, + ( $boundings->y1 - $boundings->y0 ) * $this->axisSpace + + $this->nullPosition * ( $boundings->y1 - $boundings->y0 ) * ( 1 - 2 * $this->axisSpace ) ); break; } diff --git a/src/element/legend.php b/src/element/legend.php index ed110f4..1d8fe9e 100644 --- a/src/element/legend.php +++ b/src/element/legend.php @@ -227,8 +227,6 @@ class ezcGraphChartElementLegend extends ezcGraphChartElement $type ); - var_dump( $this->boundings, $boundings ); - return $boundings; } } diff --git a/src/renderer/2d.php b/src/renderer/2d.php index 0ac0e91..83ed126 100644 --- a/src/renderer/2d.php +++ b/src/renderer/2d.php @@ -630,6 +630,11 @@ class ezcGraphRenderer2d extends ezcGraphRenderer ezcGraphChartElementAxis $axis, ezcGraphAxisLabelRenderer $labelClass = null ) { + $start->x += $boundings->x0; + $start->y += $boundings->y0; + $end->x += $boundings->x0; + $end->y += $boundings->y0; + // Determine normalized direction $direction = new ezcGraphCoordinate( $start->x - $end->x, diff --git a/tests/complete_rendering_test.php b/tests/complete_rendering_test.php index ff8d954..92b4d83 100644 --- a/tests/complete_rendering_test.php +++ b/tests/complete_rendering_test.php @@ -15,7 +15,7 @@ * @package ImageAnalysis * @subpackage Tests */ -class ezcGraphCompleteRenderingTest extends ezcTestCase +class ezcGraphCompleteRenderingTest extends ezcImageTestCase { protected $testFiles = array( @@ -58,7 +58,7 @@ class ezcGraphCompleteRenderingTest extends ezcTestCase $filename = $this->tempDir . __FUNCTION__ . '.png'; $chart = ezcGraph::create( 'line' ); - $chart->palette = 'black'; + $chart->palette = 'Black'; $chart['Line 1'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1); $chart['Line 2'] = array( 'sample 1' => 543, 'sample 2' => 234, 'sample 3' => 298, 'sample 4' => 5, 'sample 5' => 613); @@ -74,6 +74,48 @@ class ezcGraphCompleteRenderingTest extends ezcTestCase ); } + public function testRenderLineChartAxis() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $renderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawAxis', + ) ); + + $chart = ezcGraph::create( 'line' ); + $chart->palette = 'Black'; + + $renderer + ->expects( $this->at( 0 ) ) + ->method( 'drawAxis' ) + ->with( + $this->equalTo( new ezcGraphBoundings( 100, 0, 500, 200 ), 1. ), + $this->equalTo( new ezcGraphCoordinate( 0, 180 ), 1. ), + $this->equalTo( new ezcGraphCoordinate( 400, 180 ), 1. ), + $this->equalTo( $chart->xAxis ), + $this->equalTo( $chart->xAxis->axisLabelRenderer ) + ); + $renderer + ->expects( $this->at( 1 ) ) + ->method( 'drawAxis' ) + ->with( + $this->equalTo( new ezcGraphBoundings( 100, 0, 500, 200 ), 1. ), + $this->equalTo( new ezcGraphCoordinate( 40, 200 ), 1. ), + $this->equalTo( new ezcGraphCoordinate( 40, 0 ), 1. ), + $this->equalTo( $chart->yAxis ), + $this->equalTo( $chart->yAxis->axisLabelRenderer ) + ); + + $chart['Line 1'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1); + $chart['Line 2'] = array( 'sample 1' => 543, 'sample 2' => 234, 'sample 3' => 298, 'sample 4' => 5, 'sample 5' => 613); + + $chart->renderer = $renderer; + + $chart->driver = new ezcGraphGdDriver(); + $chart->options->font = $this->basePath . 'font.ttf'; + $chart->render( 500, 200, $filename ); + } + public function testRenderWithTransparentBackground() { $filename = $this->tempDir . __FUNCTION__ . '.png'; diff --git a/tests/line_test.php b/tests/line_test.php index 34491ca..820bc75 100644 --- a/tests/line_test.php +++ b/tests/line_test.php @@ -110,7 +110,7 @@ class ezcGraphLineChartTest extends ezcTestCase ->expects( $this->at( 0 ) ) ->method( 'drawDataLine' ) ->with( - $this->equalTo( new ezcGraphBoundings( 101, 18, 499, 182 ) ), + $this->equalTo( new ezcGraphBoundings( 140., 20., 464., 182. ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), $this->equalTo( new ezcGraphCoordinate( .0, .415 ), .05 ), $this->equalTo( new ezcGraphCoordinate( .0, .415 ), .05 ), @@ -122,7 +122,7 @@ class ezcGraphLineChartTest extends ezcTestCase ->expects( $this->at( 1 ) ) ->method( 'drawDataLine' ) ->with( - $this->equalTo( new ezcGraphBoundings( 101, 18, 499, 182 ) ), + $this->equalTo( new ezcGraphBoundings( 140., 20., 464., 182. ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), $this->equalTo( new ezcGraphCoordinate( .0, .415 ), .05 ), $this->equalTo( new ezcGraphCoordinate( .25, .95 ), .05 ), @@ -134,7 +134,7 @@ class ezcGraphLineChartTest extends ezcTestCase ->expects( $this->at( 2 ) ) ->method( 'drawDataLine' ) ->with( - $this->equalTo( new ezcGraphBoundings( 101, 18, 499, 182 ) ), + $this->equalTo( new ezcGraphBoundings( 140., 20., 464., 182. ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), $this->equalTo( new ezcGraphCoordinate( .25, .95 ), .05 ), $this->equalTo( new ezcGraphCoordinate( .5, .2 ), .05 ), @@ -146,7 +146,7 @@ class ezcGraphLineChartTest extends ezcTestCase ->expects( $this->at( 3 ) ) ->method( 'drawDataLine' ) ->with( - $this->equalTo( new ezcGraphBoundings( 101, 18, 499, 182 ) ), + $this->equalTo( new ezcGraphBoundings( 140., 20., 464., 182. ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), $this->equalTo( new ezcGraphCoordinate( .5, .2 ), .05 ), $this->equalTo( new ezcGraphCoordinate( .75, .7 ), .05 ), @@ -158,7 +158,7 @@ class ezcGraphLineChartTest extends ezcTestCase ->expects( $this->at( 4 ) ) ->method( 'drawDataLine' ) ->with( - $this->equalTo( new ezcGraphBoundings( 101, 18, 499, 182 ) ), + $this->equalTo( new ezcGraphBoundings( 140., 20., 464., 182. ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), $this->equalTo( new ezcGraphCoordinate( .75, .7 ), .05 ), $this->equalTo( new ezcGraphCoordinate( 1., .9975 ), .05 ), @@ -187,7 +187,7 @@ class ezcGraphLineChartTest extends ezcTestCase ->expects( $this->at( 0 ) ) ->method( 'drawDataLine' ) ->with( - $this->equalTo( new ezcGraphBoundings( 103, 20, 497, 180 ) ), + $this->equalTo( new ezcGraphBoundings( 140., 20., 464., 182. ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#3465A4' ) ), $this->equalTo( new ezcGraphCoordinate( .0, .165 ), .05 ), $this->equalTo( new ezcGraphCoordinate( .0, .165 ), .05 ), @@ -199,7 +199,7 @@ class ezcGraphLineChartTest extends ezcTestCase ->expects( $this->at( 1 ) ) ->method( 'drawDataLine' ) ->with( - $this->equalTo( new ezcGraphBoundings( 103, 20, 497, 180 ) ), + $this->equalTo( new ezcGraphBoundings( 140., 20., 464., 182. ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#3465A4' ) ), $this->equalTo( new ezcGraphCoordinate( .0, .165 ), .05 ), $this->equalTo( new ezcGraphCoordinate( .25, .6975 ), .05 ), @@ -211,7 +211,7 @@ class ezcGraphLineChartTest extends ezcTestCase ->expects( $this->at( 4 ) ) ->method( 'drawDataLine' ) ->with( - $this->equalTo( new ezcGraphBoundings( 103, 20, 497, 180 ) ), + $this->equalTo( new ezcGraphBoundings( 140., 20., 464., 182. ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#3465A4' ) ), $this->equalTo( new ezcGraphCoordinate( .75, .45 ), .05 ), $this->equalTo( new ezcGraphCoordinate( 1., .5 ), .05 ), @@ -241,7 +241,7 @@ class ezcGraphLineChartTest extends ezcTestCase ->expects( $this->at( 0 ) ) ->method( 'drawDataLine' ) ->with( - $this->equalTo( new ezcGraphBoundings( 103, 20, 497, 180 ) ), + $this->equalTo( new ezcGraphBoundings( 140., 20., 464., 182. ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#729FCF' ) ), $this->equalTo( new ezcGraphCoordinate( .0, .415 ), .05 ), $this->equalTo( new ezcGraphCoordinate( .0, .415 ), .05 ), @@ -253,7 +253,7 @@ class ezcGraphLineChartTest extends ezcTestCase ->expects( $this->at( 2 ) ) ->method( 'drawDataLine' ) ->with( - $this->equalTo( new ezcGraphBoundings( 103, 20, 497, 180 ) ), + $this->equalTo( new ezcGraphBoundings( 140., 20., 464., 182. ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#729FCF' ) ), $this->equalTo( new ezcGraphCoordinate( .25, .9475 ), .05 ), $this->equalTo( new ezcGraphCoordinate( .5, .19 ), .05 ), @@ -265,7 +265,7 @@ class ezcGraphLineChartTest extends ezcTestCase ->expects( $this->at( 4 ) ) ->method( 'drawDataLine' ) ->with( - $this->equalTo( new ezcGraphBoundings( 103, 20, 497, 180 ) ), + $this->equalTo( new ezcGraphBoundings( 140., 20., 464., 182. ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#729FCF' ) ), $this->equalTo( new ezcGraphCoordinate( .75, .7 ), .05 ), $this->equalTo( new ezcGraphCoordinate( 1., .9975 ), .05 ), diff --git a/tests/pie_test.php b/tests/pie_test.php index c3fa240..ccf88a8 100644 --- a/tests/pie_test.php +++ b/tests/pie_test.php @@ -103,7 +103,7 @@ class ezcGraphPieChartTest extends ezcTestCase ->expects( $this->at( 0 ) ) ->method( 'drawPieSegment' ) ->with( - $this->equalTo( new ezcGraphBoundings( 81, 18, 399, 182 ) ), + $this->equalTo( new ezcGraphBoundings( 80, 0, 400, 200 ) ), $this->equalTo( ezcGraphColor::fromHex( '#4E9A06' ) ), $this->equalTo( 0., 1. ), $this->equalTo( 220.5, .1 ), @@ -114,8 +114,8 @@ class ezcGraphPieChartTest extends ezcTestCase ->expects( $this->at( 1 ) ) ->method( 'drawPieSegment' ) ->with( - $this->equalTo( new ezcGraphBoundings( 81, 18, 399, 182 ) ), - $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), + $this->equalTo( new ezcGraphBoundings( 80, 0, 400, 200 ) ), + $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), $this->equalTo( 220.5, .1 ), $this->equalTo( 238., 1. ), $this->equalTo( 'IE' ), @@ -125,7 +125,7 @@ class ezcGraphPieChartTest extends ezcTestCase ->expects( $this->at( 2 ) ) ->method( 'drawPieSegment' ) ->with( - $this->equalTo( new ezcGraphBoundings( 81, 18, 399, 182 ) ), + $this->equalTo( new ezcGraphBoundings( 80, 0, 400, 200 ) ), $this->equalTo( ezcGraphColor::fromHex( '#EDD400' ) ), $this->equalTo( 238., 1. ), $this->equalTo( 298.6, 1. ), @@ -136,7 +136,7 @@ class ezcGraphPieChartTest extends ezcTestCase ->expects( $this->at( 3 ) ) ->method( 'drawPieSegment' ) ->with( - $this->equalTo( new ezcGraphBoundings( 81, 18, 399, 182 ) ), + $this->equalTo( new ezcGraphBoundings( 80, 0, 400, 200 ) ), $this->equalTo( ezcGraphColor::fromHex( '#75505B' ) ), $this->equalTo( 298.6, 1. ), $this->equalTo( 310., 1. ), @@ -147,7 +147,7 @@ class ezcGraphPieChartTest extends ezcTestCase ->expects( $this->at( 4 ) ) ->method( 'drawPieSegment' ) ->with( - $this->equalTo( new ezcGraphBoundings( 81, 18, 399, 182 ) ), + $this->equalTo( new ezcGraphBoundings( 80, 0, 400, 200 ) ), $this->equalTo( ezcGraphColor::fromHex( '#F57900' ) ), $this->equalTo( 310., 1. ), $this->equalTo( 360., 1. ), diff --git a/tests/renderer_2d_test.php b/tests/renderer_2d_test.php index 49d7a39..41ed9d8 100644 --- a/tests/renderer_2d_test.php +++ b/tests/renderer_2d_test.php @@ -1331,8 +1331,8 @@ class ezcGraphRenderer2dTest extends ezcTestCase ->expects( $this->at( 0 ) ) ->method( 'drawLine' ) ->with( - $this->equalTo( new ezcGraphCoordinate( 20., 200. ), 1. ), - $this->equalTo( new ezcGraphCoordinate( 20., 0. ), 1. ), + $this->equalTo( new ezcGraphCoordinate( 120., 220. ), 1. ), + $this->equalTo( new ezcGraphCoordinate( 120., 20. ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), $this->equalTo( 1 ) ); @@ -1341,16 +1341,16 @@ class ezcGraphRenderer2dTest extends ezcTestCase ->method( 'drawPolygon' ) ->with( $this->equalTo( array( - new ezcGraphCoordinate( 20., 0. ), - new ezcGraphCoordinate( 22.5, 5. ), - new ezcGraphCoordinate( 17.5, 5. ), + new ezcGraphCoordinate( 120., 20. ), + new ezcGraphCoordinate( 122.5, 25. ), + new ezcGraphCoordinate( 117.5, 25. ), ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), $this->equalTo( true ) ); $this->renderer->drawAxis( - new ezcGraphBoundings( 0, 0, 200, 400 ), + new ezcGraphBoundings( 100, 20, 500, 220 ), new ezcGraphCoordinate( 20, 200 ), new ezcGraphCoordinate( 20, 0 ), $chart->yAxis @@ -1365,8 +1365,8 @@ class ezcGraphRenderer2dTest extends ezcTestCase ->expects( $this->at( 0 ) ) ->method( 'drawLine' ) ->with( - $this->equalTo( new ezcGraphCoordinate( 20., 0. ), 1. ), - $this->equalTo( new ezcGraphCoordinate( 20., 200. ), 1. ), + $this->equalTo( new ezcGraphCoordinate( 120., 20. ), 1. ), + $this->equalTo( new ezcGraphCoordinate( 120., 220. ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), $this->equalTo( 1 ) ); @@ -1375,16 +1375,16 @@ class ezcGraphRenderer2dTest extends ezcTestCase ->method( 'drawPolygon' ) ->with( $this->equalTo( array( - new ezcGraphCoordinate( 20., 200. ), - new ezcGraphCoordinate( 17.5, 195. ), - new ezcGraphCoordinate( 22.5, 195. ), + new ezcGraphCoordinate( 120., 220. ), + new ezcGraphCoordinate( 117.5, 215. ), + new ezcGraphCoordinate( 122.5, 215. ), ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), $this->equalTo( true ) ); $this->renderer->drawAxis( - new ezcGraphBoundings( 0, 0, 200, 400 ), + new ezcGraphBoundings( 100, 20, 500, 220 ), new ezcGraphCoordinate( 20, 0 ), new ezcGraphCoordinate( 20, 200 ), $chart->yAxis @@ -1399,8 +1399,8 @@ class ezcGraphRenderer2dTest extends ezcTestCase ->expects( $this->at( 0 ) ) ->method( 'drawLine' ) ->with( - $this->equalTo( new ezcGraphCoordinate( 50., 100. ), 1. ), - $this->equalTo( new ezcGraphCoordinate( 350., 100. ), 1. ), + $this->equalTo( new ezcGraphCoordinate( 150., 120. ), 1. ), + $this->equalTo( new ezcGraphCoordinate( 450., 120. ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), $this->equalTo( 1 ) ); @@ -1409,16 +1409,16 @@ class ezcGraphRenderer2dTest extends ezcTestCase ->method( 'drawPolygon' ) ->with( $this->equalTo( array( - new ezcGraphCoordinate( 350., 100. ), - new ezcGraphCoordinate( 342., 96. ), - new ezcGraphCoordinate( 342., 104. ), + new ezcGraphCoordinate( 450., 120. ), + new ezcGraphCoordinate( 442., 116. ), + new ezcGraphCoordinate( 442., 124. ), ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), $this->equalTo( true ) ); $this->renderer->drawAxis( - new ezcGraphBoundings( 0, 0, 200, 400 ), + new ezcGraphBoundings( 100, 20, 500, 220 ), new ezcGraphCoordinate( 50, 100 ), new ezcGraphCoordinate( 350, 100 ), $chart->yAxis @@ -1433,8 +1433,8 @@ class ezcGraphRenderer2dTest extends ezcTestCase ->expects( $this->at( 0 ) ) ->method( 'drawLine' ) ->with( - $this->equalTo( new ezcGraphCoordinate( 350., 100. ), 1. ), - $this->equalTo( new ezcGraphCoordinate( 50., 100. ), 1. ), + $this->equalTo( new ezcGraphCoordinate( 450., 120. ), 1. ), + $this->equalTo( new ezcGraphCoordinate( 150., 120. ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), $this->equalTo( 1 ) ); @@ -1443,16 +1443,16 @@ class ezcGraphRenderer2dTest extends ezcTestCase ->method( 'drawPolygon' ) ->with( $this->equalTo( array( - new ezcGraphCoordinate( 50., 100. ), - new ezcGraphCoordinate( 57., 103.5 ), - new ezcGraphCoordinate( 57., 96.5 ), + new ezcGraphCoordinate( 150., 120. ), + new ezcGraphCoordinate( 157., 123.5 ), + new ezcGraphCoordinate( 157., 116.5 ), ), 1. ), $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), $this->equalTo( true ) ); $this->renderer->drawAxis( - new ezcGraphBoundings( 0, 0, 200, 400 ), + new ezcGraphBoundings( 100, 20, 500, 220 ), new ezcGraphCoordinate( 350, 100 ), new ezcGraphCoordinate( 50, 100 ), $chart->yAxis |