summaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/axis/labeled.php138
-rw-r--r--src/axis/numeric.php6
-rw-r--r--src/driver/svg.php1
-rw-r--r--src/driver/verbose.php17
-rw-r--r--src/element/axis.php6
-rw-r--r--src/interfaces/axis_label_renderer.php139
-rw-r--r--src/interfaces/renderer.php2
-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
10 files changed, 191 insertions, 229 deletions
diff --git a/src/axis/labeled.php b/src/axis/labeled.php
index 132200f..1d202ce 100644
--- a/src/axis/labeled.php
+++ b/src/axis/labeled.php
@@ -165,7 +165,7 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis
*
* @return integer Count of minor steps
*/
- protected function getMinorStepCount()
+ public function getMinorStepCount()
{
return 0;
}
@@ -175,150 +175,18 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis
*
* @return integer Count of major steps
*/
- protected function getMajorStepCount()
+ public function getMajorStepCount()
{
return count( $this->displayedLabels ) - 1;
}
/**
- * Draw labels for an axis
- *
- * @param ezcGraphRenderer $renderer
- * @param ezcGraphCoordinate $start
- * @param ezcGraphCoordinate $end
- * @param ezcGraphBoundings $boundings
- * @return void
- */
- protected function drawLabels( ezcGraphRenderer $renderer, ezcGraphCoordinate $start, ezcGraphCoordinate $end, ezcGraphBoundings $boundings )
- {
- // Draw major steps
- $steps = $this->getMajorStepCount() + 1;
-
- // Calculate stepsize
- $xStepsize = ( $end->x - $start->x ) / $steps;
- $yStepsize = ( $end->y - $start->y ) / $steps;
-
- // Caluclate datafree chart border
- $xBorder = abs ( ( $boundings->x1 - $boundings->x0 ) * ( $this->axisSpace / 2 ) );
- $yBorder = abs ( ( $boundings->y1 - $boundings->y0 ) * ( $this->axisSpace / 2 ) );
-
- for ( $i = 0; $i <= $steps; ++$i )
- {
- $label = sprintf( $this->formatString, $this->getLabel( $i ) );
-
- switch ( $this->position )
- {
- case ezcGraph::LEFT:
- if ( $i === 0 )
- {
- $align = ezcGraph::LEFT;
- }
- elseif ( $i >= ( $steps - 1 ) )
- {
- $align = ezcGraph::RIGHT;
- }
- else
- {
- $align = ezcGraph::CENTER;
- }
-
- $renderer->drawTextBox(
- new ezcGraphCoordinate(
- (int) round( $start->x + $i * $xStepsize + $this->labelPadding ),
- (int) round( $start->y + $i * $yStepsize + $this->labelPadding )
- ),
- $label,
- (int) round( $xStepsize ) - $this->labelPadding,
- $yBorder - $this->labelPadding,
- $align | ezcGraph::TOP
- );
- break;
- case ezcGraph::RIGHT:
- if ( $i === 0 )
- {
- $align = ezcGraph::RIGHT;
- }
- elseif ( $i >= ( $steps - 1 ) )
- {
- $align = ezcGraph::LEFT;
- }
- else
- {
- $align = ezcGraph::CENTER;
- }
-
- $renderer->drawTextBox(
- new ezcGraphCoordinate(
- (int) round( $start->x + $i * $xStepsize + $xStepsize ),
- (int) round( $start->y + $i * $yStepsize + $this->labelPadding )
- ),
- $label,
- (int) round( -$xStepsize ) - $this->labelPadding,
- $yBorder - $this->labelPadding,
- $align | ezcGraph::TOP
- );
- break;
- case ezcGraph::BOTTOM:
- if ( $i === 0 )
- {
- $align = ezcGraph::BOTTOM;
- }
- elseif ( $i >= ( $steps - 1 ) )
- {
- $align = ezcGraph::TOP;
- }
- else
- {
- $align = ezcGraph::MIDDLE;
- }
-
- $renderer->drawTextBox(
- new ezcGraphCoordinate(
- (int) round( $start->x + $i * $xStepsize - $xBorder ),
- (int) round( $start->y + $i * $yStepsize + $yStepsize )
- ),
- $label,
- $xBorder - $this->labelPadding,
- (int) round( -$yStepsize ) - $this->labelPadding,
- ezcGraph::RIGHT | $align
- );
- break;
- case ezcGraph::TOP:
- if ( $i === 0 )
- {
- $align = ezcGraph::TOP;
- }
- elseif ( $i >= ( $steps - 1 ) )
- {
- $align = ezcGraph::BOTTOM;
- }
- else
- {
- $align = ezcGraph::MIDDLE;
- }
-
- $renderer->drawTextBox(
- new ezcGraphCoordinate(
- (int) round( $start->x + $i * $xStepsize - $xBorder ),
- (int) round( $start->y + $i * $yStepsize + $this->labelPadding )
- ),
- $label,
- $xBorder - $this->labelPadding,
- (int) round( $yStepsize ) - $this->labelPadding,
- ezcGraph::RIGHT | $align
- );
- break;
- }
- }
- }
-
- /**
* Get label for a dedicated step on the axis
*
* @param integer $step Number of step
* @return string label
*/
- protected function getLabel( $step )
+ public function getLabel( $step )
{
if ( isset( $this->displayedLabels[$step] ) )
{
diff --git a/src/axis/numeric.php b/src/axis/numeric.php
index f0cfc24..023a9ea 100644
--- a/src/axis/numeric.php
+++ b/src/axis/numeric.php
@@ -301,7 +301,7 @@ class ezcGraphChartElementNumericAxis extends ezcGraphChartElementAxis
*
* @return integer Count of minor steps
*/
- protected function getMinorStepCount()
+ public function getMinorStepCount()
{
return (int) ( ( $this->max - $this->min ) / $this->minorStep );
}
@@ -311,7 +311,7 @@ class ezcGraphChartElementNumericAxis extends ezcGraphChartElementAxis
*
* @return integer Count of major steps
*/
- protected function getMajorStepCount()
+ public function getMajorStepCount()
{
return (int) ( ( $this->max - $this->min ) / $this->majorStep );
}
@@ -463,7 +463,7 @@ class ezcGraphChartElementNumericAxis extends ezcGraphChartElementAxis
* @param integer $step Number of step
* @return string label
*/
- protected function getLabel( $step )
+ public function getLabel( $step )
{
return $this->min + ( $step * $this->majorStep );
}
diff --git a/src/driver/svg.php b/src/driver/svg.php
index 42ad365..69941bb 100644
--- a/src/driver/svg.php
+++ b/src/driver/svg.php
@@ -51,7 +51,6 @@ class ezcGraphSvgDriver extends ezcGraphDriver
public function __construct( array $options = array() )
{
$this->options = new ezcGraphSvgDriverOptions( $options );
-
}
protected function createDocument()
diff --git a/src/driver/verbose.php b/src/driver/verbose.php
index 80867fd..1a0757e 100644
--- a/src/driver/verbose.php
+++ b/src/driver/verbose.php
@@ -17,8 +17,9 @@ class ezcGraphVerboseDriver extends ezcGraphDriver
{
protected $call = 0;
- public function __construct()
+ public function __construct( array $options = array() )
{
+ $this->options = new ezcGraphSvgDriverOptions( $options );
echo "\n";
}
@@ -38,7 +39,7 @@ class ezcGraphVerboseDriver extends ezcGraphDriver
$pointString .= sprintf( "\t( %.2f, %.2f )\n", $point->x, $point->y );
}
- printf( "%03d: Draw %spolygon:\n%s",
+ printf( "% 4d: Draw %spolygon:\n%s",
$this->call++,
( $filled ? 'filled ' : '' ),
$pointString
@@ -55,7 +56,7 @@ class ezcGraphVerboseDriver extends ezcGraphDriver
*/
public function drawLine( ezcGraphCoordinate $start, ezcGraphCoordinate $end, ezcGraphColor $color, $thickness = 1 )
{
- printf( "%03d: Draw line from ( %.2f, %.2f ) to ( %.2f, %.2f ) with thickness %d.\n",
+ printf( "% 4d: Draw line from ( %.2f, %.2f ) to ( %.2f, %.2f ) with thickness %d.\n",
$this->call++,
$start->x,
$start->y,
@@ -77,7 +78,7 @@ class ezcGraphVerboseDriver extends ezcGraphDriver
*/
public function drawTextBox( $string, ezcGraphCoordinate $position, $width, $height, $align )
{
- printf( "%03d: Draw text '%s' at ( %.2f, %.2f ) with dimensions ( %d, %d ) and alignement %d.\n",
+ printf( "% 4d: Draw text '%s' at ( %.2f, %.2f ) with dimensions ( %d, %d ) and alignement %d.\n",
$this->call++,
$string,
$position->x,
@@ -100,7 +101,7 @@ class ezcGraphVerboseDriver extends ezcGraphDriver
*/
public function drawCircleSector( ezcGraphCoordinate $center, $width, $height, $startAngle, $endAngle, ezcGraphColor $color, $filled = true )
{
- printf( "%03d: Draw %scicle sector at ( %.2f, %.2f ) with dimensions ( %d, %d ) from %.2f to %.2f.\n",
+ printf( "% 4d: Draw %scicle sector at ( %.2f, %.2f ) with dimensions ( %d, %d ) from %.2f to %.2f.\n",
$this->call++,
( $filled ? 'filled ' : '' ),
$center->x,
@@ -126,7 +127,7 @@ class ezcGraphVerboseDriver extends ezcGraphDriver
*/
public function drawCircularArc( ezcGraphCoordinate $center, $width, $height, $size, $startAngle, $endAngle, ezcGraphColor $color )
{
- printf( "%03d: Draw circular arc at ( %.2f, %.2f ) with dimensions ( %d, %d ) and size %.2f from %.2f to %.2f.\n",
+ printf( "% 4d: Draw circular arc at ( %.2f, %.2f ) with dimensions ( %d, %d ) and size %.2f from %.2f to %.2f.\n",
$this->call++,
$center->x,
$center->y,
@@ -151,7 +152,7 @@ class ezcGraphVerboseDriver extends ezcGraphDriver
*/
public function drawCircle( ezcGraphCoordinate $center, $width, $height, ezcGraphColor $color, $filled = true )
{
- printf( "%03d: Draw %scircle at ( %.2f, %.2f ) with dimensions ( %d, %d ).\n",
+ printf( "% 4d: Draw %scircle at ( %.2f, %.2f ) with dimensions ( %d, %d ).\n",
$this->call++,
( $filled ? 'filled ' : '' ),
$center->x,
@@ -172,7 +173,7 @@ class ezcGraphVerboseDriver extends ezcGraphDriver
*/
public function drawImage( $file, ezcGraphCoordinate $position, $width, $height )
{
- printf( "%03d: Draw image '%s' at ( %.2f, %.2f ) with dimensions ( %d, %d ).\n",
+ printf( "% 4d: Draw image '%s' at ( %.2f, %.2f ) with dimensions ( %d, %d ).\n",
$this->call++,
$file,
$position->x,
diff --git a/src/element/axis.php b/src/element/axis.php
index ac867a7..86623a0 100644
--- a/src/element/axis.php
+++ b/src/element/axis.php
@@ -202,14 +202,14 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement
*
* @return integer Count of minor steps
*/
- abstract protected function getMinorStepCount();
+ abstract public function getMinorStepCount();
/**
* Return count of major steps
*
* @return integer Count of major steps
*/
- abstract protected function getMajorStepCount();
+ abstract public function getMajorStepCount();
/**
* Get label for a dedicated step on the axis
@@ -217,7 +217,7 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement
* @param integer $step Number of step
* @return string label
*/
- abstract protected function getLabel( $step );
+ abstract public function getLabel( $step );
/**
* Add data for this axis
diff --git a/src/interfaces/axis_label_renderer.php b/src/interfaces/axis_label_renderer.php
index 0a024fb..5e6c06d 100644
--- a/src/interfaces/axis_label_renderer.php
+++ b/src/interfaces/axis_label_renderer.php
@@ -31,8 +31,6 @@ abstract class ezcGraphAxisLabelRenderer extends ezcBaseOptions
protected $outerStep = false;
- protected $innerGrid = true;
-
protected $outerGrid = false;
public function __set( $propertyName, $propertyValue )
@@ -67,9 +65,6 @@ abstract class ezcGraphAxisLabelRenderer extends ezcBaseOptions
case 'outerStep':
$this->outerStep = (bool) $propertyValue;
break;
- case 'innerGrid':
- $this->innerGrid = (bool) $propertyValue;
- break;
case 'outerGrid':
$this->outerGrid = (bool) $propertyValue;
break;
@@ -78,11 +73,55 @@ abstract class ezcGraphAxisLabelRenderer extends ezcBaseOptions
}
}
+ public function determineLineCuttingPoint( ezcGraphCoordinate $aStart, ezcGraphCoordinate $aDir, ezcGraphCoordinate $bStart, ezcGraphCoordinate $bDir )
+ {
+ // Check if line are parallel
+ // @TODO: This is not the optimal way because of inexact floating point
+ // numbers and not needed use of sqrt
+ $aLength = sqrt( pow( $aDir->x, 2 ) + pow( $aDir->y, 2 ) );
+ $bLength = sqrt( pow( $bDir->x, 2 ) + pow( $bDir->y, 2 ) );
+
+ if ( ( $aLength > 0 ) &&
+ ( $aDir->x / $aLength == $bDir->x / $bLength ) &&
+ ( $bLength > 0 ) &&
+ ( $aDir->y / $aLength == $bDir->y / $bLength ) )
+ {
+ return false;
+ }
+
+ // Use ? : to prevent division by zero
+ $denominator =
+ ( $aDir->y != 0 ? $bDir->y / $aDir->y : 0 ) -
+ ( $aDir->x != 0 ? $bDir->x / $aDir->x : 0 );
+
+ // Solve equatation
+ if ( $denominator == 0 )
+ {
+ return - (
+ ( $aDir->y != 0 ? $bStart->y / $aDir->y : 0 ) -
+ ( $aDir->y != 0 ? $aStart->y / $aDir->y : 0 ) -
+ ( $aDir->x != 0 ? $bStart->x / $aDir->x : 0 ) +
+ ( $aDir->x != 0 ? $aStart->x / $aDir->x : 0 )
+ );
+ }
+ else
+ {
+ return - (
+ ( $aDir->y != 0 ? $bStart->y / $aDir->y : 0 ) -
+ ( $aDir->y != 0 ? $aStart->y / $aDir->y : 0 ) -
+ ( $aDir->x != 0 ? $bStart->x / $aDir->x : 0 ) +
+ ( $aDir->x != 0 ? $aStart->x / $aDir->x : 0 )
+ ) / $denominator;
+
+ }
+ }
+
/**
* Draw single step on a axis
*
* Draws a step on a axis at the current position
*
+ * @param ezcGraphRenderer $renderer Renderer to draw the step with
* @param ezcGraphCoordinate $position Position of step
* @param ezcGraphCoordinate $direction Direction of axis
* @param int $axisPosition Position of axis
@@ -90,92 +129,71 @@ abstract class ezcGraphAxisLabelRenderer extends ezcBaseOptions
* @param ezcGraphColor $color Color of axis
* @return void
*/
- protected function drawStep( ezcGraphCoordinate $position, ezcGraphCoordinate $direction, $axisPosition, $size, ezcGraphColor $color )
+ public function drawStep( ezcGraphRenderer $renderer, ezcGraphCoordinate $position, ezcGraphCoordinate $direction, $axisPosition, $size, ezcGraphColor $color )
{
$drawStep = false;
if ( ( ( $axisPosition === ezcGraph::CENTER ) && $this->innerStep ) ||
- ( ( $axisPosition === ezcGraph::RIGHT ) && $this->innerStep ) ||
- ( ( $axisPosition === ezcGraph::LEFT ) && $this->outerStep ) )
+ ( ( $axisPosition === ezcGraph::BOTTOM ) && $this->outerStep ) ||
+ ( ( $axisPosition === ezcGraph::TOP ) && $this->innerStep ) ||
+ ( ( $axisPosition === ezcGraph::RIGHT ) && $this->outerStep ) ||
+ ( ( $axisPosition === ezcGraph::LEFT ) && $this->innerStep ) )
{
// Turn direction vector to left by 90 degrees and multiply
// with major step size
$stepStart = new ezcGraphCoordinate(
- - $direction->y * $size,
- $direction->x * $size
+ $position->x - $direction->y * $size,
+ $position->y + $direction->x * $size
);
$drawStep = true;
}
else
{
- $stepStart = $start;
+ $stepStart = $position;
}
if ( ( ( $axisPosition === ezcGraph::CENTER ) && $this->innerStep ) ||
- ( ( $axisPosition === ezcGraph::RIGHT ) && $this->outerStep ) ||
- ( ( $axisPosition === ezcGraph::LEFT ) && $this->innerStep ) )
+ ( ( $axisPosition === ezcGraph::BOTTOM ) && $this->innerStep ) ||
+ ( ( $axisPosition === ezcGraph::TOP ) && $this->outerStep ) ||
+ ( ( $axisPosition === ezcGraph::RIGHT ) && $this->innerStep ) ||
+ ( ( $axisPosition === ezcGraph::LEFT ) && $this->outerStep ) )
{
// Turn direction vector to right by 90 degrees and multiply
// with major step size
$stepEnd = new ezcGraphCoordinate(
- $direction->y * $size,
- - $direction->x * $size
+ $position->x + $direction->y * $size,
+ $position->y - $direction->x * $size
);
$drawStep = true;
}
else
{
- $stepEnd = $end;
+ $stepEnd = $position;
}
if ( $drawStep )
{
- $this->driver->drawLine(
+ $renderer->drawStepLine(
$stepStart,
$stepEnd,
$color
);
}
}
-
- public function determineLineCuttingPoint( ezcGraphCoordinate $aStart, ezcGraphCoordinate $aDir, ezcGraphCoordinate $bStart, ezcGraphCoordinate $bDir )
- {
- // Check if line are parallel
- // @TODO: This is not the optimal way because of inexact floating point
- // numbers and not needed use of sqrt
- $aLength = sqrt( pow( $aDir->x, 2 ) + pow( $aDir->y, 2 ) );
- $bLength = sqrt( pow( $bDir->x, 2 ) + pow( $bDir->y, 2 ) );
-
- if ( ( $aDir->x / $aLength == $bDir->x / $bLength ) &&
- ( $aDir->x / $aLength == $bDir->x / $bLength ) )
- {
- return false;
- }
-
- // Solve equatation
- return - (
- ( $bStart->y / $aDir->y ) -
- ( $aStart->y / $aDir->y ) -
- ( $bStart->x / $aDir->x ) +
- ( $aStart->x / $aDir->x )
- ) / (
- ( $bDir->y / $aDir->y ) -
- ( $bDir->x / $aDir->x )
- );
- }
/**
* Draw grid
*
* Draws a grid line at the current position
*
+ * @param ezcGraphRenderer $renderer Renderer to draw the grid with
* @param ezcGraphBoundings $boundings Boundings of axis
* @param ezcGraphCoordinate $position Position of step
* @param ezcGraphCoordinate $direction Direction of axis
* @param ezcGraphColor $color Color of axis
* @return void
*/
- protected function drawGrid( ezcGraphBoundings $boundings, ezcGraphCoordinate $position, ezcGraphCoordinate $direction, ezcGraphColor $color )
+ protected function drawGrid( ezcGraphRenderer $renderer, ezcGraphBoundings $boundings, ezcGraphCoordinate $position, ezcGraphCoordinate $direction, ezcGraphColor $color )
{
// Direction of grid line is direction of axis turned right by 90
// degrees
@@ -192,7 +210,7 @@ abstract class ezcGraphAxisLabelRenderer extends ezcBaseOptions
),
array(
'start' => new ezcGraphCoordinate( $boundings->x0, $boundings->y0 ),
- 'dir' => new ezcGraphCoordinate( 0, $boundings->x1 - $boundings->x0 )
+ 'dir' => new ezcGraphCoordinate( $boundings->x1 - $boundings->x0, 0 )
),
array(
'start' => new ezcGraphCoordinate( $boundings->x1, $boundings->y1 ),
@@ -200,7 +218,7 @@ abstract class ezcGraphAxisLabelRenderer extends ezcBaseOptions
),
array(
'start' => new ezcGraphCoordinate( $boundings->x1, $boundings->y1 ),
- 'dir' => new ezcGraphCoordinate( 0, $boundings->x0 - $boundings->x1 )
+ 'dir' => new ezcGraphCoordinate( $boundings->x0 - $boundings->x1, 0 )
),
) as $boundingLine )
{
@@ -210,13 +228,21 @@ abstract class ezcGraphAxisLabelRenderer extends ezcBaseOptions
// ending point for the grid lines. There should *always* be two
// points returned.
$cuttingPosition = $this->determineLineCuttingPoint(
- $start,
- $gridDirection,
$boundingLine['start'],
- $boundingLine['dir']
+ $boundingLine['dir'],
+ $position,
+ $gridDirection
);
- if ( $cuttingPosition > 0 && $cuttingPosition <= 1 )
+ if ( $cuttingPosition === false )
+ {
+ continue;
+ }
+ // Round to prevent minor float incorectnesses
+ $cuttingPosition = round( $cuttingPosition, 2 );
+
+ if ( ( $cuttingPosition >= 0 ) &&
+ ( $cuttingPosition <= 1 ) )
{
$cuttingPoints[] = new ezcGraphCoordinate(
$boundingLine['start']->x + $cuttingPosition * $boundingLine['dir']->x,
@@ -225,8 +251,13 @@ abstract class ezcGraphAxisLabelRenderer extends ezcBaseOptions
}
}
+ if ( count( $cuttingPoints ) < 2 )
+ {
+ return false;
+ }
+
// Finally draw grid line
- $this->driver->drawLine(
+ $renderer->drawGridLine(
$cuttingPoints[0],
$cuttingPoints[1],
$color
@@ -266,19 +297,19 @@ abstract class ezcGraphAxisLabelRenderer extends ezcBaseOptions
*
* 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
*/
abstract public function renderLabels(
+ ezcGraphRenderer $renderer,
ezcGraphBoundings $boundings,
ezcGraphCoordinate $start,
ezcGraphCoordinate $end,
- ezcGraphChartElementAxis $axis,
- $axisPosition
+ ezcGraphChartElementAxis $axis
);
}
?>
diff --git a/src/interfaces/renderer.php b/src/interfaces/renderer.php
index 03b2ea5..01f628c 100644
--- a/src/interfaces/renderer.php
+++ b/src/interfaces/renderer.php
@@ -135,7 +135,7 @@ abstract class ezcGraphRenderer
$text,
$align = ezcGraph::LEFT
);
-
+
/**
* Draw axis
*
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