Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/element/axis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -296,6 +299,21 @@ public function __set( $propertyName, $propertyValue )

$this->properties['labelMargin'] = (int) $propertyValue;
break;
case 'labelPosition':
$positions = array(
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 ) )
Expand Down
24 changes: 24 additions & 0 deletions src/renderer/axis_label_exact.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,30 @@ public function renderLabels(
// Skip last step if showLastValue is false
$showLabel = false;
break;
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 ) ) ||
Expand Down
43 changes: 43 additions & 0 deletions tests/axis_exact_renderer_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
28 changes: 28 additions & 0 deletions tests/element_options_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down