summaryrefslogtreecommitdiffstats
path: root/src/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer')
-rw-r--r--src/renderer/axis_label_centered.php96
-rw-r--r--src/renderer/axis_label_exact.php19
2 files changed, 95 insertions, 20 deletions
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 ) ) ||
OpenPOWER on IntegriCloud