diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2006-08-14 12:50:28 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2006-08-14 12:50:28 +0000 |
commit | 48155e33dd6901e3966d9b151d837bcbdc8e9968 (patch) | |
tree | 04fbae229bbf0a5bbea14d3e4da3f0bd976a4572 /src | |
parent | 21f7809f953a75b9e6214d0549a7f1941e3df7b9 (diff) | |
download | zetacomponents-graph-48155e33dd6901e3966d9b151d837bcbdc8e9968.zip zetacomponents-graph-48155e33dd6901e3966d9b151d837bcbdc8e9968.tar.gz |
- Changed datsets to accept instances of ezcGraphDataSet only
- Added bar charts
- Globally increase acceptable difference noise for created images in tests
Diffstat (limited to 'src')
-rw-r--r-- | src/charts/line.php | 140 | ||||
-rw-r--r-- | src/charts/pie.php | 36 | ||||
-rw-r--r-- | src/datasets/array.php | 42 | ||||
-rw-r--r-- | src/datasets/average.php | 2 | ||||
-rw-r--r-- | src/datasets/base.php | 31 | ||||
-rw-r--r-- | src/exceptions/invalid_id.php | 1 | ||||
-rw-r--r-- | src/exceptions/unknown_dataset_source.php | 2 | ||||
-rw-r--r-- | src/graph.php | 4 | ||||
-rw-r--r-- | src/graph_autoload.php | 5 | ||||
-rw-r--r-- | src/interfaces/axis_label_renderer.php | 5 | ||||
-rw-r--r-- | src/interfaces/chart.php | 35 | ||||
-rw-r--r-- | src/interfaces/renderer.php | 24 | ||||
-rw-r--r-- | src/options/renderer_2d.php | 31 | ||||
-rw-r--r-- | src/options/renderer_3d.php | 33 | ||||
-rw-r--r-- | src/renderer/2d.php | 66 | ||||
-rw-r--r-- | src/renderer/3d.php | 29 | ||||
-rw-r--r-- | src/renderer/axis_label_boxed.php | 171 |
17 files changed, 571 insertions, 86 deletions
diff --git a/src/charts/line.php b/src/charts/line.php index 8ca290a..db33938 100644 --- a/src/charts/line.php +++ b/src/charts/line.php @@ -83,49 +83,119 @@ class ezcGraphLineChart extends ezcGraphChart $yAxisNullPosition = $this->elements['yAxis']->getCoordinate( false ); - $nr = count( $this->data ); + // Initialize counters + $nr = array(); + $count = array(); + foreach ( $this->data as $data ) { - --$nr; - // Determine fill color for dataset - if ( $this->options->fillLines !== false ) - { - $fillColor = clone $data->color->default; - $fillColor->alpha = (int) round( ( 255 - $fillColor->alpha ) * ( $this->options->fillLines / 255 ) ); - } - else + if ( !isset( $nr[$data->displayType->default] ) ) { - $fillColor = null; + $nr[$data->displayType->default] = 0; + $count[$data->displayType->default] = 0; } - // Draw lines for dataset - $lastPoint = false; - foreach ( $data as $key => $value ) + $nr[$data->displayType->default]++; + $count[$data->displayType->default]++; + } + + // Display data + foreach ( $this->data as $data ) + { + --$nr[$data->displayType->default]; + switch ( $data->displayType->default ) { - $point = new ezcGraphCoordinate( - $this->elements['xAxis']->getCoordinate( $key ), - $this->elements['yAxis']->getCoordinate( $value ) - ); - - $renderer->drawDataLine( - $boundings, - $data->color->default, - ( $lastPoint === false ? $point : $lastPoint ), - $point, - $nr, - count( $this->data ), - $data->symbol[$key], - $data->color[$key], - $fillColor, - $yAxisNullPosition - ); - - $lastPoint = $point; + case ezcGraph::LINE: + // Determine fill color for dataset + if ( $this->options->fillLines !== false ) + { + $fillColor = clone $data->color->default; + $fillColor->alpha = (int) round( ( 255 - $fillColor->alpha ) * ( $this->options->fillLines / 255 ) ); + } + else + { + $fillColor = null; + } + + // Draw lines for dataset + $lastPoint = false; + foreach ( $data as $key => $value ) + { + $point = $this->elements['xAxis']->axisLabelRenderer->modifyChartDataPosition( + $this->elements['yAxis']->axisLabelRenderer->modifyChartDataPosition( + new ezcGraphCoordinate( + $this->elements['xAxis']->getCoordinate( $key ), + $this->elements['yAxis']->getCoordinate( $value ) + ) + ) + ); + + $renderer->drawDataLine( + $boundings, + $data->color->default, + ( $lastPoint === false ? $point : $lastPoint ), + $point, + $nr[$data->displayType->default], + $count[$data->displayType->default], + $data->symbol[$key], + $data->color[$key], + $fillColor, + $yAxisNullPosition + ); + + $lastPoint = $point; + } + break; + case ezcGraph::BAR: + $width = $this->elements['xAxis']->axisLabelRenderer->modifyChartDataPosition( + $this->elements['yAxis']->axisLabelRenderer->modifyChartDataPosition( + new ezcGraphCoordinate( + ( $boundings->x1 - $boundings->x0 ) / $this->elements['xAxis']->getMajorStepCount(), + 0 + ) + ) + )->x; + + foreach ( $data as $key => $value ) + { + $point = new ezcGraphCoordinate( + $this->elements['xAxis']->getCoordinate( $key ), + $this->elements['yAxis']->getCoordinate( $value ) + ); + + $renderer->drawBar( + $boundings, + $data->color->default, + $this->elements['xAxis']->axisLabelRenderer->modifyChartDataPosition( + $this->elements['yAxis']->axisLabelRenderer->modifyChartDataPosition( + $point + ) + ), + $width, + $nr[$data->displayType->default], + $count[$data->displayType->default], + $yAxisNullPosition + ); + } + break; + default: + throw new ezcGraphInvalidDisplayTypeException( $data->displayType->default ); + break; } } } /** + * Returns the default display type of the current chart type. + * + * @return int Display type + */ + protected function getDefaultDisplayType() + { + return ezcGraph::LINE; + } + + /** * Render a line chart * * @param ezcGraphRenderer $renderer @@ -168,6 +238,12 @@ class ezcGraphLineChart extends ezcGraphChart $boundings->x1 = $this->options->width; $boundings->y1 = $this->options->height; + $boundings = $this->elements['xAxis']->axisLabelRenderer->modifyChartBoundings( + $this->elements['yAxis']->axisLabelRenderer->modifyChartBoundings( + $boundings, new ezcGraphCoordinate( 1, 0 ) + ), new ezcGraphCoordinate( -1, 0 ) + ); + // Render subelements foreach ( $this->elements as $name => $element ) { diff --git a/src/charts/pie.php b/src/charts/pie.php index 4a23911..a832796 100644 --- a/src/charts/pie.php +++ b/src/charts/pie.php @@ -31,7 +31,7 @@ class ezcGraphPieChart extends ezcGraphChart * If too many datasets are created * @return ezcGraphDataSet */ - protected function addDataSet( $name, $values ) + protected function addDataSet( $name, ezcGraphDataSet $values ) { if ( count( $this->data ) >= 1 && !isset( $this->data[$name] ) ) @@ -67,18 +67,36 @@ class ezcGraphPieChart extends ezcGraphChart $angle = 0; foreach ( $dataset as $label => $value ) { - $renderer->drawPieSegment( - $boundings, - $dataset->color[$label], - $angle, - $angle += $value / $sum * 360, - sprintf( $this->options->label, $label, $value, $value / $sum * 100 ), - $dataset->highlight[$label] - ); + switch( $dataset->displayType->default ) + { + case ezcGraph::PIE: + $renderer->drawPieSegment( + $boundings, + $dataset->color[$label], + $angle, + $angle += $value / $sum * 360, + sprintf( $this->options->label, $label, $value, $value / $sum * 100 ), + $dataset->highlight[$label] + ); + break; + default: + throw new ezcGraphInvalidDisplayTypeException( $dataset->displayType->default ); + break; + } } } /** + * Returns the default display type of the current chart type. + * + * @return int Display type + */ + protected function getDefaultDisplayType() + { + return ezcGraph::PIE; + } + + /** * Render a pie chart * * @param ezcGraphRenderer $renderer diff --git a/src/datasets/array.php b/src/datasets/array.php new file mode 100644 index 0000000..44aa82c --- /dev/null +++ b/src/datasets/array.php @@ -0,0 +1,42 @@ +<?php +/** + * File containing the abstract ezcGraphArrayDataSet class + * + * @package Graph + * @version //autogentag// + * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ +/** + * Basic class to contain the charts data + * + * @package Graph + */ +class ezcGraphArrayDataSet extends ezcGraphDataSet +{ + public function __construct( $data ) + { + $this->createFromArray( $data ); + parent::__construct(); + } + + /** + * setData + * + * @param array $data + * @access public + * @return void + */ + protected function createFromArray( $data = array() ) + { + foreach ( $data as $key => $value ) + { + if ( is_numeric( $value ) ) + { + $this->data[$key] = (float) $value; + } + } + } +} + +?> diff --git a/src/datasets/average.php b/src/datasets/average.php index 7d9a662..3af2094 100644 --- a/src/datasets/average.php +++ b/src/datasets/average.php @@ -12,7 +12,7 @@ * * @package Graph */ -class ezcGraphDataSetAverage extends ezcDataSet +class ezcGraphDataSetAverage extends ezcGraphDataSet { } diff --git a/src/datasets/base.php b/src/datasets/base.php index 849f996..2f5fc92 100644 --- a/src/datasets/base.php +++ b/src/datasets/base.php @@ -12,7 +12,7 @@ * * @package Graph */ -class ezcGraphDataSet implements ArrayAccess, Iterator +abstract class ezcGraphDataSet implements ArrayAccess, Iterator { /** @@ -45,6 +45,13 @@ class ezcGraphDataSet implements ArrayAccess, Iterator protected $highlight; /** + * Display type of chart data. + * + * @var integer + */ + protected $displayType; + + /** * Array which contains the data of the dataset * * @var array @@ -72,28 +79,11 @@ class ezcGraphDataSet implements ArrayAccess, Iterator $this->color = new ezcGraphDataSetColorProperty( $this ); $this->symbol = new ezcGraphDataSetIntProperty( $this ); $this->highlight = new ezcGraphDataSetBooleanProperty( $this ); + $this->displayType = new ezcGraphDataSetIntProperty( $this ); $this->highlight->default = false; } - /** - * setData - * - * @param array $data - * @access public - * @return void - */ - public function createFromArray( $data = array() ) - { - foreach ( $data as $key => $value ) - { - if ( is_numeric( $value ) ) - { - $this->data[$key] = (float) $value; - } - } - } - public function __set( $propertyName, $propertyValue ) { switch ( $propertyName ) @@ -111,6 +101,9 @@ class ezcGraphDataSet implements ArrayAccess, Iterator case 'hilight': $this->highlight->default = $propertyValue; break; + case 'displayType': + $this->displayType->default = $propertyValue; + break; case 'palette': $this->palette = $propertyValue; $this->color->default = $this->palette->dataSetColor; diff --git a/src/exceptions/invalid_id.php b/src/exceptions/invalid_id.php index d849f13..684aeeb 100644 --- a/src/exceptions/invalid_id.php +++ b/src/exceptions/invalid_id.php @@ -23,4 +23,3 @@ class ezcGraphSvgDriverInvalidIdException extends ezcGraphException } ?> - diff --git a/src/exceptions/unknown_dataset_source.php b/src/exceptions/unknown_dataset_source.php index 63beb52..7bd719a 100644 --- a/src/exceptions/unknown_dataset_source.php +++ b/src/exceptions/unknown_dataset_source.php @@ -18,7 +18,7 @@ class ezcGraphUnknownDataSetSourceException extends ezcGraphException { public function __construct( $source ) { - parent::__construct( 'You provided data which could not be handled as a dataset, yet.' ); + parent::__construct( 'Your provided data which could not be handled as a dataset.' ); } } diff --git a/src/graph.php b/src/graph.php index fa4555a..0b9cff3 100644 --- a/src/graph.php +++ b/src/graph.php @@ -29,6 +29,10 @@ class ezcGraph const RIGHT = 8; const CENTER = 16; const MIDDLE = 32; + + const PIE = 1; + const LINE = 2; + const BAR = 3; } ?> diff --git a/src/graph_autoload.php b/src/graph_autoload.php index 15703ea..188a38a 100644 --- a/src/graph_autoload.php +++ b/src/graph_autoload.php @@ -36,6 +36,7 @@ return array( 'ezcGraphAxisNoLabelRenderer' => 'Graph/renderer/axis_label_none.php', 'ezcGraphAxisExactLabelRenderer' => 'Graph/renderer/axis_label_exact.php', 'ezcGraphAxisCenteredLabelRenderer' => 'Graph/renderer/axis_label_centered.php', + 'ezcGraphAxisBoxedLabelRenderer' => 'Graph/renderer/axis_label_boxed.php', 'ezcGraphDriver' => 'Graph/interfaces/driver.php', 'ezcGraphDriverOptions' => 'Graph/options/driver.php', @@ -66,7 +67,8 @@ return array( 'ezcGraphChartElementLabeledAxis' => 'Graph/axis/labeled.php', 'ezcGraphDataSet' => 'Graph/datasets/base.php', - 'ezcGraphDataSetAverage' => 'Graph/datasets/average.php', + 'ezcGraphArrayDataSet' => 'Graph/datasets/array.php', + 'ezcGraphAverageDataSet' => 'Graph/datasets/average.php', 'ezcGraphDataSetProperty' => 'Graph/interfaces/dataset_property.php', 'ezcGraphDataSetColorProperty' => 'Graph/datasets/property/color.php', 'ezcGraphDataSetStringProperty' => 'Graph/datasets/property/string.php', @@ -76,6 +78,7 @@ return array( 'ezcGraphNoSuchDataSetException' => 'Graph/exceptions/no_such_dataset.php', 'ezcGraphTooManyDataSetsExceptions' => 'Graph/exceptions/too_many_datasets.php', 'ezcGraphUnknownDataSetSourceException' => 'Graph/exceptions/unknown_dataset_source.php', + 'ezcGraphInvalidDisplayTypeException' => 'Graph/exceptions/invalid_display_type.php', 'ezcGraphBoundings' => 'Graph/structs/boundings.php', 'ezcGraphCoordinate' => 'Graph/structs/coordinate.php', diff --git a/src/interfaces/axis_label_renderer.php b/src/interfaces/axis_label_renderer.php index 309edcc..63401d5 100644 --- a/src/interfaces/axis_label_renderer.php +++ b/src/interfaces/axis_label_renderer.php @@ -270,7 +270,7 @@ abstract class ezcGraphAxisLabelRenderer extends ezcBaseOptions /** * Modify chart boundings * - * Optionally modify boundings of + * Optionally modify boundings of chart data * * @param ezcGraphBoundings $boundings Current boundings of chart * @param ezcGraphCoordinate $direction Direction of the current axis @@ -287,10 +287,9 @@ abstract class ezcGraphAxisLabelRenderer extends ezcBaseOptions * Optionally additionally modify the coodinate of a data point * * @param ezcGraphCoordinate $coordinate Data point coordinate - * @param ezcGraphCoordinate $direction Direction of the current axis * @return ezcGraphCoordinate Modified coordinate */ - public function modifyChartDataPosition( ezcGraphCoordinate $coordinate, ezcGraphCoordinate $direction ) + public function modifyChartDataPosition( ezcGraphCoordinate $coordinate ) { return $coordinate; } diff --git a/src/interfaces/chart.php b/src/interfaces/chart.php index ca9b16b..d87ad37 100644 --- a/src/interfaces/chart.php +++ b/src/interfaces/chart.php @@ -194,26 +194,13 @@ abstract class ezcGraphChart implements ArrayAccess * If too many datasets are created * @return ezcGraphDataSet */ - protected function addDataSet( $name, $values ) + protected function addDataSet( $name, ezcGraphDataSet $dataSet ) { - $this->data[$name] = new ezcGraphDataSet(); + $this->data[$name] = $dataSet; - if ( is_array($values) ) - { - $this->data[$name]->createFromArray( $values ); - $this->data[$name]->label = $name; - $this->data[$name]->palette = $this->palette; - } - elseif ( $values instanceof PDOStatement ) - { - $this->data[$name]->createFromStatement( $values ); - $this->data[$name]->label = $name; - $this->data[$name]->palette = $this->palette; - } - else - { - throw new ezcGraphUnknownDataSetSourceException( $values ); - } + $this->data[$name]->label = $name; + $this->data[$name]->palette = $this->palette; + $this->data[$name]->displayType = $this->getDefaultDisplayType(); } /** @@ -261,6 +248,11 @@ abstract class ezcGraphChart implements ArrayAccess public function offsetSet( $key, $value ) { + if ( !$value instanceof ezcGraphDataSet ) + { + throw new ezcGraphUnknownDataSetSourceException( $value ); + } + return $this->addDataSet( $key, $value ); } @@ -291,6 +283,13 @@ abstract class ezcGraphChart implements ArrayAccess } /** + * Returns the default display type of the current chart type. + * + * @return int Display type + */ + abstract protected function getDefaultDisplayType(); + + /** * Renders this chart * * Creates basic visual chart elements from the chart to be processed by diff --git a/src/interfaces/renderer.php b/src/interfaces/renderer.php index 5abb86f..2549f00 100644 --- a/src/interfaces/renderer.php +++ b/src/interfaces/renderer.php @@ -47,6 +47,30 @@ abstract class ezcGraphRenderer ); /** + * Draw bar + * + * Draws a bar as a data element in a line chart + * + * @param ezcGraphBoundings $boundings Chart boundings + * @param ezcGraphColor $color Color of line + * @param ezcGraphCoordinate $position Position of data point + * @param float $stepSize Space which can be used for bars + * @param int $dataNumber Number of dataset + * @param int $dataCount Count of datasets in chart + * @param float $axisPosition Position of axis for drawing filled lines + * @return void + */ + abstract public function drawBar( + ezcGraphBoundings $boundings, + ezcGraphColor $color, + ezcGraphCoordinate $position, + $stepSize, + $dataNumber = 1, + $dataCount = 1, + $axisPosition = 0. + ); + + /** * Draw data line * * Draws a line as a data element in a line chart diff --git a/src/options/renderer_2d.php b/src/options/renderer_2d.php index caddacd..dd2c4b2 100644 --- a/src/options/renderer_2d.php +++ b/src/options/renderer_2d.php @@ -60,6 +60,28 @@ class ezcGraphRenderer2dOptions extends ezcGraphChartOptions protected $titleAlignement = 48; // ezcGraph::MIDDLE | ezcGraph::CENTER /** + * Factor to darken border of data elements, like lines, bars and pie + * segments + * + * @var float + */ + protected $dataBorder = .5; + + /** + * Procentual distance between bar blocks + * + * @var float + */ + protected $barMargin = .1; + + /** + * Procentual distance between bars + * + * @var float + */ + protected $barPadding = .05; + + /** * Set an option value * * @param string $propertyName @@ -90,6 +112,15 @@ class ezcGraphRenderer2dOptions extends ezcGraphChartOptions case 'titleAlignement': $this->titleAlignement = (int) $propertyValue; break; + case 'dataBorder': + $this->dataBorder = min( 1, max( 0, (float) $propertyValue ) ); + break; + case 'barMargin': + $this->barMargin = min( 1, max( 0, (float) $propertyValue ) ); + break; + case 'barPadding': + $this->barPadding = min( 1, max( 0, (float) $propertyValue ) ); + break; default: return parent::__set( $propertyName, $propertyValue ); } diff --git a/src/options/renderer_3d.php b/src/options/renderer_3d.php index abf8046..04994d1 100644 --- a/src/options/renderer_3d.php +++ b/src/options/renderer_3d.php @@ -112,6 +112,27 @@ class ezcGraphRenderer3dOptions extends ezcGraphChartOptions protected $pieChartRotation = .6; /** + * Used transparency for pie chart shadows + * + * @var float + */ + protected $pieChartShadow = .6; + + /** + * Procentual distance between bar blocks + * + * @var float + */ + protected $barMargin = .1; + + /** + * Procentual distance between bars + * + * @var float + */ + protected $barPadding = .05; + + /** * Set an option value * * @param string $propertyName @@ -163,6 +184,18 @@ class ezcGraphRenderer3dOptions extends ezcGraphChartOptions case 'pieChartRotation': $this->pieChartRotation = min( 1, max( 0, (float) $propertyValue ) ); break; + case 'pieChartRotation': + $this->pieChartRotation = min( 1, max( 0, (float) $propertyValue ) ); + break; + case 'pieChartShadow': + $this->pieChartShadow = min( 1, max( 0, (float) $propertyValue ) ); + break; + case 'barMargin': + $this->barMargin = min( 1, max( 0, (float) $propertyValue ) ); + break; + case 'barPadding': + $this->barPadding = min( 1, max( 0, (float) $propertyValue ) ); + break; default: return parent::__set( $propertyName, $propertyValue ); } diff --git a/src/renderer/2d.php b/src/renderer/2d.php index 1c54de0..ed3ebff 100644 --- a/src/renderer/2d.php +++ b/src/renderer/2d.php @@ -264,6 +264,72 @@ class ezcGraphRenderer2d extends ezcGraphRenderer } /** + * Draw bar + * + * Draws a bar as a data element in a line chart + * + * @param ezcGraphBoundings $boundings Chart boundings + * @param ezcGraphColor $color Color of line + * @param ezcGraphCoordinate $position Position of data point + * @param float $stepSize Space which can be used for bars + * @param int $dataNumber Number of dataset + * @param int $dataCount Count of datasets in chart + * @param float $axisPosition Position of axis for drawing filled lines + * @return void + */ + public function drawBar( + ezcGraphBoundings $boundings, + ezcGraphColor $color, + ezcGraphCoordinate $position, + $stepSize, + $dataNumber = 1, + $dataCount = 1, + $axisPosition = 0. ) + { + // Apply margin + $margin = $stepSize * $this->options->barMargin; + $padding = $stepSize * $this->options->barPadding; + $barWidth = ( $stepSize - $margin ) / $dataCount - $padding; + $offset = - $stepSize / 2 + $margin / 2 + $dataNumber * ( $padding + $barWidth ) + $padding / 2; + + $barPointArray = array( + new ezcGraphCoordinate( + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $position->x + $offset, + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition + ), + new ezcGraphCoordinate( + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $position->x + $offset, + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $position->y + ), + new ezcGraphCoordinate( + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $position->x + $offset + $barWidth, + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $position->y + ), + new ezcGraphCoordinate( + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $position->x + $offset + $barWidth, + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition + ), + ); + + $this->driver->drawPolygon( + $barPointArray, + $color, + true + ); + + if ( $this->options->dataBorder > 0 ) + { + $darkened = $color->darken( $this->options->dataBorder ); + $this->driver->drawPolygon( + $barPointArray, + $darkened, + false, + 1 + ); + } + } + + /** * Draw data line * * Draws a line as a data element in a line chart diff --git a/src/renderer/3d.php b/src/renderer/3d.php index 1997e56..4537fa7 100644 --- a/src/renderer/3d.php +++ b/src/renderer/3d.php @@ -91,7 +91,8 @@ class ezcGraphRenderer3d extends ezcGraphRenderer // Calculate position and size of pie $center = new ezcGraphCoordinate( $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2, - $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2 - $this->options->pieChartHeight / 2 + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2 + - $this->options->pieChartHeight / 2 ); // Limit radius to fourth of width and half of height at maximum @@ -432,6 +433,32 @@ class ezcGraphRenderer3d extends ezcGraphRenderer } /** + * Draw bar + * + * Draws a bar as a data element in a line chart + * + * @param ezcGraphBoundings $boundings Chart boundings + * @param ezcGraphColor $color Color of line + * @param ezcGraphCoordinate $position Position of data point + * @param float $stepSize Space which can be used for bars + * @param int $dataNumber Number of dataset + * @param int $dataCount Count of datasets in chart + * @param float $axisPosition Position of axis for drawing filled lines + * @return void + */ + public function drawBar( + ezcGraphBoundings $boundings, + ezcGraphColor $color, + ezcGraphCoordinate $position, + $stepSize, + $dataNumber = 1, + $dataCount = 1, + $axisPosition = 0. ) + { + // @TODO: implement + } + + /** * Draw data line * * Draws a line as a data element in a line chart diff --git a/src/renderer/axis_label_boxed.php b/src/renderer/axis_label_boxed.php new file mode 100644 index 0000000..be76e9a --- /dev/null +++ b/src/renderer/axis_label_boxed.php @@ -0,0 +1,171 @@ +<?php +/** + * File containing the abstract ezcGraphAxisExactLabelRenderer class + * + * @package Graph + * @version //autogentag// + * @copyright Copyright (C) 2005, + 2006 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ +/** + * Renders axis labels like known from charts drawn in analysis + * + * @package Graph + */ +class ezcGraphAxisBoxedLabelRenderer extends ezcGraphAxisLabelRenderer +{ + + protected $outerStep = true; + + protected $direction; + + /** + * Render Axis labels + * + * Render labels for an axis. + * + * @param ezcGraphRenderer $renderer Renderer used to draw the chart + * @param ezcGraphBoundings $boundings Boundings of the axis + * @param ezcGraphCoordinate $start Axis starting point + * @param ezcGraphCoordinate $end Axis ending point + * @param ezcGraphChartElementAxis $axis Axis instance + * @return void + */ + public function renderLabels( + ezcGraphRenderer $renderer, + ezcGraphBoundings $boundings, + ezcGraphCoordinate $start, + ezcGraphCoordinate $end, + ezcGraphChartElementAxis $axis ) + { + // receive rendering parameters from axis + $this->majorStepCount = $axis->getMajorStepCount() + 1; + + // Determine normalized axis direction + $direction = new ezcGraphCoordinate( + $start->x - $end->x, + $start->y - $end->y + ); + $length = sqrt( pow( $direction->x, 2) + pow( $direction->y, 2 ) ); + $direction->x /= $length; + $direction->y /= $length; + $this->direction = $direction; + + // Calculate stepsizes for mjor and minor steps + $majorStep = new ezcGraphCoordinate( + ( $end->x - $start->x ) / $this->majorStepCount, + ( $end->y - $start->y ) / $this->majorStepCount + ); + + if ( $this->outerGrid ) + { + $gridBoundings = $boundings; + } + else + { + $gridBoundings = new ezcGraphBoundings( + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $axis->axisSpace, + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axis->axisSpace, + $boundings->x1 - ( $boundings->x1 - $boundings->x0 ) * $axis->axisSpace, + $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $axis->axisSpace + ); + } + + // Determine size of labels + switch ( $axis->position ) + { + case ezcGraph::RIGHT: + case ezcGraph::LEFT: + $labelWidth = min( + abs( $majorStep->x ), + ( $boundings->x1 - $boundings->x0 ) * $axis->axisSpace * 2 + ); + $labelHeight = ( $boundings->y1 - $boundings->y0 ) * $axis->axisSpace; + break; + case ezcGraph::BOTTOM: + case ezcGraph::TOP: + $labelWidth = ( $boundings->x1 - $boundings->x0 ) * $axis->axisSpace; + $labelHeight = min( + abs( $majorStep->y ), + ( $boundings->y1 - $boundings->y0 ) * $axis->axisSpace * 2 + ); + break; + } + + // Draw steps and grid + $step = 0; + while ( $step <= $this->majorStepCount ) + { + if ( ! $axis->isZeroStep( $step ) ) + { + // major grid + if ( $axis->majorGrid ) + { + $this->drawGrid( $renderer, $gridBoundings, $start, $majorStep, $axis->majorGrid ); + } + + // major step + $this->drawStep( $renderer, $start, $direction, $axis->position, $this->majorStepSize, $axis->border ); + } + + // draw label + if ( $step < $this->majorStepCount ) + { + $label = $axis->getLabel( $step ); + switch ( $axis->position ) + { + case ezcGraph::TOP: + case ezcGraph::BOTTOM: + $renderer->drawText( + new ezcGraphBoundings( + $start->x - $labelWidth + $this->labelPadding, + $start->y + $this->labelPadding, + $start->x - $this->labelPadding, + $start->y + $labelHeight - $this->labelPadding + ), + $label, + ezcGraph::MIDDLE | ezcGraph::RIGHT + ); + break; + case ezcGraph::LEFT: + case ezcGraph::RIGHT: + $renderer->drawText( + new ezcGraphBoundings( + $start->x + $this->labelPadding, + $start->y + $this->labelPadding, + $start->x + $labelWidth - $this->labelPadding, + $start->y + $labelHeight - $this->labelPadding + ), + $label, + ezcGraph::CENTER | ezcGraph::TOP + ); + break; + } + } + + $start->x += $majorStep->x; + $start->y += $majorStep->y; + ++$step; + } + } + + /** + * Modify chart data position + * + * Optionally additionally modify the coodinate of a data point + * + * @param ezcGraphCoordinate $coordinate Data point coordinate + * @return ezcGraphCoordinate Modified coordinate + */ + public function modifyChartDataPosition( ezcGraphCoordinate $coordinate ) + { + return new ezcGraphCoordinate( + $coordinate->x * abs( $this->direction->y ) + + ( $coordinate->x * ( 1 - 1 / $this->majorStepCount ) + ( 1 / $this->majorStepCount / 2 ) ) * abs( $this->direction->x ), + $coordinate->y * abs( $this->direction->x ) + + ( $coordinate->y * ( 1 - 1 / $this->majorStepCount ) + ( 1 / $this->majorStepCount / 2 ) ) * abs( $this->direction->y ) + ); + } +} +?> |