Author: kn
Date: Wed Aug 1 10:56:03 2007
New Revision: 5791
Log:
- Fixed bug #11107: Floating point inaccuracies caused missing grid in line
chart
Added:
trunk/Graph/tests/data/compare/ezcGraphRenderer2dTest_testBug11107_MissingGridWithBottomLegend.svg
(with props)
Modified:
trunk/Graph/ChangeLog
trunk/Graph/src/interfaces/axis_label_renderer.php
trunk/Graph/tests/data/compare/ezcGraphRadarChartAxisTest_testBoxedMultipleDirections.svg
trunk/Graph/tests/data/compare/ezcGraphRadarChartAxisTest_testCenteredMultipleDirections.svg
trunk/Graph/tests/data/compare/ezcGraphRadarChartAxisTest_testExactMultipleDirections.svg
trunk/Graph/tests/data/compare/ezcGraphRenderer2dTest_testRenderBarChartWithMoreBarsThenMajorSteps.svg
trunk/Graph/tests/renderer_2d_test.php
Modified: trunk/Graph/ChangeLog
==============================================================================
--- trunk/Graph/ChangeLog [iso-8859-1] (original)
+++ trunk/Graph/ChangeLog [iso-8859-1] Wed Aug 1 10:56:03 2007
@@ -1,3 +1,9 @@
+1.2beta1 - [date]
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Fixed bug #11107: Floating point inaccuracies caused missing grid in line
+ chart
+
1.1 - Monday 02 July 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Modified: trunk/Graph/src/interfaces/axis_label_renderer.php
==============================================================================
--- trunk/Graph/src/interfaces/axis_label_renderer.php [iso-8859-1] (original)
+++ trunk/Graph/src/interfaces/axis_label_renderer.php [iso-8859-1] Wed Aug 1
10:56:03 2007
@@ -199,10 +199,10 @@
public function determineLineCuttingPoint( ezcGraphCoordinate $aStart,
ezcGraphCoordinate $aDir, ezcGraphCoordinate $bStart, ezcGraphCoordinate $bDir )
{
// Check if lines are parallel
- if ( ( ( $aDir->x == 0 ) && ( $bDir->x == 0 ) ) ||
- ( ( $aDir->y == 0 ) && ( $bDir->y == 0 ) ) ||
- ( ( $aDir->x * $bDir->x * $aDir->y * $bDir->y != 0 ) &&
- ( ( $aDir->x / $aDir->y ) == ( $bDir->x / $bDir->y ) )
+ if ( ( ( abs( $aDir->x ) < .000001 ) && ( abs( $bDir->x ) < .000001 )
) ||
+ ( ( abs( $aDir->y ) < .000001 ) && ( abs( $bDir->y ) < .000001 )
) ||
+ ( ( abs( $aDir->x * $bDir->x * $aDir->y * $bDir->y ) > .000001 )
&&
+ ( abs( ( $aDir->x / $aDir->y ) - ( $bDir->x / $bDir->y ) ) <
.000001 )
)
)
{
@@ -211,26 +211,26 @@
// Use ? : to prevent division by zero
$denominator =
- ( $aDir->y != 0 ? $bDir->y / $aDir->y : 0 ) -
- ( $aDir->x != 0 ? $bDir->x / $aDir->x : 0 );
+ ( abs( $aDir->y ) > .000001 ? $bDir->y / $aDir->y : .0 ) -
+ ( abs( $aDir->x ) > .000001 ? $bDir->x / $aDir->x : .0 );
// Solve equatation
- if ( $denominator == 0 )
+ if ( abs( $denominator ) < .000001 )
{
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 )
- );
+ ( abs( $aDir->y ) > .000001 ? $bStart->y / $aDir->y : .0 ) -
+ ( abs( $aDir->y ) > .000001 ? $aStart->y / $aDir->y : .0 ) -
+ ( abs( $aDir->x ) > .000001 ? $bStart->x / $aDir->x : .0 ) +
+ ( abs( $aDir->x ) > .000001 ? $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 )
+ ( abs( $aDir->y ) > .000001 ? $bStart->y / $aDir->y : .0 ) -
+ ( abs( $aDir->y ) > .000001 ? $aStart->y / $aDir->y : .0 ) -
+ ( abs( $aDir->x ) > .000001 ? $bStart->x / $aDir->x : .0 ) +
+ ( abs( $aDir->x ) > .000001 ? $aStart->x / $aDir->x : .0 )
) / $denominator;
}
}
@@ -345,11 +345,11 @@
),
) as $boundingLine )
{
- // Test for cutting points with bounding lines, where cutting
+ // Test for cutting points with bounding lines, where cutting
// position is between 0 and 1, which means, that the line is hit
// on the bounding box rectangle. Use these points as a start and
- // ending point for the grid lines. There should *always* be two
- // points returned.
+ // ending point for the grid lines. There should *always* be
+ // exactly two points returned.
$cuttingPosition = $this->determineLineCuttingPoint(
$boundingLine['start'],
$boundingLine['dir'],
@@ -357,10 +357,16 @@
$gridDirection
);
+ $cuttingPoint = new ezcGraphCoordinate(
+ $boundingLine['start']->x + $cuttingPosition *
$boundingLine['dir']->x,
+ $boundingLine['start']->y + $cuttingPosition *
$boundingLine['dir']->y
+ );
+
if ( $cuttingPosition === false )
{
continue;
}
+
// Round to prevent minor float incorectnesses
$cuttingPosition = abs( round( $cuttingPosition, 2 ) );
@@ -376,6 +382,7 @@
if ( count( $cuttingPoints ) < 2 )
{
+ // This should not happpen
return false;
}
Modified:
trunk/Graph/tests/data/compare/ezcGraphRadarChartAxisTest_testBoxedMultipleDirections.svg
==============================================================================
Binary files - no diff available.
Modified:
trunk/Graph/tests/data/compare/ezcGraphRadarChartAxisTest_testCenteredMultipleDirections.svg
==============================================================================
Binary files - no diff available.
Modified:
trunk/Graph/tests/data/compare/ezcGraphRadarChartAxisTest_testExactMultipleDirections.svg
==============================================================================
Binary files - no diff available.
Added:
trunk/Graph/tests/data/compare/ezcGraphRenderer2dTest_testBug11107_MissingGridWithBottomLegend.svg
==============================================================================
Binary file - no diff available.
Propchange:
trunk/Graph/tests/data/compare/ezcGraphRenderer2dTest_testBug11107_MissingGridWithBottomLegend.svg
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
trunk/Graph/tests/data/compare/ezcGraphRenderer2dTest_testBug11107_MissingGridWithBottomLegend.svg
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified:
trunk/Graph/tests/data/compare/ezcGraphRenderer2dTest_testRenderBarChartWithMoreBarsThenMajorSteps.svg
==============================================================================
Binary files - no diff available.
Modified: trunk/Graph/tests/renderer_2d_test.php
==============================================================================
--- trunk/Graph/tests/renderer_2d_test.php [iso-8859-1] (original)
+++ trunk/Graph/tests/renderer_2d_test.php [iso-8859-1] Wed Aug 1 10:56:03 2007
@@ -2047,6 +2047,26 @@
);
}
+ public function testBug11107_MissingGridWithBottomLegend()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+ $graph = new ezcGraphLineChart();
+ $graph->palette = new ezcGraphPaletteBlack();
+ $graph->legend->position = ezcGraph::BOTTOM;
+
+ $graph->data['sample'] = new ezcGraphArrayDataSet(
+ array( 1, 4, 6, 8, 2 )
+ );
+
+ $graph->render( 560, 250, $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ .
'.svg'
+ );
+ }
+
public function testRendererOptionsPropertyMaxLabelHeight()
{
$options = new ezcGraphRendererOptions();
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components