diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2009-01-07 11:18:16 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2009-01-07 11:18:16 +0000 |
commit | b55f6d4f3303dc7c123939207f28297906c92e88 (patch) | |
tree | 162bd2470ae3150dbcec65cd17cc53cc93304150 /src/interfaces | |
parent | 20df6e81b14f382ee73c8968ac587afb6be58fb7 (diff) | |
download | zetacomponents-graph-b55f6d4f3303dc7c123939207f28297906c92e88.zip zetacomponents-graph-b55f6d4f3303dc7c123939207f28297906c92e88.tar.gz |
- Resolved task #14219: Refactor grid drawing to be less susceptible to
floating point inaccuracies
# Handle orthogonal axis as a special case, which fixes this for the far most
# common case.
# Also fixes slight grid irregularities which occurred sometimes.
Diffstat (limited to 'src/interfaces')
-rw-r--r-- | src/interfaces/axis_label_renderer.php | 83 |
1 files changed, 78 insertions, 5 deletions
diff --git a/src/interfaces/axis_label_renderer.php b/src/interfaces/axis_label_renderer.php index 9a5f064..fb6a644 100644 --- a/src/interfaces/axis_label_renderer.php +++ b/src/interfaces/axis_label_renderer.php @@ -306,9 +306,9 @@ abstract class ezcGraphAxisLabelRenderer extends ezcBaseOptions } /** - * Draw grid + * Draw non-rectangular grid lines grid * - * Draws a grid line at the current position + * Draws a grid line at the current position, for non-rectangular axis. * * @param ezcGraphRenderer $renderer Renderer to draw the grid with * @param ezcGraphBoundings $boundings Boundings of axis @@ -317,7 +317,7 @@ abstract class ezcGraphAxisLabelRenderer extends ezcBaseOptions * @param ezcGraphColor $color Color of axis * @return void */ - protected function drawGrid( ezcGraphRenderer $renderer, ezcGraphBoundings $boundings, ezcGraphCoordinate $position, ezcGraphCoordinate $direction, ezcGraphColor $color ) + protected function drawNonRectangularGrid( ezcGraphRenderer $renderer, ezcGraphBoundings $boundings, ezcGraphCoordinate $position, ezcGraphCoordinate $direction, ezcGraphColor $color ) { // Direction of grid line is direction of axis turned right by 90 // degrees @@ -363,8 +363,7 @@ abstract class ezcGraphAxisLabelRenderer extends ezcBaseOptions continue; } - // Round to prevent minor float incorectnesses - $cuttingPosition = abs( round( $cuttingPosition, 2 ) ); + $cuttingPosition = abs( $cuttingPosition ); if ( ( $cuttingPosition >= 0 ) && ( $cuttingPosition <= 1 ) ) @@ -391,6 +390,80 @@ abstract class ezcGraphAxisLabelRenderer extends ezcBaseOptions } /** + * Draw rectangular grid + * + * Draws a grid line at the current position for rectangular directed axis. + * + * Method special for rectangularly directed axis to minimize the floating + * point calculation inaccuracies. Those are not necessary for rectangles, + * while for non-rectangular directed axis. + * + * @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 drawRectangularGrid( ezcGraphRenderer $renderer, ezcGraphBoundings $boundings, ezcGraphCoordinate $position, ezcGraphCoordinate $direction, ezcGraphColor $color ) + { + if ( abs( $direction->x ) < .00001 ) + { + $renderer->drawGridLine( + new ezcGraphCoordinate( + $boundings->x0, + $position->y + ), + new ezcGraphCoordinate( + $boundings->x1, + $position->y + ), + $color + ); + } + else + { + $renderer->drawGridLine( + new ezcGraphCoordinate( + $position->x, + $boundings->y0 + ), + new ezcGraphCoordinate( + $position->x, + $boundings->y1 + ), + $color + ); + } + } + + /** + * 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( ezcGraphRenderer $renderer, ezcGraphBoundings $boundings, ezcGraphCoordinate $position, ezcGraphCoordinate $direction, ezcGraphColor $color ) + { + // Check if the axis direction is rectangular + if ( ( abs( $direction->x ) < .00001 ) || + ( abs( $direction->y ) < .00001 ) ) + { + return $this->drawRectangularGrid( $renderer, $boundings, $position, $direction, $color ); + } + else + { + return $this->drawNonRectangularGrid( $renderer, $boundings, $position, $direction, $color ); + } + } + + /** * Modify chart boundings * * Optionally modify boundings of chart data |