From c3791202abeb0709671f564ca387a2c2d1b7679d Mon Sep 17 00:00:00 2001 From: PhoenixFnX Date: Wed, 6 Aug 2014 01:31:13 +0200 Subject: [PATCH 1/5] Adding a position feature to the axes labels I just commit the minimum code to allow labels on the right of a vertical secondary axis --- src/element/axis.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/element/axis.php b/src/element/axis.php index e9a65387..2dcb7dc7 100644 --- a/src/element/axis.php +++ b/src/element/axis.php @@ -119,6 +119,8 @@ * Size of axis label * @property int $labelMargin * Distance between label an axis + * @property int $labelPosition + * Integer defining the labels position regarding the axe. * @property int $minArrowHeadSize * Minimum Size used to draw arrow heads. * @property int $maxArrowHeadSize @@ -179,6 +181,7 @@ public function __construct( array $options = array() ) $this->properties['label'] = false; $this->properties['labelSize'] = 14; $this->properties['labelMargin'] = 2; + $this->properties['labelPosition'] = ezcGraph::LEFT; $this->properties['minArrowHeadSize'] = 4; $this->properties['maxArrowHeadSize'] = 8; $this->properties['labelCallback'] = null; @@ -296,6 +299,23 @@ public function __set( $propertyName, $propertyValue ) $this->properties['labelMargin'] = (int) $propertyValue; break; + case 'labelPosition': + $positions = array( + ezcGraph::TOP, + ezcGraph::BOTTOM, + ezcGraph::LEFT, + ezcGraph::RIGHT, + ); + + if ( in_array( $propertyValue, $positions, true ) ) + { + $this->properties['labelPosition'] = $propertyValue; + } + else + { + throw new ezcBaseValueException( 'labelPosition', $propertyValue, 'integer' ); + } + break; case 'maxArrowHeadSize': if ( !is_numeric( $propertyValue ) || ( $propertyValue <= 0 ) ) From 8f760ec621defc708d1d00cfda86bf18f772eb39 Mon Sep 17 00:00:00 2001 From: PhoenixFnX Date: Wed, 6 Aug 2014 01:32:36 +0200 Subject: [PATCH 2/5] Adding a position feature to the axes labels only $axis->labelPosition === ezcGraph::RIGHT is supported --- src/renderer/axis_label_exact.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/renderer/axis_label_exact.php b/src/renderer/axis_label_exact.php index a158756e..d0027116 100644 --- a/src/renderer/axis_label_exact.php +++ b/src/renderer/axis_label_exact.php @@ -207,6 +207,31 @@ public function renderLabels( // Skip last step if showLastValue is false $showLabel = false; break; + // NTH : Draw label at top right of step on vertical axis + case ( ( $axis->labelPosition === ezcGraph::RIGHT ) && + ( !$step->isLast ) ) || + ( ( $axis->labelPosition === ezcGraph::RIGHT ) && + ( $step->isLast ) && + ( $this->renderLastOutside ) ) : + $labelBoundings = new ezcGraphBoundings( + $position->x + $this->labelPadding, + $position->y - $labelHeight + $this->labelPadding, + $position->x + $labelWidth - $this->labelPadding, + $position->y - $this->labelPadding + ); + $alignement = ezcGraph::LEFT | ezcGraph::BOTTOM; + break; + case ( ( $axis->labelPosition === ezcGraph::RIGHT ) && + ( $step->isLast ) && + ( !$this->renderLastOutside ) ) : + $labelBoundings = new ezcGraphBoundings( + $position->x + $this->labelPadding, + $position->y + $this->labelPadding, + $position->x + $labelWidth - $this->labelPadding, + $position->y + $labelHeight - $this->labelPadding + ); + $alignement = ezcGraph::TOP | ezcGraph::LEFT; + break; // Draw label at top left of step case ( ( $axis->position === ezcGraph::BOTTOM ) && ( !$step->isLast ) ) || From 5025ae721395053b4f0bcde51ffc0c062dbce38c Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Fri, 21 Jan 2022 18:22:16 +0100 Subject: [PATCH 3/5] Add test for new $axis->labelPosition = ezcGraph::RIGHT feature. --- tests/axis_exact_renderer_test.php | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/axis_exact_renderer_test.php b/tests/axis_exact_renderer_test.php index dc384290..7a9de51d 100644 --- a/tests/axis_exact_renderer_test.php +++ b/tests/axis_exact_renderer_test.php @@ -390,6 +390,49 @@ public function testRenderTextBoxes() $chart->render( 500, 200 ); } + public function testRenderTextBoxesWithLabelPositionRight() + { + $chart = new ezcGraphLineChart(); + $chart->palette = new ezcGraphPaletteBlack(); + $chart->xAxis->axisLabelRenderer = new ezcGraphAxisExactLabelRenderer(); + $chart->xAxis->labelPosition = ezcGraph::RIGHT; + $chart->yAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer(); + $chart->data['sampleData'] = new ezcGraphArrayDataSet( 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( 142., 162., 178., 178. ), 1. ), + $this->equalTo( 'sample 1' ), + $this->equalTo( ezcGraph::BOTTOM | ezcGraph::LEFT ) + ); + $mockedRenderer + ->expects( $this->at( 1 ) ) + ->method( 'drawText' ) + ->with( + $this->equalTo( new ezcGraphBoundings( 222., 162., 258., 178. ), 1. ), + $this->equalTo( 'sample 2' ), + $this->equalTo( ezcGraph::BOTTOM | ezcGraph::LEFT ) + ); + $mockedRenderer + ->expects( $this->at( 4 ) ) + ->method( 'drawText' ) + ->with( + $this->equalTo( new ezcGraphBoundings( 462., 182., 498., 198. ), 1. ), + $this->equalTo( 'sample 5' ), + $this->equalTo( ezcGraph::TOP | ezcGraph::LEFT ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); + } + public function testRenderTextBoxesWithoutLastLabel() { $chart = new ezcGraphLineChart(); From 1cd476a3a35c803f9b3968bbb045ebbe4b4e3ad0 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Fri, 21 Jan 2022 18:27:10 +0100 Subject: [PATCH 4/5] Remove TOP/BOTTOM options for label position for now as LEFT is default and only code for RIGHT exists. Add a test for setting element property. --- src/element/axis.php | 2 -- tests/element_options_test.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/element/axis.php b/src/element/axis.php index 2dcb7dc7..0ade916c 100644 --- a/src/element/axis.php +++ b/src/element/axis.php @@ -301,8 +301,6 @@ public function __set( $propertyName, $propertyValue ) break; case 'labelPosition': $positions = array( - ezcGraph::TOP, - ezcGraph::BOTTOM, ezcGraph::LEFT, ezcGraph::RIGHT, ); diff --git a/tests/element_options_test.php b/tests/element_options_test.php index cd9856f8..353358ae 100644 --- a/tests/element_options_test.php +++ b/tests/element_options_test.php @@ -652,6 +652,34 @@ public function testChartElementAxisPropertyAxisSpace() $this->fail( 'Expected ezcBaseValueException.' ); } + public function testChartElementAxisPropertyLabelPosition() + { + $options = new ezcGraphChartElementNumericAxis(); + + $this->assertSame( + ezcGraph::LEFT, + $options->labelPosition, + 'Wrong default value for property labelPosition in class ezcGraphChartElementNumericAxis' + ); + + $options->labelPosition = ezcGraph::RIGHT; + + $this->assertSame( + ezcGraph::RIGHT, + $options->labelPosition, + 'Setting property value did not work for property labelPosition in class ezcGraphChartElementNumericAxis' + ); + + try + { + $options->labelPosition = ezcGraph::TOP; + } + catch ( ezcBaseValueException $e ) + { + return true; + } + } + /* Disabled for now. public function testChartElementAxisPropertyOuterAxisSpace() { From d0ae978de3c385742e7ef5aaf1fd49c03160225e Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Fri, 21 Jan 2022 18:29:16 +0100 Subject: [PATCH 5/5] Improve cs slightly --- src/renderer/axis_label_exact.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/renderer/axis_label_exact.php b/src/renderer/axis_label_exact.php index d0027116..a07fd5de 100644 --- a/src/renderer/axis_label_exact.php +++ b/src/renderer/axis_label_exact.php @@ -207,12 +207,11 @@ public function renderLabels( // Skip last step if showLastValue is false $showLabel = false; break; - // NTH : Draw label at top right of step on vertical axis - case ( ( $axis->labelPosition === ezcGraph::RIGHT ) && - ( !$step->isLast ) ) || - ( ( $axis->labelPosition === ezcGraph::RIGHT ) && - ( $step->isLast ) && - ( $this->renderLastOutside ) ) : + case ( ( $axis->labelPosition === ezcGraph::RIGHT ) && + ( !$step->isLast ) ) || + ( ( $axis->labelPosition === ezcGraph::RIGHT ) && + ( $step->isLast ) && + ( $this->renderLastOutside ) ) : $labelBoundings = new ezcGraphBoundings( $position->x + $this->labelPadding, $position->y - $labelHeight + $this->labelPadding, @@ -221,9 +220,9 @@ public function renderLabels( ); $alignement = ezcGraph::LEFT | ezcGraph::BOTTOM; break; - case ( ( $axis->labelPosition === ezcGraph::RIGHT ) && - ( $step->isLast ) && - ( !$this->renderLastOutside ) ) : + case ( ( $axis->labelPosition === ezcGraph::RIGHT ) && + ( $step->isLast ) && + ( !$this->renderLastOutside ) ) : $labelBoundings = new ezcGraphBoundings( $position->x + $this->labelPadding, $position->y + $this->labelPadding,