diff options
-rw-r--r-- | src/element/legend.php | 22 | ||||
-rw-r--r-- | tests/legend_test.php | 36 | ||||
-rw-r--r-- | tests/line_test.php | 1 |
3 files changed, 35 insertions, 24 deletions
diff --git a/src/element/legend.php b/src/element/legend.php index ae2aa07..a8192ae 100644 --- a/src/element/legend.php +++ b/src/element/legend.php @@ -69,6 +69,13 @@ class ezcGraphChartElementLegend extends ezcGraphChartElement protected $minimumSymbolSize = .05; /** + * Space between lael elements in pixel + * + * @var integer + */ + protected $spacing = 2; + + /** * __set * * @param mixed $propertyName @@ -95,6 +102,9 @@ class ezcGraphChartElementLegend extends ezcGraphChartElement case 'portraitSize': $this->portraitSize = max( 0, min( 1, (float) $propertyValue ) ); break; + case 'spacing': + $this->portraitSize = max( 0, (int) $propertyValue ); + break; default: parent::__set( $propertyName, $propertyValue ); break; @@ -200,7 +210,7 @@ class ezcGraphChartElementLegend extends ezcGraphChartElement $label['color'], new ezcGraphCoordinate( $this->boundings->x0 + $this->padding, - $this->boundings->y0 + $labelNr * $symbolSize + $this->padding + $this->boundings->y0 + $labelNr * ( $symbolSize + $this->spacing ) + $this->padding ), $symbolSize - 2 * $this->padding, $symbolSize - 2 * $this->padding, @@ -208,11 +218,11 @@ class ezcGraphChartElementLegend extends ezcGraphChartElement ); $renderer->drawTextBox( new ezcGraphCoordinate( - $this->boundings->x0 + $symbolSize, - $this->boundings->y0 + $labelNr * $symbolSize + $this->padding + $this->boundings->x0 + $symbolSize + $this->spacing, + $this->boundings->y0 + $labelNr * ( $symbolSize + $this->spacing ) + $this->padding ), $label['label'], - $this->boundings->x1 - $this->boundings->x0 - $symbolSize - $this->padding, + $this->boundings->x1 - $this->boundings->x0 - $symbolSize - $this->padding - $this->spacing, $symbolSize - 2 * $this->padding, ezcGraph::LEFT | ezcGraph::MIDDLE ); @@ -240,11 +250,11 @@ class ezcGraphChartElementLegend extends ezcGraphChartElement ); $renderer->drawTextBox( new ezcGraphCoordinate( - $this->boundings->x0 + $labelNr * $width + $this->padding + $symbolSize, + $this->boundings->x0 + $labelNr * $width + $this->padding + $symbolSize + $this->spacing, $this->boundings->y0 + $this->padding ), $label['label'], - $width - $this->padding - $symbolSize, + $width - $this->padding - $symbolSize - $this->spacing, $symbolSize - 2 * $this->padding, ezcGraph::LEFT | ezcGraph::MIDDLE ); diff --git a/tests/legend_test.php b/tests/legend_test.php index 24751e7..f850b22 100644 --- a/tests/legend_test.php +++ b/tests/legend_test.php @@ -212,7 +212,7 @@ class ezcGraphLegendTest extends ezcTestCase ->method( 'drawSymbol' ) ->with( $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 2, 16 ) ), + $this->equalTo( new ezcGraphCoordinate( 2, 18 ) ), $this->equalTo( 12 ), $this->equalTo( 12 ), ezcGraph::NO_SYMBOL @@ -222,7 +222,7 @@ class ezcGraphLegendTest extends ezcTestCase ->method( 'drawSymbol' ) ->with( $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 2, 30 ) ), + $this->equalTo( new ezcGraphCoordinate( 2, 34 ) ), $this->equalTo( 12 ), $this->equalTo( 12 ), ezcGraph::NO_SYMBOL @@ -254,9 +254,9 @@ class ezcGraphLegendTest extends ezcTestCase ->expects( $this->at( 0 ) ) ->method( 'drawTextBox' ) ->with( - $this->equalTo( new ezcGraphCoordinate( 15, 2 ) ), + $this->equalTo( new ezcGraphCoordinate( 17, 2 ) ), 'sampleData', - $this->equalTo( 83 ), + $this->equalTo( 81 ), $this->equalTo( 12 ), $this->equalTo( ezcGraph::LEFT | ezcGraph::MIDDLE ) ); @@ -264,9 +264,9 @@ class ezcGraphLegendTest extends ezcTestCase ->expects( $this->at( 1 ) ) ->method( 'drawTextBox' ) ->with( - $this->equalTo( new ezcGraphCoordinate( 15, 16 ) ), + $this->equalTo( new ezcGraphCoordinate( 17, 18 ) ), 'moreData', - $this->equalTo( 83 ), + $this->equalTo( 81 ), $this->equalTo( 12 ), $this->equalTo( ezcGraph::LEFT | ezcGraph::MIDDLE ) @@ -275,9 +275,9 @@ class ezcGraphLegendTest extends ezcTestCase ->expects( $this->at( 2 ) ) ->method( 'drawTextBox' ) ->with( - $this->equalTo( new ezcGraphCoordinate( 15, 30 ) ), + $this->equalTo( new ezcGraphCoordinate( 17, 34 ) ), 'Even more data', - $this->equalTo( 83 ), + $this->equalTo( 81 ), $this->equalTo( 12 ), $this->equalTo( ezcGraph::LEFT | ezcGraph::MIDDLE ) @@ -355,7 +355,7 @@ class ezcGraphLegendTest extends ezcTestCase ->method( 'drawSymbol' ) ->with( $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 402, 16 ) ), + $this->equalTo( new ezcGraphCoordinate( 402, 18 ) ), $this->equalTo( 12 ), $this->equalTo( 12 ), ezcGraph::NO_SYMBOL @@ -365,7 +365,7 @@ class ezcGraphLegendTest extends ezcTestCase ->method( 'drawSymbol' ) ->with( $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 402, 30 ) ), + $this->equalTo( new ezcGraphCoordinate( 402, 34 ) ), $this->equalTo( 12 ), $this->equalTo( 12 ), ezcGraph::NO_SYMBOL @@ -483,27 +483,27 @@ class ezcGraphLegendTest extends ezcTestCase ->expects( $this->at( 0 ) ) ->method( 'drawTextBox' ) ->with( - $this->equalTo( new ezcGraphCoordinate( 16, 2 ) ), + $this->equalTo( new ezcGraphCoordinate( 18, 2 ) ), 'sampleData', - $this->equalTo( 184 ), + $this->equalTo( 182 ), $this->equalTo( 12 ) ); $mockedRenderer ->expects( $this->at( 1 ) ) ->method( 'drawTextBox' ) ->with( - $this->equalTo( new ezcGraphCoordinate( 215, 2 ) ), + $this->equalTo( new ezcGraphCoordinate( 217, 2 ) ), 'moreData', - $this->equalTo( 184 ), + $this->equalTo( 182 ), $this->equalTo( 12 ) ); $mockedRenderer ->expects( $this->at( 2 ) ) ->method( 'drawTextBox' ) ->with( - $this->equalTo( new ezcGraphCoordinate( 414, 2 ) ), + $this->equalTo( new ezcGraphCoordinate( 416, 2 ) ), 'Even more data', - $this->equalTo( 184 ), + $this->equalTo( 182 ), $this->equalTo( 12 ) ); @@ -546,7 +546,7 @@ class ezcGraphLegendTest extends ezcTestCase ->method( 'drawSymbol' ) ->with( $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 6, 26 ) ), + $this->equalTo( new ezcGraphCoordinate( 6, 28 ) ), $this->equalTo( 14 ), $this->equalTo( 14 ), ezcGraph::NO_SYMBOL @@ -556,7 +556,7 @@ class ezcGraphLegendTest extends ezcTestCase ->method( 'drawSymbol' ) ->with( $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 6, 46 ) ), + $this->equalTo( new ezcGraphCoordinate( 6, 50 ) ), $this->equalTo( 14 ), $this->equalTo( 14 ), ezcGraph::NO_SYMBOL diff --git a/tests/line_test.php b/tests/line_test.php index adf7a09..677c8e4 100644 --- a/tests/line_test.php +++ b/tests/line_test.php @@ -238,6 +238,7 @@ class ezcGraphLineChartTest extends ezcTestCase { $chart = ezcGraph::create( 'Line' ); $chart->title = 'Test graph'; + $chart->palette = 'Black'; $this->addSampleData( $chart ); $chart->driver = new ezcGraphGdDriver(); |