diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2009-07-21 11:25:18 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2009-07-21 11:25:18 +0000 |
commit | 73061d5af4bcddd2df8169dccca17dfea5bb8477 (patch) | |
tree | dd1a19fe8c644a3f53d5f276ef5facfd5c6b57d6 /src/renderer | |
parent | 9ce834beee81194e02525a6cb836516dc379eeb7 (diff) | |
download | zetacomponents-graph-73061d5af4bcddd2df8169dccca17dfea5bb8477.zip zetacomponents-graph-73061d5af4bcddd2df8169dccca17dfea5bb8477.tar.gz |
- Implemented: #15133: Better configurable axis spaces.
# Large number of tests added. Had to go through all sensible combinations of
# axis and axis spaces to ensure it works correctly.
Diffstat (limited to 'src/renderer')
-rw-r--r-- | src/renderer/axis_label_rotated.php | 76 |
1 files changed, 46 insertions, 30 deletions
diff --git a/src/renderer/axis_label_rotated.php b/src/renderer/axis_label_rotated.php index 547bfdd..6187494 100644 --- a/src/renderer/axis_label_rotated.php +++ b/src/renderer/axis_label_rotated.php @@ -114,6 +114,43 @@ class ezcGraphAxisRotatedLabelRenderer extends ezcGraphAxisLabelRenderer } /** + * Determine label angle + * + * Determine the optiomal angle for the axis labels, of no angle has been + * provided by the user. + * + * @param array $steps + * @return void + */ + protected function determineAngle( array $steps, $xSpace, $ySpace, ezcGraphBoundings $axisBoundings ) + { + if ( $this->angle === null ) + { + $minimumStepWidth = null; + foreach ( $steps as $nr => $step ) + { + if ( ( $minimumStepWidth === null ) || + ( $step->width < $minimumStepWidth ) ) + { + $minimumStepWidth = $step->width; + } + } + + $width = abs( + $axisBoundings->width * $minimumStepWidth * $this->direction->x + + $axisBoundings->height * $minimumStepWidth * $this->direction->y + ); + $height = abs( + $ySpace * $this->direction->x + + $xSpace * $this->direction->y + ); + + $length = sqrt( pow( $width, 2 ) + pow( $height, 2 ) ); + $this->angle = rad2deg( acos( $height / $length ) ); + } + } + + /** * Render Axis labels * * Render labels for an axis. @@ -155,30 +192,7 @@ class ezcGraphAxisRotatedLabelRenderer extends ezcGraphAxisLabelRenderer list( $xSpace, $ySpace ) = $this->getAxisSpace( $renderer, $boundings, $axis, $innerBoundings, $gridBoundings ); // Determine optimal angle if none specified - if ( $this->angle === null ) - { - $minimumStepWidth = null; - foreach ( $steps as $nr => $step ) - { - if ( ( $minimumStepWidth === null ) || - ( $step->width < $minimumStepWidth ) ) - { - $minimumStepWidth = $step->width; - } - } - - $width = abs( - $axisBoundings->width * $minimumStepWidth * $this->direction->x + - $axisBoundings->height * $minimumStepWidth * $this->direction->y - ); - $height = abs( - $ySpace * $this->direction->x + - $xSpace * $this->direction->y - ); - - $length = sqrt( pow( $width, 2 ) + pow( $height, 2 ) ); - $this->angle = rad2deg( acos( $height / $length ) ); - } + $this->determineAngle( $steps, $xSpace, $ySpace, $axisBoundings ); // Determine additional required axis space by boxes $firstStep = reset( $steps ); @@ -369,11 +383,11 @@ class ezcGraphAxisRotatedLabelRenderer extends ezcGraphAxisLabelRenderer ): $labelBoundings = new ezcGraphBoundings( $position->x, - $position->y + $labelSize, - $position->x + abs( $labelLength ) - $lengthReducement, - $position->y + $position->y, + $position->x - abs( $labelLength ) + $lengthReducement, + $position->y + $labelSize ); - $labelAlignement = ezcGraph::LEFT | ezcGraph::BOTTOM; + $labelAlignement = ezcGraph::LEFT | ezcGraph::TOP; $labelRotation = $degTextAngle; break; } @@ -424,9 +438,11 @@ class ezcGraphAxisRotatedLabelRenderer extends ezcGraphAxisLabelRenderer { return new ezcGraphCoordinate( $coordinate->x * abs( $this->direction->y ) + - ( $coordinate->x * ( 1 - abs( $this->offset ) ) + max( 0, $this->offset ) ) * abs( $this->direction->x ), + ( $coordinate->x * ( 1 - abs( $this->offset ) ) * abs( $this->direction->x ) ) + + ( abs( $this->offset ) * abs( $this->direction->x ) ), $coordinate->y * abs( $this->direction->x ) + - ( $coordinate->y * ( 1 - abs( $this->offset ) ) + max( 0, $this->offset ) ) * abs( $this->direction->y ) + ( $coordinate->y * ( 1 - abs( $this->offset ) ) * abs( $this->direction->y ) ) + + ( abs( $this->offset ) * abs( $this->direction->y ) ) ); } } |