summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-08-15 09:37:47 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-08-15 09:37:47 +0000
commit04e2d9db41d47bc0364261a1cb30fe502409c339 (patch)
tree5d67ca1c0433d8521671fcf3364e2f4030f0fdad /src
parent58808385c0739092503c32c35e9365335040d5d0 (diff)
downloadzetacomponents-graph-04e2d9db41d47bc0364261a1cb30fe502409c339.zip
zetacomponents-graph-04e2d9db41d47bc0364261a1cb30fe502409c339.tar.gz
- Changed access to datasets from $chart['dataset'] to $chart->data['dataset']
Diffstat (limited to 'src')
-rw-r--r--src/charts/line.php2
-rw-r--r--src/charts/pie.php34
-rw-r--r--src/data_container/base.php215
-rw-r--r--src/data_container/single.php46
-rw-r--r--src/driver/svg.php1
-rw-r--r--src/element/legend.php8
-rw-r--r--src/graph_autoload.php3
-rw-r--r--src/interfaces/chart.php65
8 files changed, 281 insertions, 93 deletions
diff --git a/src/charts/line.php b/src/charts/line.php
index db33938..02323e9 100644
--- a/src/charts/line.php
+++ b/src/charts/line.php
@@ -190,7 +190,7 @@ class ezcGraphLineChart extends ezcGraphChart
*
* @return int Display type
*/
- protected function getDefaultDisplayType()
+ public function getDefaultDisplayType()
{
return ezcGraph::LINE;
}
diff --git a/src/charts/pie.php b/src/charts/pie.php
index a832796..3b38648 100644
--- a/src/charts/pie.php
+++ b/src/charts/pie.php
@@ -20,40 +20,14 @@ class ezcGraphPieChart extends ezcGraphChart
$this->options = new ezcGraphPieChartOptions( $options );
parent::__construct( $options );
- }
-
- /**
- * Adds a dataset to the charts data
- *
- * @param string $name Name of dataset
- * @param mixed $values Values to create dataset with
- * @throws ezcGraphTooManyDataSetExceptions
- * If too many datasets are created
- * @return ezcGraphDataSet
- */
- protected function addDataSet( $name, ezcGraphDataSet $values )
- {
- if ( count( $this->data ) >= 1 &&
- !isset( $this->data[$name] ) )
- {
- throw new ezcGraphTooManyDataSetsExceptions( $name );
- }
- else
- {
- parent::addDataSet( $name, $values );
- // Colorize each data element
- foreach ( $this->data[$name] as $label => $value )
- {
- $this->data[$name]->color[$label] = $this->palette->dataSetColor;
- }
- }
+ $this->data = new ezcGraphChartSingleDataContainer( $this );
}
protected function renderData( $renderer, $boundings )
{
// Only draw the first (and only) dataset
- $dataset = reset( $this->data );
+ $dataset = $this->data->rewind();
$this->driver->options->font = $this->options->font;
@@ -91,7 +65,7 @@ class ezcGraphPieChart extends ezcGraphChart
*
* @return int Display type
*/
- protected function getDefaultDisplayType()
+ public function getDefaultDisplayType()
{
return ezcGraph::PIE;
}
@@ -110,7 +84,7 @@ class ezcGraphPieChart extends ezcGraphChart
$this->driver->options->height = $height;
// Generate legend
- $this->elements['legend']->generateFromDataSet( reset( $this->data ) );
+ $this->elements['legend']->generateFromDataSet( $this->data->rewind() );
// Get boundings from parameters
$this->options->width = $width;
diff --git a/src/data_container/base.php b/src/data_container/base.php
new file mode 100644
index 0000000..38bc86c
--- /dev/null
+++ b/src/data_container/base.php
@@ -0,0 +1,215 @@
+<?php
+/**
+ * File containing the abstract ezcGraphChart 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
+ */
+/**
+ * Class containing the container for the charts datasets
+ *
+ * @package Graph
+ */
+
+class ezcGraphChartDataContainer implements ArrayAccess, Iterator, Countable
+{
+ /**
+ * Contains the data of a chart
+ *
+ * @var array( ezcGraphDataSet )
+ */
+ protected $data = array();
+
+ /**
+ * Chart using this data set storage
+ *
+ * @var ezcGraphChart
+ */
+ protected $chart;
+
+ public function __construct( ezcGraphChart $chart )
+ {
+ $this->chart = $chart;
+ }
+
+ /**
+ * Adds a dataset to the charts data
+ *
+ * @param string $name Name of dataset
+ * @param mixed $values Values to create dataset with
+ * @throws ezcGraphTooManyDataSetExceptions
+ * If too many datasets are created
+ * @return ezcGraphDataSet
+ */
+ protected function addDataSet( $name, ezcGraphDataSet $dataSet )
+ {
+ $this->data[$name] = $dataSet;
+
+ $this->data[$name]->label = $name;
+ $this->data[$name]->palette = $this->chart->palette;
+ $this->data[$name]->displayType = $this->chart->getDefaultDisplayType();
+ }
+
+ /**
+ * Returns if the given offset exists.
+ *
+ * This method is part of the ArrayAccess interface to allow access to the
+ * data of this object as if it was an array.
+ *
+ * @param string $key Identifier of dataset.
+ * @return bool True when the offset exists, otherwise false.
+ */
+ public function offsetExists( $key )
+ {
+ return isset( $this->data[$key] );
+ }
+
+ /**
+ * Returns the element with the given offset.
+ *
+ * This method is part of the ArrayAccess interface to allow access to the
+ * data of this object as if it was an array.
+ *
+ * @param string $key Identifier of dataset.
+ * @return ezcGraphDataSet
+ *
+ * @throws ezcGraphNoSuchDataSetException
+ * If no dataset with identifier exists
+ */
+ public function offsetGet( $key )
+ {
+ if ( !isset( $key ) )
+ {
+ throw new ezcGraphNoSuchDataSetException( $key );
+ }
+
+ return $this->data[$key];
+ }
+
+ /**
+ * Set the element with the given offset.
+ *
+ * This method is part of the ArrayAccess interface to allow access to the
+ * data of this object as if it was an array.
+ *
+ * @param string $key Identifier of dataset
+ * @param ezcGraphDataSet$value The dataset to assign.
+ * @return void
+ *
+ * @throws ezcGraphUnknownDataSetSourceException
+ * If supplied value is not an ezcGraphDataSet
+ */
+ public function offsetSet( $key, $value )
+ {
+ if ( !$value instanceof ezcGraphDataSet )
+ {
+ throw new ezcGraphUnknownDataSetSourceException( $value );
+ }
+
+ return $this->addDataSet( $key, $value );
+ }
+
+ /**
+ * Unset the element with the given offset.
+ *
+ * This method is part of the ArrayAccess interface to allow access to the
+ * data of this object as if it was an array.
+ *
+ * @param int $offset The offset to unset the value for.
+ * @return void
+ */
+ public function offsetUnset( $key )
+ {
+ if ( !isset( $key ) )
+ {
+ throw new ezcGraphNoSuchDataSetException( $key );
+ }
+
+ unset( $this->data[$key] );
+ }
+
+ /**
+ * Returns the currently selected dataset.
+ *
+ * This method is part of the Iterator interface to allow access to the
+ * datasets of this row by iterating over it like an array (e.g. using
+ * foreach).
+ *
+ * @return ezcGraphDataSet The currently selected dataset.
+ */
+ public function current()
+ {
+ return current( $this->data );
+ }
+
+ /**
+ * Returns the next dataset and selects it or false on the last dataset.
+ *
+ * This method is part of the Iterator interface to allow access to the
+ * datasets of this row by iterating over it like an array (e.g. using
+ * foreach).
+ *
+ * @return mixed ezcGraphDataSet if the next dataset exists, or false.
+ */
+ public function next()
+ {
+ return next( $this->data );
+ }
+
+ /**
+ * Returns the key of the currently selected dataset.
+ *
+ * This method is part of the Iterator interface to allow access to the
+ * datasets of this row by iterating over it like an array (e.g. using
+ * foreach).
+ *
+ * @return int The key of the currently selected dataset.
+ */
+ public function key()
+ {
+ return key( $this->data );
+ }
+
+ /**
+ * Returns if the current dataset is valid.
+ *
+ * This method is part of the Iterator interface to allow access to the
+ * datasets of this row by iterating over it like an array (e.g. using
+ * foreach).
+ *
+ * @return bool If the current dataset is valid
+ */
+ public function valid()
+ {
+ return ( current( $this->data ) !== false );
+ }
+
+ /**
+ * Selects the very first dataset and returns it.
+ * This method is part of the Iterator interface to allow access to the
+ * datasets of this row by iterating over it like an array (e.g. using
+ * foreach).
+ *
+ * @return ezcGraphDataSet The very first dataset.
+ */
+ public function rewind()
+ {
+ return reset( $this->data );
+ }
+
+ /**
+ * Returns the number of datasets in the row.
+ *
+ * This method is part of the Countable interface to allow the usage of
+ * PHP's count() function to check how many datasets exist.
+ *
+ * @return int Number of datasets.
+ */
+ public function count()
+ {
+ return count( $this->data );
+ }
+}
+?>
diff --git a/src/data_container/single.php b/src/data_container/single.php
new file mode 100644
index 0000000..5167511
--- /dev/null
+++ b/src/data_container/single.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * File containing the abstract ezcGraphChart 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
+ */
+/**
+ * Class containing the container for the charts datasets
+ *
+ * @package Graph
+ */
+
+class ezcGraphChartSingleDataContainer extends ezcGraphChartDataContainer
+{
+ /**
+ * Adds a dataset to the charts data
+ *
+ * @param string $name Name of dataset
+ * @param mixed $values Values to create dataset with
+ * @throws ezcGraphTooManyDataSetExceptions
+ * If too many datasets are created
+ * @return ezcGraphDataSet
+ */
+ protected function addDataSet( $name, ezcGraphDataSet $dataSet )
+ {
+ if ( count( $this->data ) >= 1 &&
+ !isset( $this->data[$name] ) )
+ {
+ throw new ezcGraphTooManyDataSetsExceptions( $name );
+ }
+ else
+ {
+ parent::addDataSet( $name, $dataSet );
+
+ // Colorize each data element
+ foreach ( $this->data[$name] as $label => $value )
+ {
+ $this->data[$name]->color[$label] = $this->chart->palette->dataSetColor;
+ }
+ }
+ }
+}
+?>
diff --git a/src/driver/svg.php b/src/driver/svg.php
index 53bb73c..2b5ff90 100644
--- a/src/driver/svg.php
+++ b/src/driver/svg.php
@@ -60,6 +60,7 @@ class ezcGraphSvgDriver extends ezcGraphDriver
if ( $this->options->templateDocument !== false )
{
$this->dom = new DOMDocument();
+// @TODO: Add $this->dom->format
$this->dom->load( $this->options->templateDocument );
$this->defs = $this->dom->getElementsByTagName( 'defs' )->item( 0 );
diff --git a/src/element/legend.php b/src/element/legend.php
index 952bfc1..8f0458c 100644
--- a/src/element/legend.php
+++ b/src/element/legend.php
@@ -117,10 +117,10 @@ class ezcGraphChartElementLegend extends ezcGraphChartElement
* @param array $datasets
* @return void
*/
- public function generateFromDataSets(array $datasets)
+ public function generateFromDataSets( ezcGraphChartDataContainer $datasets )
{
$this->labels = array();
- foreach ($datasets as $dataset)
+ foreach ( $datasets as $dataset )
{
$this->labels[] = array(
'label' => $dataset->label->default,
@@ -138,10 +138,10 @@ class ezcGraphChartElementLegend extends ezcGraphChartElement
* @param ezcGraphDataSet $dataset
* @return void
*/
- public function generateFromDataSet(ezcGraphDataSet $dataset)
+ public function generateFromDataSet( ezcGraphDataSet $dataset )
{
$this->labels = array();
- foreach ($dataset as $label => $data)
+ foreach ( $dataset as $label => $data )
{
$this->labels[] = array(
'label' => $label,
diff --git a/src/graph_autoload.php b/src/graph_autoload.php
index 188a38a..f8a1693 100644
--- a/src/graph_autoload.php
+++ b/src/graph_autoload.php
@@ -22,6 +22,9 @@ return array(
'ezcGraphLineChartOptions' => 'Graph/options/line_chart.php',
'ezcGraphInvalidImageFileException' => 'Graph/exceptions/invalid_image_file.php',
+ 'ezcGraphChartDataContainer' => 'Graph/data_container/base.php',
+ 'ezcGraphChartSingleDataContainer' => 'Graph/data_container/single.php',
+
'ezcGraphColor' => 'Graph/structs/color.php',
'ezcGraphUnknownColorDefinitionException' => 'Graph/exceptions/unknown_color_definition.php',
diff --git a/src/interfaces/chart.php b/src/interfaces/chart.php
index d87ad37..828a77b 100644
--- a/src/interfaces/chart.php
+++ b/src/interfaces/chart.php
@@ -12,7 +12,7 @@
*
* @package Graph
*/
-abstract class ezcGraphChart implements ArrayAccess
+abstract class ezcGraphChart
{
/**
@@ -32,9 +32,9 @@ abstract class ezcGraphChart implements ArrayAccess
/**
* Contains the data of the chart
*
- * @var array( ezcGraphDataSet )
+ * @var ezcGraphChartDataContainer
*/
- protected $data = array();
+ protected $data;
/**
* Renderer for the chart
@@ -68,6 +68,8 @@ abstract class ezcGraphChart implements ArrayAccess
{
$this->__set( 'palette', new ezcGraphPaletteTango() );
+ $this->data = new ezcGraphChartDataContainer( $this );
+
// Add standard elements
$this->addElement( 'background', new ezcGraphChartElementBackground() );
$this->elements['background']->position = ezcGraph::CENTER | ezcGraph::MIDDLE;
@@ -186,24 +188,6 @@ abstract class ezcGraphChart implements ArrayAccess
}
/**
- * Adds a dataset to the charts data
- *
- * @param string $name Name of dataset
- * @param mixed $values Values to create dataset with
- * @throws ezcGraphTooManyDataSetExceptions
- * If too many datasets are created
- * @return ezcGraphDataSet
- */
- protected function addDataSet( $name, ezcGraphDataSet $dataSet )
- {
- $this->data[$name] = $dataSet;
-
- $this->data[$name]->label = $name;
- $this->data[$name]->palette = $this->palette;
- $this->data[$name]->displayType = $this->getDefaultDisplayType();
- }
-
- /**
* Returns the requested property
*
* @param mixed $propertyName
@@ -221,7 +205,7 @@ abstract class ezcGraphChart implements ArrayAccess
return $this->elements[$propertyName];
}
- if ( $propertyName === "options" )
+ if ( $propertyName === 'options' )
{
return $this->options;
}
@@ -231,41 +215,6 @@ abstract class ezcGraphChart implements ArrayAccess
}
}
- public function offsetExists( $key )
- {
- return isset( $this->data[$key] );
- }
-
- public function offsetGet( $key )
- {
- if ( !isset( $key ) )
- {
- throw new ezcGraphNoSuchDataSetException( $key );
- }
-
- return $this->data[$key];
- }
-
- public function offsetSet( $key, $value )
- {
- if ( !$value instanceof ezcGraphDataSet )
- {
- throw new ezcGraphUnknownDataSetSourceException( $value );
- }
-
- return $this->addDataSet( $key, $value );
- }
-
- public function offsetUnset( $key )
- {
- if ( !isset( $key ) )
- {
- throw new ezcGraphNoSuchDataSetException( $key );
- }
-
- unset( $this->data[$key] );
- }
-
public function setOptions( $options )
{
if ( is_array( $options ) )
@@ -287,7 +236,7 @@ abstract class ezcGraphChart implements ArrayAccess
*
* @return int Display type
*/
- abstract protected function getDefaultDisplayType();
+ abstract public function getDefaultDisplayType();
/**
* Renders this chart
OpenPOWER on IntegriCloud