diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2006-09-20 09:59:56 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2006-09-20 09:59:56 +0000 |
commit | da06e1ce094169abdcd0ab4df70180fc1a4988cd (patch) | |
tree | 44fc4abcc8a8312d2ea01c4c0c9ae1415467e760 | |
parent | 593169b297351ac5f2a40b800a308eed4fd99955 (diff) | |
download | zetacomponents-graph-da06e1ce094169abdcd0ab4df70180fc1a4988cd.zip zetacomponents-graph-da06e1ce094169abdcd0ab4df70180fc1a4988cd.tar.gz |
- Made palette properties writeable
- Fixed wrong parameters
-rw-r--r-- | src/interfaces/element.php | 2 | ||||
-rw-r--r-- | src/interfaces/palette.php | 92 | ||||
-rw-r--r-- | tests/palette_test.php | 90 |
3 files changed, 163 insertions, 21 deletions
diff --git a/src/interfaces/element.php b/src/interfaces/element.php index d27b3c9..c05090b 100644 --- a/src/interfaces/element.php +++ b/src/interfaces/element.php @@ -137,7 +137,7 @@ abstract class ezcGraphChartElement extends ezcBaseOptions } else { - throw new ezcBaseValueException( $propertyValue, 'ezcGraphFontOptions' ); + throw new ezcBaseValueException( $propertyName, $propertyValue, 'ezcGraphFontOptions' ); } break; case 'position': diff --git a/src/interfaces/palette.php b/src/interfaces/palette.php index 41bbe6b..1cab18b 100644 --- a/src/interfaces/palette.php +++ b/src/interfaces/palette.php @@ -160,19 +160,22 @@ abstract class ezcGraphPalette * * @param string $propertyName Name of property * @return mixed + * @ignore */ public function __get( $propertyName ) { switch ( $propertyName ) { case 'axisColor': - return $this->checkColor( $this->axisColor ); - case 'majorGridColor': - return $this->checkColor( $this->majorGridColor ); case 'minorGridColor': - return $this->checkColor( $this->minorGridColor ); - + case 'fontColor': + case 'chartBackground': + case 'chartBorderColor': + case 'elementBackground': + case 'elementBorderColor': + return ( $this->$propertyName = $this->checkColor( $this->$propertyName ) ); + case 'dataSetColor': $this->colorIndex = ( ( $this->colorIndex + 1 ) % count( $this->dataSetColor ) ); return $this->checkColor( $this->dataSetColor[ $this->colorIndex ] ); @@ -180,30 +183,79 @@ abstract class ezcGraphPalette $this->symbolIndex = ( ( $this->symbolIndex + 1 ) % count( $this->dataSetSymbol ) ); return $this->dataSetSymbol[ $this->symbolIndex ]; - case 'fontColor': - return $this->checkColor( $this->fontColor ); case 'fontName': - return $this->fontName; + case 'chartBorderWidth': + case 'elementBorderWidth': + case 'padding': + case 'margin': + return $this->$propertyName; + + default: + throw new ezcBasePropertyNotFoundException( $propertyName ); + } + } + /** + * __set + * + * @param mixed $propertyName Property name + * @param mixed $propertyValue Property value + * @access public + * @ignore + */ + public function __set( $propertyName, $propertyValue ) + { + switch ( $propertyName ) + { + case 'axisColor': + case 'majorGridColor': + case 'minorGridColor': + case 'fontColor': case 'chartBackground': - return $this->checkColor( $this->chartBackground ); case 'chartBorderColor': - return $this->checkColor( $this->chartBorderColor ); - case 'chartBorderWidth': - return $this->chartBorderWidth; - case 'elementBackground': - return $this->checkColor( $this->elementBackground ); case 'elementBorderColor': - return $this->checkColor( $this->elementBorderColor ); - case 'elementBorderWidth': - return $this->elementBorderWidth; + $this->$propertyName = ezcGraphColor::create( $propertyValue ); + break; + case 'dataSetColor': + if ( !is_array( $propertyValue ) ) + { + throw new ezcBaseValueException( $propertyName, $propertyValue, 'array( ezcGraphColor )' ); + } + + $this->dataSetColor = array(); + foreach ( $propertyValue as $value ) + { + $this->dataSetColor[] = ezcGraphColor::create( $value ); + } + $this->colorIndex = -1; + break; + case 'dataSetSymbol': + if ( !is_array( $propertyValue ) ) + { + throw new ezcBaseValueException( $propertyName, $propertyValue, 'array( (int) ezcGraph::SYMBOL_TYPE )' ); + } + + $this->dataSetSymbol = array(); + foreach ( $propertyValue as $value ) + { + $this->dataSetSymbol[] = (int) $value; + } + $this->symbolIndex = -1; + break; + + case 'fontName': + $this->$propertyName = (string) $propertyValue; + break; + + case 'chartBorderWidth': + case 'elementBorderWidth': case 'padding': - return $this->padding; case 'margin': - return $this->margin; - + $this->$propertyName = max( 0, (int) $propertyValue ); + break; + default: throw new ezcBasePropertyNotFoundException( $propertyName ); } diff --git a/tests/palette_test.php b/tests/palette_test.php index bb57b0e..892d683 100644 --- a/tests/palette_test.php +++ b/tests/palette_test.php @@ -337,6 +337,96 @@ class ezcGraphPaletteTest extends ezcTestCase 'Chart background not set from pallet.' ); } + + public function testModifyPaletteColorProperty() + { + $palette = new ezcGraphPaletteTango(); + + $palette->axisColor = '#FFFFFF'; + $palette->majorGridColor = array( 255, 255, 255, 255 ); + $palette->minorGridColor = ezcGraphColor::fromHex( '#00000000' ); + + $this->assertEquals( + $palette->axisColor, + ezcGraphColor::fromHex( '#FFFFFF' ) + ); + + try + { + $palette->axisColor = false; + } + catch ( ezcGraphUnknownColorDefinitionException $e ) + { + return true; + } + + $this->fail( 'expected ezcGraphUnknownColorDefinitionException.' ); + } + + public function testModifyPaletteIntProperty() + { + $palette = new ezcGraphPaletteTango(); + + $palette->chartBorderWidth = 0; + $palette->padding = -1; + $palette->margin = 3; + + $this->assertSame( $palette->chartBorderWidth, 0 ); + $this->assertSame( $palette->padding, 0 ); + $this->assertSame( $palette->margin, 3 ); + } + + public function testModifyPaletteDatasetColorArray() + { + $palette = new ezcGraphPaletteTango(); + + $palette->dataSetColor = array( + '#ABCDEF', + array( 255, 255, 255 ), + ); + + $this->assertEquals( + $palette->dataSetColor, + ezcGraphColor::fromHex( '#ABCDEF' ) + ); + + try + { + $palette->dataSetColor = '#FFFFFF'; + } + catch ( ezcBaseValueException $e ) + { + return true; + } + + $this->fail( 'expected ezcBaseValueException.' ); + } + + public function testModifyPaletteDatasetSymbolArray() + { + $palette = new ezcGraphPaletteTango(); + + $palette->dataSetSymbol = array( + ezcGraph::BULLET, + ezcGraph::CIRCLE + ); + + $this->assertSame( + $palette->dataSetSymbol, + ezcGraph::BULLET + ); + + try + { + $palette->dataSetSymbol = ezcGraph::BULLET; + } + catch ( ezcBaseValueException $e ) + { + return true; + } + + $this->fail( 'expected ezcBaseValueException.' ); + } } ?> |