summaryrefslogtreecommitdiffstats
path: root/src/renderer
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-07-21 14:14:56 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-07-21 14:14:56 +0000
commit49ded86c90d1bfa6cc0b780b1ad00544f9d198fd (patch)
tree29a292b23a6b1af6159fa6fa82515c3aed1097e6 /src/renderer
parent14f4f83b181822bb65c55ca76eb0e28157ba43b4 (diff)
downloadzetacomponents-graph-49ded86c90d1bfa6cc0b780b1ad00544f9d198fd.zip
zetacomponents-graph-49ded86c90d1bfa6cc0b780b1ad00544f9d198fd.tar.gz
- Readded drawing of axis steps and grids (only available in
ezcGraphAxisExactLabelRenderer yet)
Diffstat (limited to 'src/renderer')
-rw-r--r--src/renderer/2d.php62
-rw-r--r--src/renderer/axis_label_centered.php12
-rw-r--r--src/renderer/axis_label_exact.php37
3 files changed, 87 insertions, 24 deletions
diff --git a/src/renderer/2d.php b/src/renderer/2d.php
index b3a21f2..b022d8d 100644
--- a/src/renderer/2d.php
+++ b/src/renderer/2d.php
@@ -585,6 +585,46 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
$align
);
}
+
+ /**
+ * Draw grid line
+ *
+ * Draw line for the grid in the chart background
+ *
+ * @param ezcGraphCoordinate $start Start point
+ * @param ezcGraphCoordinate $end End point
+ * @param ezcGraphColor $color Color of the grid line
+ * @return void
+ */
+ public function drawGridLine( ezcGraphCoordinate $start, ezcGraphCoordinate $end, ezcGraphColor $color )
+ {
+ $this->driver->drawLine(
+ $start,
+ $end,
+ $color,
+ 1
+ );
+ }
+
+ /**
+ * Draw step line
+ *
+ * Draw a step (marker for label position) on a axis.
+ *
+ * @param ezcGraphCoordinate $start Start point
+ * @param ezcGraphCoordinate $end End point
+ * @param ezcGraphColor $color Color of the grid line
+ * @return void
+ */
+ public function drawStepLine( ezcGraphCoordinate $start, ezcGraphCoordinate $end, ezcGraphColor $color )
+ {
+ $this->driver->drawLine(
+ $start,
+ $end,
+ $color,
+ 1
+ );
+ }
/**
* Draw axis
@@ -679,11 +719,25 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
true
);
+ $xAxisSpace = ( $end->x - $start->x ) * $axis->axisSpace;
+ $yAxisSpace = ( $end->y - $start->y ) * $axis->axisSpace;
+
// Apply axisSpace to start and end
- $start->x += ( $end->x - $start->x ) * ( $axis->axisSpace / 2 );
- $start->y += ( $end->y - $start->y ) * ( $axis->axisSpace / 2 );
- $end->x -= ( $end->x - $start->x ) * ( $axis->axisSpace / 2 );
- $end->y -= ( $end->y - $start->y ) * ( $axis->axisSpace / 2 );
+ $start->x += $xAxisSpace;
+ $start->y += $yAxisSpace;
+ $end->x -= $xAxisSpace;
+ $end->y -= $yAxisSpace;
+
+ if ( $labelClass !== null )
+ {
+ $labelClass->renderLabels(
+ $this,
+ $boundings,
+ $start,
+ $end,
+ $axis
+ );
+ }
}
/**
diff --git a/src/renderer/axis_label_centered.php b/src/renderer/axis_label_centered.php
index 04edfc4..165af95 100644
--- a/src/renderer/axis_label_centered.php
+++ b/src/renderer/axis_label_centered.php
@@ -14,24 +14,28 @@
*
* @package Graph
*/
-abstract class ezcGraphAxisLabelRenderer
+class ezcGraphAxisLabelRenderer
{
/**
* Render Axis labels
*
* Render labels for an axis.
*
+ * @param ezcGraphRenderer $renderer Renderer used to draw the chart
* @param ezcGraphBoundings $boundings Boundings of the axis
* @param ezcGraphCoordinate $start Axis starting point
* @param ezcGraphCoordinate $end Axis ending point
* @param ezcGraphChartElementAxis $axis Axis instance
* @return void
*/
- abstract function renderLabels(
+ public function renderLabels(
+ ezcGraphRenderer $renderer,
ezcGraphBoundings $boundings,
ezcGraphCoordinate $start,
ezcGraphCoordinate $end,
- ezcGraphChartElementAxis $axis
- );
+ ezcGraphChartElementAxis $axis )
+ {
+
+ }
}
?>
diff --git a/src/renderer/axis_label_exact.php b/src/renderer/axis_label_exact.php
index 9103956..1c71c6f 100644
--- a/src/renderer/axis_label_exact.php
+++ b/src/renderer/axis_label_exact.php
@@ -29,20 +29,24 @@ class ezcGraphAxisExactLabelRenderer extends ezcGraphAxisLabelRenderer
*
* Render labels for an axis.
*
+ * @param ezcGraphRenderer $renderer Renderer used to draw the chart
* @param ezcGraphBoundings $boundings Boundings of the axis
* @param ezcGraphCoordinate $start Axis starting point
* @param ezcGraphCoordinate $end Axis ending point
* @param ezcGraphChartElementAxis $axis Axis instance
- * @param int $position Position of axis (left, right, or center)
* @return void
*/
public function renderLabels(
+ ezcGraphRenderer $renderer,
ezcGraphBoundings $boundings,
ezcGraphCoordinate $start,
ezcGraphCoordinate $end,
- ezcGraphChartElementAxis $axis,
- $axisPosition )
+ ezcGraphChartElementAxis $axis )
{
+ // receive rendering parameters from axis
+ $this->majorStepCount = $axis->getMajorStepCount();
+ $this->minorStepCount = $axis->getMinorStepCount();
+
// Determine normalized axis direction
$direction = new ezcGraphCoordinate(
$start->x - $end->x,
@@ -58,7 +62,7 @@ class ezcGraphAxisExactLabelRenderer extends ezcGraphAxisLabelRenderer
( $end->y - $start->y ) / $this->majorStepCount
);
- if ( $this->minorStepCount !== false )
+ if ( $this->minorStepCount )
{
$minorStep = new ezcGraphCoordinate(
( $end->x - $start->x ) / $this->minorStepCount,
@@ -81,19 +85,20 @@ class ezcGraphAxisExactLabelRenderer extends ezcGraphAxisLabelRenderer
}
// Draw steps and grid
- while ( $start->x <= $end->x )
+ while ( ( $start->x <= $end->x ) &&
+ ( $start->y <= $end->y ) )
{
- // major step
- $this->drawStep( $start, $direction, $axisPosition, $this->majorStepSize, $axis->border );
-
// major grid
- if ( $this->majorGrid )
+ if ( $axis->majorGrid )
{
- $this->drawGrid( $gridBoundings, $start, $majorStep, $axis->majorGrid );
+ $this->drawGrid( $renderer, $gridBoundings, $start, $majorStep, $axis->majorGrid );
}
+ // major step
+ $this->drawStep( $renderer, $start, $direction, $axis->position, $this->majorStepSize, $axis->border );
+
// second iteration for minor steps, if wanted
- if ( $this->minorStepCount !== false )
+ if ( $this->minorStepCount )
{
$minorGridPosition = new ezcGraphCoordinate(
$start->x + $minorStep->x,
@@ -102,17 +107,17 @@ class ezcGraphAxisExactLabelRenderer extends ezcGraphAxisLabelRenderer
while ( $minorGridPosition->x < ( $start->x + $majorStep->x ) )
{
- // minor step
- $this->drawStep( $minorGridPosition, $direction, $axisPosition, $this->minorStepSize, $axis->border );
-
// minor grid
- if ( $this->minorGrid )
+ if ( $axis->minorGrid )
{
- $this->drawGrid( $gridBoundings, $minorGridPosition, $majorStep, $axis->minorGrid );
+ $this->drawGrid( $renderer, $gridBoundings, $minorGridPosition, $majorStep, $axis->minorGrid );
}
$minorGridPosition->x += $minorStep->x;
$minorGridPosition->y += $minorStep->y;
+
+ // minor step
+ $this->drawStep( $renderer, $minorGridPosition, $direction, $axis->position, $this->minorStepSize, $axis->border );
}
}
OpenPOWER on IntegriCloud