Author: Kore Nordmann Date: 2007-03-05 12:03:43 +0100 (Mon, 05 Mar 2007) New Revision: 4711
Log: - Implemented #10375: Manually reduce or increase the label count on labeled axis Added: trunk/Graph/tests/data/compare/ezcGraphLabeledAxisTest_testRenderManualLabelCount1.svg trunk/Graph/tests/data/compare/ezcGraphLabeledAxisTest_testRenderManualLabelCount2.svg trunk/Graph/tests/data/compare/ezcGraphLabeledAxisTest_testRenderManualLabelCount3.svg Modified: trunk/Graph/ChangeLog trunk/Graph/src/axis/labeled.php trunk/Graph/tests/labeled_axis_test.php Modified: trunk/Graph/ChangeLog =================================================================== --- trunk/Graph/ChangeLog 2007-03-05 10:46:11 UTC (rev 4710) +++ trunk/Graph/ChangeLog 2007-03-05 11:03:43 UTC (rev 4711) @@ -19,6 +19,8 @@ - Fixed issue #10246: sprintf output modification in PHP 5.2.1 - Fixed issue #10275: Low label count on labeled axis, when having (prime number > 10) + 1 labels +- Added feature #10375: Manually reduce or increase the label count on + labeled axis 1.0 - Monday 18 December 2006 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Modified: trunk/Graph/src/axis/labeled.php =================================================================== --- trunk/Graph/src/axis/labeled.php 2007-03-05 10:46:11 UTC (rev 4710) +++ trunk/Graph/src/axis/labeled.php 2007-03-05 11:03:43 UTC (rev 4711) @@ -11,6 +11,9 @@ * Class to represent a labeled axis. Values on the x axis are considered as * strings and used in the given order. * + * @property float $labelCount + * Define count of displayed labels on the axis + * * @package Graph * @mainclass */ @@ -53,12 +56,45 @@ */ public function __construct( array $options = array() ) { + $this->properties['labelCount'] = null; + $this->axisLabelRenderer = new ezcGraphAxisCenteredLabelRenderer(); parent::__construct( $options ); } /** + * __set + * + * @param mixed $propertyName + * @param mixed $propertyValue + * @throws ezcBaseValueException + * If a submitted parameter was out of range or type. + * @throws ezcBasePropertyNotFoundException + * If a the value for the property options is not an instance of + * @return void + * @ignore + */ + public function __set( $propertyName, $propertyValue ) + { + switch ( $propertyName ) + { + case 'labelCount': + if ( !is_numeric( $propertyValue ) || + ( $propertyValue <= 1 ) ) + { + throw new ezcBaseValueException( $propertyName, $propertyValue, 'int > 1' ); + } + + $this->properties['labelCount'] = (int) $propertyValue; + break; + default: + parent::__set( $propertyName, $propertyValue ); + break; + } + } + + /** * Increase the keys of all elements in the array up from the start key, to * insert an additional element at the correct position. * @@ -138,49 +174,56 @@ return true; } - if ( $labelCount <= self::MAX_LABEL_COUNT ) + if ( $this->properties['labelCount'] === null ) { - $stepSize = 1 / $labelCount; - - foreach ( $this->labels as $nr => $label ) + if ( $labelCount <= self::MAX_LABEL_COUNT ) { - $this->steps[] = new ezcGraphAxisStep( - $stepSize * $nr, - $stepSize, - $label, - array(), - $nr === 0, - $nr === $labelCount - ); - } + $stepSize = 1 / $labelCount; - // @TODO: This line is deprecated and only build for - // deprecated getLabel() - $this->displayedLabels = $this->labels; + foreach ( $this->labels as $nr => $label ) + { + $this->steps[] = new ezcGraphAxisStep( + $stepSize * $nr, + $stepSize, + $label, + array(), + $nr === 0, + $nr === $labelCount + ); + } - return true; - } + // @TODO: This line is deprecated and only build for + // deprecated getLabel() + $this->displayedLabels = $this->labels; - for ( $div = self::MAX_LABEL_COUNT; $div > 1; --$div ) - { - if ( ( $labelCount % $div ) === 0 ) + return true; + } + + for ( $div = self::MAX_LABEL_COUNT; $div > 1; --$div ) { - // @TODO: This part is deprecated and only build for - // deprecated getLabel() - $step = $labelCount / $div; + if ( ( $labelCount % $div ) === 0 ) + { + // @TODO: This part is deprecated and only build for + // deprecated getLabel() + $step = $labelCount / $div; - foreach ( $this->labels as $nr => $label ) - { - if ( ( $nr % $step ) === 0 ) + foreach ( $this->labels as $nr => $label ) { - $this->displayedLabels[] = $label; + if ( ( $nr % $step ) === 0 ) + { + $this->displayedLabels[] = $label; + } } + // End of deprecated part + + break; } - // End of deprecated part - - break; } } + else + { + $div = false; + } // Build up step array if ( $div > 2 ) @@ -215,7 +258,15 @@ } else { - $floatStep = $labelCount / ( self::MAX_LABEL_COUNT - 1 ); + if ( $this->properties['labelCount'] === null ) + { + $floatStep = $labelCount / ( self::MAX_LABEL_COUNT - 1 ); + } + else + { + $floatStep = $labelCount / min( $labelCount, $this->properties['labelCount'] - 1 ); + } + $position = 0; $minorStepSize = 1 / $labelCount; Added: trunk/Graph/tests/data/compare/ezcGraphLabeledAxisTest_testRenderManualLabelCount1.svg =================================================================== (Binary files differ) Property changes on: trunk/Graph/tests/data/compare/ezcGraphLabeledAxisTest_testRenderManualLabelCount1.svg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Name: svn:eol-style + native Added: trunk/Graph/tests/data/compare/ezcGraphLabeledAxisTest_testRenderManualLabelCount2.svg =================================================================== (Binary files differ) Property changes on: trunk/Graph/tests/data/compare/ezcGraphLabeledAxisTest_testRenderManualLabelCount2.svg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Name: svn:eol-style + native Added: trunk/Graph/tests/data/compare/ezcGraphLabeledAxisTest_testRenderManualLabelCount3.svg =================================================================== (Binary files differ) Property changes on: trunk/Graph/tests/data/compare/ezcGraphLabeledAxisTest_testRenderManualLabelCount3.svg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Name: svn:eol-style + native Modified: trunk/Graph/tests/labeled_axis_test.php =================================================================== --- trunk/Graph/tests/labeled_axis_test.php 2007-03-05 10:46:11 UTC (rev 4710) +++ trunk/Graph/tests/labeled_axis_test.php 2007-03-05 11:03:43 UTC (rev 4711) @@ -462,6 +462,119 @@ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } + + public function testChartElementNumericAxisPropertyLabelCount() + { + $options = new ezcGraphChartElementLabeledAxis(); + + $this->assertSame( + null, + $options->labelCount, + 'Wrong default value for property labelCount in class ezcGraphChartElementNumericAxis' + ); + + $options->labelCount = 10; + $this->assertSame( + 10, + $options->labelCount, + 'Setting property value did not work for property labelCount in class ezcGraphChartElementNumericAxis' + ); + + try + { + $options->labelCount = 1; + } + catch ( ezcBaseValueException $e ) + { + return true; + } + + $this->fail( 'Expected ezcBaseValueException.' ); + } + + public function testRenderManualLabelCount1() + { + $filename = $this->tempDir . __FUNCTION__ . '.svg'; + + $labelCount = 4; + + // Make this reproducible + mt_srand( 2 ); + + for ( $i = 0; $i < $labelCount; ++$i ) + { + $data[(string) ( 2000 + $i )] = mt_rand( 500, 2000 ); + } + + $chart = new ezcGraphLineChart(); + $chart->data['sample'] = new ezcGraphArrayDataSet( $data ); + + // Set manual label count + $chart->xAxis->labelCount = 3; + + $chart->render( 500, 200, $filename ); + + $this->compare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' + ); + } + + public function testRenderManualLabelCount2() + { + $filename = $this->tempDir . __FUNCTION__ . '.svg'; + + $labelCount = 4; + + // Make this reproducible + mt_srand( 2 ); + + for ( $i = 0; $i < $labelCount; ++$i ) + { + $data[(string) ( 2000 + $i )] = mt_rand( 500, 2000 ); + } + + $chart = new ezcGraphLineChart(); + $chart->data['sample'] = new ezcGraphArrayDataSet( $data ); + + // Set manual label count + $chart->xAxis->labelCount = 10; + + $chart->render( 500, 200, $filename ); + + $this->compare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' + ); + } + + public function testRenderManualLabelCount3() + { + $filename = $this->tempDir . __FUNCTION__ . '.svg'; + + $labelCount = 35; + + // Make this reproducible + mt_srand( 2 ); + + for ( $i = 0; $i < $labelCount; ++$i ) + { + $data[(string) ( 2000 + $i )] = mt_rand( 500, 2000 ); + } + + $chart = new ezcGraphLineChart(); + $chart->data['sample'] = new ezcGraphArrayDataSet( $data ); + + // Set manual label count + $chart->xAxis->labelCount = 7; + + $chart->render( 500, 200, $filename ); + + $this->compare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' + ); + } } ?> -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components