summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-12-15 10:03:14 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-12-15 10:03:14 +0000
commit608e7e2984878c368127f41bb722c416e533c646 (patch)
treee21798ee9144799d4943328419dc965ca95b0624
parent2de1a60acb861441417cb3a228091260b5cf0faa (diff)
downloadzetacomponents-graph-608e7e2984878c368127f41bb722c416e533c646.zip
zetacomponents-graph-608e7e2984878c368127f41bb722c416e533c646.tar.gz
- Fixed: Bug #9827 (auto scaling on numeric axes inconsistent)
-rw-r--r--ChangeLog2
-rw-r--r--src/axis/labeled.php20
-rw-r--r--src/axis/numeric.php12
-rw-r--r--tests/numeric_axis_test.php64
4 files changed, 93 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index ca2b6c8..fdcd474 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,8 @@
absoluteTreshHold to absoluteThreshold
- Added feature #9647: Add render to output method
+- Fixed issue #9827: Use majorStep size for min/max estimating on numeric axis
+ with only one value
- Fixed issue #9823: Failing tests with PHP 5.1, because of different
parameter handling in imagepng, and (string) not calling __toString method
- Fixed issue #9795: Interferring bars, when bars count is higher then major
diff --git a/src/axis/labeled.php b/src/axis/labeled.php
index 5fe5c1f..4463c91 100644
--- a/src/axis/labeled.php
+++ b/src/axis/labeled.php
@@ -176,10 +176,24 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis
{
case ezcGraph::LEFT:
case ezcGraph::TOP:
- return (float) $key / ( count ( $this->labels ) - 1 );
+ if ( count( $this->labels ) > 1 )
+ {
+ return (float) $key / ( count ( $this->labels ) - 1 );
+ }
+ else
+ {
+ return 0;
+ }
case ezcGraph::BOTTOM:
case ezcGraph::RIGHT:
- return (float) 1 - $key / ( count ( $this->labels ) - 1 );
+ if ( count( $this->labels ) > 1 )
+ {
+ return (float) 1 - $key / ( count ( $this->labels ) - 1 );
+ }
+ else
+ {
+ return 1;
+ }
}
}
}
@@ -201,7 +215,7 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis
*/
public function getMajorStepCount()
{
- return count( $this->displayedLabels ) - 1;
+ return max( count( $this->displayedLabels ) - 1, 1 );
}
/**
diff --git a/src/axis/numeric.php b/src/axis/numeric.php
index 70fc801..b596774 100644
--- a/src/axis/numeric.php
+++ b/src/axis/numeric.php
@@ -235,8 +235,16 @@ class ezcGraphChartElementNumericAxis extends ezcGraphChartElementAxis
}
else
{
- $this->properties['minValue'] -= ( $this->properties['minValue'] * .1 );
- $this->properties['maxValue'] += ( $this->properties['maxValue'] * .1 );
+ if ( $this->properties['majorStep'] !== null )
+ {
+ $this->properties['minValue'] -= $this->properties['majorStep'];
+ $this->properties['maxValue'] += $this->properties['majorStep'];
+ }
+ else
+ {
+ $this->properties['minValue'] -= ( $this->properties['minValue'] * .1 );
+ $this->properties['maxValue'] += ( $this->properties['maxValue'] * .1 );
+ }
}
}
diff --git a/tests/numeric_axis_test.php b/tests/numeric_axis_test.php
index 5de1af9..31d5236 100644
--- a/tests/numeric_axis_test.php
+++ b/tests/numeric_axis_test.php
@@ -378,6 +378,70 @@ class ezcGraphNumericAxisTest extends ezcTestCase
);
}
+ public function testMixedAutomagicAndManualScaling5()
+ {
+ $chart = new ezcGraphLineChart();
+ $chart->data['sample'] = new ezcGraphArrayDataSet( array( 4.5 ) );
+ $chart->yAxis->majorStep = .5;
+ $chart->render( 500, 200 );
+
+ $this->assertEquals(
+ 4.,
+ $chart->yAxis->min,
+ 'As value for: min; '
+ );
+
+ $this->assertEquals(
+ 5.,
+ $chart->yAxis->max,
+ 'As value for: max; '
+ );
+
+ $this->assertEquals(
+ .5,
+ $chart->yAxis->majorStep,
+ 'As value for: majorStep; '
+ );
+
+ $this->assertEquals(
+ .1,
+ $chart->yAxis->minorStep,
+ 'As value for: minorStep; '
+ );
+ }
+
+ public function testMixedAutomagicAndManualScaling6()
+ {
+ $chart = new ezcGraphLineChart();
+ $chart->data['sample'] = new ezcGraphArrayDataSet( array( 113.5 ) );
+ $chart->yAxis->majorStep = .5;
+ $chart->render( 500, 200 );
+
+ $this->assertEquals(
+ 113.,
+ $chart->yAxis->min,
+ 'As value for: min; '
+ );
+
+ $this->assertEquals(
+ 114.,
+ $chart->yAxis->max,
+ 'As value for: max; '
+ );
+
+ $this->assertEquals(
+ .5,
+ $chart->yAxis->majorStep,
+ 'As value for: majorStep; '
+ );
+
+ $this->assertEquals(
+ .1,
+ $chart->yAxis->minorStep,
+ 'As value for: minorStep; '
+ );
+ }
+
public function testPositionLeft()
{
$chart = new ezcGraphLineChart();
OpenPOWER on IntegriCloud