diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2009-07-21 16:17:34 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2009-07-21 16:17:34 +0000 |
commit | 7dd703aeb9f89098f5752e9b38abffe9a800c43a (patch) | |
tree | 78b32a791534b742d23257046b6fa3a23449bb01 /src/renderer | |
parent | d3098e04fc668f56dc3a5ac23b2030df2e33931b (diff) | |
download | zetacomponents-graph-7dd703aeb9f89098f5752e9b38abffe9a800c43a.zip zetacomponents-graph-7dd703aeb9f89098f5752e9b38abffe9a800c43a.tar.gz |
- Implemented: #15095: Special rotated label renderer for bar charts.
Diffstat (limited to 'src/renderer')
-rw-r--r-- | src/renderer/axis_label_rotated_boxed.php | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/src/renderer/axis_label_rotated_boxed.php b/src/renderer/axis_label_rotated_boxed.php new file mode 100644 index 0000000..089d005 --- /dev/null +++ b/src/renderer/axis_label_rotated_boxed.php @@ -0,0 +1,146 @@ +<?php +/** + * File containing the ezcGraphAxisRotatedLabelRenderer class + * + * @package Graph + * @version //autogentag// + * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ +/** + * Can render axis labels rotated, so that more axis labels fit on one axis. + * Produces best results if the axis space was increased, so that more spcae is + * available below the axis. + * + * <code> + * $chart->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer(); + * + * // Define angle manually in degree + * $chart->xAxis->axisLabelRenderer->angle = 45; + * + * // Increase axis space + * $chart->xAxis->axisSpace = .2; + * </code> + * + * @property float $angle + * Angle of labels on axis in degrees. + * + * @version //autogentag// + * @package Graph + * @mainclass + */ +class ezcGraphAxisRotatedBoxedLabelRenderer extends ezcGraphAxisRotatedLabelRenderer +{ + /** + * 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 + */ + public function renderLabels( + ezcGraphRenderer $renderer, + ezcGraphBoundings $boundings, + ezcGraphCoordinate $start, + ezcGraphCoordinate $end, + ezcGraphChartElementAxis $axis, + ezcGraphBoundings $innerBoundings = null ) + { + // receive rendering parameters from axis + $this->steps = $steps = $axis->getSteps(); + + $axisBoundings = new ezcGraphBoundings( + $start->x, $start->y, + $end->x, $end->y + ); + + // Determine normalized axis direction + $this->direction = new ezcGraphVector( + $end->x - $start->x, + $end->y - $start->y + ); + $this->direction->unify(); + + // Get axis space + $gridBoundings = null; + list( $xSpace, $ySpace ) = $this->getAxisSpace( $renderer, $boundings, $axis, $innerBoundings, $gridBoundings ); + + // Determine optimal angle if none specified + $this->determineAngle( $steps, $xSpace, $ySpace, $axisBoundings ); + $degTextAngle = $this->determineTextOffset( $axis, $steps ); + $labelLength = $this->calculateLabelLength( $start, $end, $xSpace, $ySpace, $axisBoundings ); + + // Determine additional required axis space by boxes + $firstStep = reset( $steps ); + $lastStep = end( $steps ); + + $this->widthModifier = 1 + $firstStep->width / 2 + $lastStep->width / 2; + + // Draw steps and grid + foreach ( $steps as $nr => $step ) + { + $position = new ezcGraphCoordinate( + $start->x + ( $end->x - $start->x ) * ( $step->position + $step->width ) / $this->widthModifier, + $start->y + ( $end->y - $start->y ) * ( $step->position + $step->width ) / $this->widthModifier + ); + + $stepWidth = $step->width / $this->widthModifier; + + $stepSize = new ezcGraphCoordinate( + $axisBoundings->width * $stepWidth, + $axisBoundings->height * $stepWidth + ); + + // Calculate label boundings + $labelSize = $this->calculateLabelSize( $steps, $nr, $step, $xSpace, $ySpace, $axisBoundings ); + $lengthReducement = min( + abs( tan( deg2rad( $this->angle ) ) * ( $labelSize / 2 ) ), + abs( $labelLength / 2 ) + ); + + $this->renderLabelText( $renderer, $axis, $position, $step->label, $degTextAngle, $labelLength, $labelSize, $lengthReducement ); + + // Major grid + if ( $axis->majorGrid ) + { + $this->drawGrid( $renderer, $gridBoundings, $position, $stepSize, $axis->majorGrid ); + } + + // Major step + $this->drawStep( $renderer, $position, $this->direction, $axis->position, $this->majorStepSize, $axis->border ); + } + } + + /** + * Modify chart data position + * + * Optionally additionally modify the coodinate of a data point + * + * @param ezcGraphCoordinate $coordinate Data point coordinate + * @return ezcGraphCoordinate Modified coordinate + */ + public function modifyChartDataPosition( ezcGraphCoordinate $coordinate ) + { + $firstStep = reset( $this->steps ); + $offset = $firstStep->width / 2 / $this->widthModifier; + + return new ezcGraphCoordinate( + $coordinate->x * abs( $this->direction->y ) + ( + $coordinate->x * ( 1 / $this->widthModifier ) * ( 1 - abs( $this->offset ) ) + + abs( $this->offset ) + + $offset + ) * abs( $this->direction->x ), + $coordinate->y * abs( $this->direction->x ) + ( + $coordinate->y * ( 1 / $this->widthModifier ) * ( 1 - abs( $this->offset ) ) + + abs( $this->offset ) + + $offset + ) * abs( $this->direction->y ) + ); + } +} +?> |