diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2006-08-18 10:09:06 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2006-08-18 10:09:06 +0000 |
commit | 94953ea4f75810e5e667425bfd55ce8d51672ee3 (patch) | |
tree | b6e34c66f1031c2834c3578a7e80382710c2f362 /src/element | |
parent | e981be4dca177e235f6aa9b597d4a99c0a2cf875 (diff) | |
download | zetacomponents-graph-94953ea4f75810e5e667425bfd55ce8d51672ee3.zip zetacomponents-graph-94953ea4f75810e5e667425bfd55ce8d51672ee3.tar.gz |
- Moved properties to properties array
- Fixed bug: Legend title was rendered, even when empty
Diffstat (limited to 'src/element')
-rw-r--r-- | src/element/axis.php | 124 | ||||
-rw-r--r-- | src/element/background.php | 46 | ||||
-rw-r--r-- | src/element/legend.php | 102 | ||||
-rw-r--r-- | src/element/text.php | 43 |
4 files changed, 166 insertions, 149 deletions
diff --git a/src/element/axis.php b/src/element/axis.php index b4805fa..8b3c643 100644 --- a/src/element/axis.php +++ b/src/element/axis.php @@ -10,69 +10,28 @@ /** * Class to represent a legend as a chart element * + * @property float $nullPosition + * The position of the null value. + * @property float $axisSpace + * Percent of the chart space used to display axis labels and + * arrowheads instead of data values. + * @property ezcGraphColor $majorStep + * Color of major majorGrid. + * @property ezcGraphColor $minorStep + * Color of minor majorGrid. + * @property mixed $majorStep + * Labeled major steps displayed on the axis. + * @property mixed $minorStep + * Non labeled minor steps on the axis. + * @property string $formatString + * Formatstring to use for labeling og the axis. + * @property int $maxArrowHeadSize + * Maximum Size used to draw arrow heads. + * * @package Graph */ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement { - - /** - * The position of the null value - * - * @var float - */ - protected $nullPosition; - - /** - * Percent of the chart space used to display axis labels and arrowheads - * instead of data values - * - * @var float - */ - protected $axisSpace = .1; - - /** - * Color of major majorGrid - * - * @var ezcGraphColor - */ - protected $majorGrid; - - /** - * Color of minor majorGrid - * - * @var ezcGraphColor - */ - protected $minorGrid; - - /** - * Labeled major steps displayed on the axis - * - * @var float - */ - protected $majorStep = false; - - /** - * Non labeled minor steps on the axis - * - * @var mixed - * @access protected - */ - protected $minorStep = false; - - /** - * Formatstring to use for labeling og the axis - * - * @var string - */ - protected $formatString = '%s'; - - /** - * Maximum Size used to draw arrow heads - * - * @var integer - */ - protected $maxArrowHeadSize = 8; - /** * Axis label renderer class * @@ -80,8 +39,24 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement */ protected $axisLabelRenderer; + /** + * Constructor + * + * @param array $options Default option array + * @return void + * @ignore + */ public function __construct( array $options = array() ) { + $this->properties['nullPosition'] = false; + $this->properties['axisSpace'] = .1; + $this->properties['majorGrid'] = false; + $this->properties['minorGrid'] = false; + $this->properties['majorStep'] = false; + $this->properties['minorStep'] = false; + $this->properties['formatString'] = '%s'; + $this->properties['maxArrowHeadSize'] = 8; + parent::__construct( $options ); if ( !isset( $this->axisLabelRenderer ) ) @@ -121,29 +96,29 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement switch ( $propertyName ) { case 'nullPosition': - $this->nullPosition = (float) $propertyValue; + $this->properties['nullPosition'] = (float) $propertyValue; break; case 'axisSpace': - $this->axisSpace = min( 1, max( 0, (float) $propertyValue ) ); + $this->properties['axisSpace'] = min( 1, max( 0, (float) $propertyValue ) ); break; case 'majorGrid': if ( $propertyValue instanceof ezcGraphColor ) { - $this->majorGrid = $propertyValue; + $this->properties['majorGrid'] = $propertyValue; } else { - $this->majorGrid = ezcGraphColor::create( $propertyValue ); + $this->properties['majorGrid'] = ezcGraphColor::create( $propertyValue ); } break; case 'minorGrid': if ( $propertyValue instanceof ezcGraphColor ) { - $this->minorGrid = $propertyValue; + $this->properties['minorGrid'] = $propertyValue; } else { - $this->minorGrid = ezcGraphColor::create( $propertyValue ); + $this->properties['minorGrid'] = ezcGraphColor::create( $propertyValue ); } break; case 'majorStep': @@ -151,20 +126,20 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement { throw new ezcBaseValueException( 'majorStep', $propertyValue, 'float > 0' ); } - $this->majorStep = (float) $propertyValue; + $this->properties['majorStep'] = (float) $propertyValue; break; case 'minorStep': if ( $propertyValue <= 0 ) { throw new ezcBaseValueException( 'minorStep', $propertyValue, 'float > 0' ); } - $this->minorStep = (float) $propertyValue; + $this->properties['minorStep'] = (float) $propertyValue; break; case 'formatString': - $this->formatString = (string) $propertyValue; + $this->properties['formatString'] = (string) $propertyValue; break; case 'maxArrowHeadSize': - $this->maxArrowHeadSize = max( 0, (int) $propertyValue ); + $this->properties['maxArrowHeadSize'] = max( 0, (int) $propertyValue ); break; case 'axisLabelRenderer': if ( $propertyValue instanceof ezcGraphAxisLabelRenderer ) @@ -182,6 +157,17 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement } } + public function __get( $propertyName ) + { + switch ( $propertyName ) + { + case 'axisLabelRenderer': + return $this->axisLabelRenderer; + default: + return parent::__get( $propertyName ); + } + } + /** * Get coordinate for a dedicated value on the chart * diff --git a/src/element/background.php b/src/element/background.php index 269b520..66e19da 100644 --- a/src/element/background.php +++ b/src/element/background.php @@ -10,24 +10,30 @@ /** * Class to represent a legend as a chart element * + * @property string $image + * Filename of the file to use for background + * @property int $repeat + * Defines how the background image gets repeated + * * @package Graph */ class ezcGraphChartElementBackground extends ezcGraphChartElement { /** - * Filename of the file to use for background + * Constructor * - * @var string + * @param array $options Default option array + * @return void + * @ignore */ - protected $image = false; + public function __construct( array $options = array() ) + { + $this->properties['image'] = false; + $this->properties['repeat'] = ezcGraph::NO_REPEAT; - /** - * Defines how the background image gets repeated - * - * @var int - */ - protected $repeat = ezcGraph::NO_REPEAT; + parent::__construct( $options ); + } /** * __set @@ -39,6 +45,7 @@ class ezcGraphChartElementBackground extends ezcGraphChartElement * @throws ezcBasePropertyNotFoundException * If a the value for the property options is not an instance of * @return void + * @ignore */ public function __set( $propertyName, $propertyValue ) { @@ -64,12 +71,12 @@ class ezcGraphChartElementBackground extends ezcGraphChartElement throw new ezcGraphInvalidImageFileException( 'We cant use SWF files like <' . $propertyValue . '>.' ); } - $this->image = $propertyValue; + $this->properties['image'] = $propertyValue; break; case 'repeat': if ( ( $propertyValue >= 0 ) && ( $propertyValue <= 3 ) ) { - $this->repeat = (int) $propertyValue; + $this->properties['repeat'] = (int) $propertyValue; } else { @@ -77,9 +84,12 @@ class ezcGraphChartElementBackground extends ezcGraphChartElement } break; case 'position': + // Overwrite parent position setter, to be able to use + // combination of positions like + // ezcGraph::TOP | ezcGraph::CENTER if ( is_int( $propertyValue ) ) { - $this->position = $propertyValue; + $this->properties['position'] = $propertyValue; } else { @@ -95,6 +105,18 @@ class ezcGraphChartElementBackground extends ezcGraphChartElement } } + public function __get( $propertyName ) + { + switch ( $propertyName ) + { + case 'color': + // Use color as an alias to set background color for background + return $this->properties['background']; + default: + return parent::__get( $propertyName ); + } + } + /** * Set colors and border fro this element * diff --git a/src/element/legend.php b/src/element/legend.php index 8f0458c..4cbd966 100644 --- a/src/element/legend.php +++ b/src/element/legend.php @@ -10,6 +10,20 @@ /** * Class to represent a legend as a chart element * + * @property float $portraitSize + * Size of a portrait style legend in percent of the size of the + * complete chart. + * @property float $landscapeSize + * Size of a landscape style legend in percent of the size of the + * complete chart. + * @property int $symbolSize + * Standard size of symbols and text in legends. + * @property float $minimumSymbolSize + * Scale symbol size up to to percent of complete legends size for + * very big legends. + * @property int $spacing + * Space between labels elements in pixel. + * * @package Graph */ class ezcGraphChartElementLegend extends ezcGraphChartElement @@ -31,49 +45,23 @@ class ezcGraphChartElementLegend extends ezcGraphChartElement protected $labels; /** - * Size of a portrait style legend in percent of the size of the complete - * chart - * - * @var float - */ - protected $portraitSize = .2; - - /** - * Size of a landscape style legend in percent of the size of the complete - * chart - * - * @var float - */ - protected $landscapeSize = .1; - - /** - * Standard size of symbols and text in legends - * - * @var integer - */ - protected $symbolSize = 14; - - /** - * Padding for label elements - * - * @var integer - */ - protected $padding = 1; - - /** - * Scale symbol size up to to percent of complete legends size for very - * big legends - * - * @var float - */ - protected $minimumSymbolSize = .05; - - /** - * Space between lael elements in pixel + * Constructor * - * @var integer + * @param array $options Default option array + * @return void + * @ignore */ - protected $spacing = 2; + public function __construct( array $options = array() ) + { + $this->properties['portraitSize'] = .2; + $this->properties['landscapeSize'] = .1; + $this->properties['symbolSize'] = 14; + $this->properties['padding'] = 1; + $this->properties['minimumSymbolSize'] = .05; + $this->properties['spacing'] = 2; + + parent::__construct( $options ); + } /** * __set @@ -85,6 +73,7 @@ class ezcGraphChartElementLegend extends ezcGraphChartElement * @throws ezcBasePropertyNotFoundException * If a the value for the property options is not an instance of * @return void + * @ignore */ public function __set( $propertyName, $propertyValue ) { @@ -110,6 +99,17 @@ class ezcGraphChartElementLegend extends ezcGraphChartElement break; } } + + public function __get( $propertyName ) + { + switch ( $propertyName ) + { + case 'labels': + return $this->labels; + default: + return parent::__get( $propertyName ); + } + } /** * Generate legend from several datasets with on entry per dataset @@ -155,7 +155,7 @@ class ezcGraphChartElementLegend extends ezcGraphChartElement protected function calculateBoundings( ezcGraphBoundings $boundings ) { - $this->boundings = clone $boundings; + $this->properties['boundings'] = clone $boundings; switch ( $this->position ) { @@ -209,15 +209,15 @@ class ezcGraphChartElementLegend extends ezcGraphChartElement } // Render standard elements - $this->boundings = $renderer->drawBox( - $this->boundings, - $this->background, - $this->border, - $this->borderWidth, - $this->margin, - $this->padding, - $this->title, - $this->getTitleSize( $this->boundings, $type ) + $this->properties['boundings'] = $renderer->drawBox( + $this->properties['boundings'], + $this->properties['background'], + $this->properties['border'], + $this->properties['borderWidth'], + $this->properties['margin'], + $this->properties['padding'], + $this->properties['title'], + $this->getTitleSize( $this->properties['boundings'], $type ) ); // Render legend diff --git a/src/element/text.php b/src/element/text.php index dfe1a55..ed7ed85 100644 --- a/src/element/text.php +++ b/src/element/text.php @@ -10,17 +10,26 @@ /** * Class to represent a legend as a chart element * + * @property float $height + * Maximum percent of bounding used to display the text. + * * @package Graph */ class ezcGraphChartElementText extends ezcGraphChartElement { - /** - * Maximum percent of bounding used to display the text + * Constructor * - * @var float + * @param array $options Default option array + * @return void + * @ignore */ - protected $maxHeight = .1; + public function __construct( array $options = array() ) + { + $this->properties['maxHeight'] = .1; + + parent::__construct( $options ); + } /** * __set @@ -38,7 +47,7 @@ class ezcGraphChartElementText extends ezcGraphChartElement switch ( $propertyName ) { case 'maxHeight': - $this->maxHeight = min( 1, max( 0, (float) $propertyValue ) ); + $this->properties['maxHeight'] = min( 1, max( 0, (float) $propertyValue ) ); break; default: parent::__set( $propertyName, $propertyValue ); @@ -55,18 +64,18 @@ class ezcGraphChartElementText extends ezcGraphChartElement */ public function render( ezcGraphRenderer $renderer, ezcGraphBoundings $boundings ) { - if ( empty( $this->title ) ) + if ( empty( $this->properties['title'] ) ) { return $boundings; } $height = (int) min( - round( $this->maxHeight * ( $boundings->y1 - $boundings->y0 ) ), - $this->font->maxFontSize + $this->padding * 2 + $this->margin * 2 + round( $this->properties['maxHeight'] * ( $boundings->y1 - $boundings->y0 ) ), + $this->properties['font']->maxFontSize + $this->padding * 2 + $this->margin * 2 ); - switch ( $this->position ) + switch ( $this->properties['position'] ) { case ezcGraph::TOP: $textBoundings = new ezcGraphBoundings( @@ -75,7 +84,7 @@ class ezcGraphChartElementText extends ezcGraphChartElement $boundings->x1, $boundings->y0 + $height ); - $boundings->y0 += $height + $this->margin; + $boundings->y0 += $height + $this->properties['margin']; break; case ezcGraph::BOTTOM: $textBoundings = new ezcGraphBoundings( @@ -84,22 +93,22 @@ class ezcGraphChartElementText extends ezcGraphChartElement $boundings->x1, $boundings->y1 ); - $boundings->y1 -= $height + $this->margin; + $boundings->y1 -= $height + $this->properties['margin']; break; } $textBoundings = $renderer->drawBox( $textBoundings, - $this->background, - $this->border, - $this->borderWidth, - $this->margin, - $this->padding + $this->properties['background'], + $this->properties['border'], + $this->properties['borderWidth'], + $this->properties['margin'], + $this->properties['padding'] ); $renderer->drawText( $textBoundings, - $this->title, + $this->properties['title'], ezcGraph::CENTER | ezcGraph::MIDDLE ); |