Author: Kore Nordmann Date: 2007-01-03 13:48:08 +0100 (Wed, 03 Jan 2007) New Revision: 4457
Log: - Fixed issue #9916: ArrayDataSet can handle Iterator was not documented - Added and test additional typecheck Added: trunk/Graph/src/exceptions/invalid_data_source.php Modified: trunk/Graph/ChangeLog trunk/Graph/src/datasets/array.php trunk/Graph/src/graph_autoload.php trunk/Graph/tests/dataset_test.php Modified: trunk/Graph/ChangeLog =================================================================== --- trunk/Graph/ChangeLog 2007-01-03 11:28:16 UTC (rev 4456) +++ trunk/Graph/ChangeLog 2007-01-03 12:48:08 UTC (rev 4457) @@ -2,6 +2,7 @@ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - Added feature #9402: Numeric datasets +- Fixed issue #9916: Not documented: ArrayDataSet also can use Iterators - Fixed issue #9926: Float values with date axis result in date parsing exception Modified: trunk/Graph/src/datasets/array.php =================================================================== --- trunk/Graph/src/datasets/array.php 2007-01-03 11:28:16 UTC (rev 4456) +++ trunk/Graph/src/datasets/array.php 2007-01-03 12:48:08 UTC (rev 4457) @@ -18,9 +18,8 @@ /** * Constructor * - * @param array $options Default option array + * @param mixed $options Array or Iterator containing the data * @return void - * @ignore */ public function __construct( $data ) { @@ -29,14 +28,22 @@ } /** - * setData + * setData + * + * Can handle data provided through an array or iterator. * - * @param array $data + * @param mixed $data * @access public * @return void */ protected function createFromArray( $data = array() ) { + if ( !is_array( $data ) && + !( $data instanceof Iterator ) ) + { + throw new ezcGraphInvalidArrayDataSourceException( $data ); + } + foreach ( $data as $key => $value ) { $this->data[$key] = $value; Added: trunk/Graph/src/exceptions/invalid_data_source.php =================================================================== --- trunk/Graph/src/exceptions/invalid_data_source.php 2007-01-03 11:28:16 UTC (rev 4456) +++ trunk/Graph/src/exceptions/invalid_data_source.php 2007-01-03 12:48:08 UTC (rev 4457) @@ -0,0 +1,26 @@ +<?php +/** + * File containing the ezcGraphInvalidArrayDataSourceException class + * + * @package Graph + * @version //autogen// + * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ +/** + * Exception thrown when an invalid data source is provided for an array + * data set. + * + * @package Graph + * @version //autogen// + */ +class ezcGraphInvalidArrayDataSourceException extends ezcGraphException +{ + public function __construct( $value ) + { + $type = gettype( $value ); + parent::__construct( "The array dataset can only use arrays and iterators, but you supplied '{$type}'." ); + } +} + +?> Property changes on: trunk/Graph/src/exceptions/invalid_data_source.php ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/Graph/src/graph_autoload.php =================================================================== --- trunk/Graph/src/graph_autoload.php 2007-01-03 11:28:16 UTC (rev 4456) +++ trunk/Graph/src/graph_autoload.php 2007-01-03 12:48:08 UTC (rev 4457) @@ -85,6 +85,7 @@ 'ezcGraphDataSet' => 'Graph/datasets/base.php', 'ezcGraphArrayDataSet' => 'Graph/datasets/array.php', + 'ezcGraphInvalidArrayDataSourceException' => 'Graph/exceptions/invalid_data_source.php', 'ezcGraphNumericDataSet' => 'Graph/datasets/numeric.php', 'ezcGraphDataSetAveragePolynom' => 'Graph/datasets/average.php', 'ezcGraphDatasetAverageInvalidKeysException' => 'Graph/exceptions/invalid_keys.php', Modified: trunk/Graph/tests/dataset_test.php =================================================================== --- trunk/Graph/tests/dataset_test.php 2007-01-03 11:28:16 UTC (rev 4456) +++ trunk/Graph/tests/dataset_test.php 2007-01-03 12:48:08 UTC (rev 4457) @@ -255,16 +255,36 @@ ); } - public function testDataSetSetSingleData() + public function testIteratorToDataSet() { $chart = new ezcGraphPieChart(); - $chart->data['income'] = new ezcGraphArrayDataSet( array( 2000 => 2345.2, 2456.3, 2567.4 ) ); + $chart->data['income'] = new ezcGraphArrayDataSet( new ArrayIterator( array( 2000 => 2345.2, 2456.3, 2567.4 ) ) ); $chart->data['income'][2005] = 234.21; $this->assertSame( 234.21, $chart->data['income'][2005] ); + + $this->assertSame( + 2456.3, + $chart->data['income'][2001] + ); } + + public function testDataSetInvalidDataSource() + { + $chart = new ezcGraphPieChart(); + try + { + $chart->data['income'] = new ezcGraphArrayDataSet( $chart ); + } + catch ( ezcGraphInvalidArrayDataSourceException $e ) + { + return true; + } + + $this->fail( 'Expected ezcGraphInvalidArrayDataSourceException.' ); + } } ?> -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components