summaryrefslogtreecommitdiffstats
path: root/src/axis/numeric.php
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-06-06 08:49:03 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-06-06 08:49:03 +0000
commit8e4f782905f165b9834bff2e95d07884c1fa5bd6 (patch)
tree7ab180f36768b39a81235ba8883e38daf91c8806 /src/axis/numeric.php
parent792f2f514e83efc794dd9cec3c07534c651b2a21 (diff)
downloadzetacomponents-graph-8e4f782905f165b9834bff2e95d07884c1fa5bd6.zip
zetacomponents-graph-8e4f782905f165b9834bff2e95d07884c1fa5bd6.tar.gz
- Fixed axis to use axis type based labeling methods, which results in better
labeling
Diffstat (limited to 'src/axis/numeric.php')
-rw-r--r--src/axis/numeric.php147
1 files changed, 147 insertions, 0 deletions
diff --git a/src/axis/numeric.php b/src/axis/numeric.php
index c92ebb0..161130c 100644
--- a/src/axis/numeric.php
+++ b/src/axis/numeric.php
@@ -290,6 +290,153 @@ class ezcGraphChartElementNumericAxis extends ezcGraphChartElementAxis
return (int) ( ( $this->max - $this->min ) / $this->majorStep );
}
+ /**
+ * 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();
+
+ // 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->padding / 2 ) );
+ $yBorder = abs ( ( $boundings->y1 - $boundings->y0 ) * ( $this->padding / 2 ) );
+
+ for ( $i = 0; $i <= $steps; ++$i )
+ {
+ // Draw label
+ if ( $i < $steps )
+ {
+ $label = $this->getLabel( $i );
+
+ switch ( $this->position )
+ {
+ case ezcGraph::LEFT:
+ $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,
+ ezcGraph::LEFT | ezcGraph::TOP
+ );
+ break;
+ case ezcGraph::RIGHT:
+ $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,
+ ezcGraph::RIGHT | ezcGraph::TOP
+ );
+ break;
+ case ezcGraph::BOTTOM:
+ $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 | ezcGraph::BOTTOM
+ );
+ break;
+ case ezcGraph::TOP:
+ $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 | ezcGraph::TOP
+ );
+ break;
+ }
+ }
+ else
+ {
+ $label = $this->getLabel( $i-- );
+
+ switch ( $this->position )
+ {
+ case ezcGraph::LEFT:
+ $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,
+ ezcGraph::RIGHT | ezcGraph::TOP
+ );
+ break;
+ case ezcGraph::RIGHT:
+ $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,
+ ezcGraph::LEFT | ezcGraph::TOP
+ );
+ break;
+ case ezcGraph::BOTTOM:
+ $renderer->drawTextBox(
+ new ezcGraphCoordinate(
+ (int) round( $start->x + $i * $xStepsize - $xBorder ),
+ (int) round( $start->y + $i * $yStepsize + $yStepsize + $this->labelPadding )
+ ),
+ $label,
+ $xBorder - $this->labelPadding,
+ (int) round( -$yStepsize ) - $this->labelPadding,
+ ezcGraph::RIGHT | ezcGraph::TOP
+ );
+ break;
+ case ezcGraph::TOP:
+ $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 | ezcGraph::BOTTOM
+ );
+ break;
+ }
+ ++$i;
+ }
+ }
+ }
+
+ /**
+ * Get label for a dedicated step on the axis
+ *
+ * @param integer $step Number of step
+ * @return string label
+ */
protected function getLabel( $step )
{
return $this->min + ( $step * $this->majorStep );
OpenPOWER on IntegriCloud