mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-24 02:12:17 +00:00
EZ-Components
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the ezcGraphArrayDataSet class
|
||||
*
|
||||
* @package Graph
|
||||
* @version 1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
/**
|
||||
* Dataset class which receives arrays and use them as a base for datasets.
|
||||
*
|
||||
* @version 1.3
|
||||
* @package Graph
|
||||
* @mainclass
|
||||
*/
|
||||
class ezcGraphArrayDataSet extends ezcGraphDataSet
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|Iterator $data Array or Iterator containing the data
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $data )
|
||||
{
|
||||
$this->createFromArray( $data );
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* setData
|
||||
*
|
||||
* Can handle data provided through an array or iterator.
|
||||
*
|
||||
* @param array|Iterator $data
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
protected function createFromArray( $data = array() )
|
||||
{
|
||||
if ( !is_array( $data ) &&
|
||||
!( $data instanceof Traversable ) )
|
||||
{
|
||||
throw new ezcGraphInvalidArrayDataSourceException( $data );
|
||||
}
|
||||
|
||||
$this->data = array();
|
||||
foreach ( $data as $key => $value )
|
||||
{
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
|
||||
if ( !count( $this->data ) )
|
||||
{
|
||||
throw new ezcGraphInvalidDataException( 'Data sets should contain some values.' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements in this dataset
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count( $this->data );
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,359 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the ezcGraphDataSetAverage class
|
||||
*
|
||||
* @package Graph
|
||||
* @version 1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
/**
|
||||
* Extension of basic dataset to represent averation.
|
||||
* Algorithm: http://en.wikipedia.org/wiki/Least_squares
|
||||
*
|
||||
* @property int $polynomOrder
|
||||
* Maximum order of polygon to interpolate from points
|
||||
* @property int $resolution
|
||||
* Resolution used to draw line in graph
|
||||
*
|
||||
* @version 1.3
|
||||
* @package Graph
|
||||
* @mainclass
|
||||
*/
|
||||
class ezcGraphDataSetAveragePolynom extends ezcGraphDataSet
|
||||
{
|
||||
|
||||
/**
|
||||
* Source dataset to base averation on.
|
||||
*
|
||||
* @var ezcGraphDataSet
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* Calculated averation polynom
|
||||
*
|
||||
* @var ezcGraphPolynom
|
||||
*/
|
||||
protected $polynom = false;
|
||||
|
||||
/**
|
||||
* Minimum key
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
protected $min = false;
|
||||
|
||||
/**
|
||||
* Maximum key
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
protected $max = false;
|
||||
|
||||
/**
|
||||
* Position of the data iterator. Depends on the configured resolution.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $position = 0;
|
||||
|
||||
/**
|
||||
* Container to hold the properties
|
||||
*
|
||||
* @var array(string=>mixed)
|
||||
*/
|
||||
protected $properties;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ezcGraphDataSet $dataset Dataset to interpolate
|
||||
* @param int $order Maximum order of interpolating polynom
|
||||
* @return void
|
||||
* @ignore
|
||||
*/
|
||||
public function __construct( ezcGraphDataSet $dataset, $order = 3 )
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->properties['resolution'] = 100;
|
||||
$this->properties['polynomOrder'] = (int) $order;
|
||||
|
||||
$this->source = $dataset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options write access
|
||||
*
|
||||
* @throws ezcBasePropertyNotFoundException
|
||||
* If Option could not be found
|
||||
* @throws ezcBaseValueException
|
||||
* If value is out of range
|
||||
* @param mixed $propertyName Option name
|
||||
* @param mixed $propertyValue Option value;
|
||||
* @return mixed
|
||||
*/
|
||||
public function __set( $propertyName, $propertyValue )
|
||||
{
|
||||
switch ( $propertyName ) {
|
||||
case 'polynomOrder':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue < 0 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'int > 0' );
|
||||
}
|
||||
|
||||
$this->properties['polynomOrder'] = (int) $propertyValue;
|
||||
$this->polynom = false;
|
||||
break;
|
||||
case 'resolution':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue < 1 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'int > 1' );
|
||||
}
|
||||
|
||||
$this->properties['resolution'] = (int) $propertyValue;
|
||||
break;
|
||||
default:
|
||||
parent::__set( $propertyName, $propertyValue );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Property get access.
|
||||
* Simply returns a given option.
|
||||
*
|
||||
* @param string $propertyName The name of the option to get.
|
||||
* @return mixed The option value.
|
||||
*
|
||||
* @throws ezcBasePropertyNotFoundException
|
||||
* If a the value for the property options is not an instance of
|
||||
*/
|
||||
public function __get( $propertyName )
|
||||
{
|
||||
if ( array_key_exists( $propertyName, $this->properties ) )
|
||||
{
|
||||
return $this->properties[$propertyName];
|
||||
}
|
||||
return parent::__get( $propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the polynom based on the given points.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function buildPolynom()
|
||||
{
|
||||
$points = array();
|
||||
|
||||
foreach ( $this->source as $key => $value )
|
||||
{
|
||||
if ( !is_numeric( $key ) )
|
||||
{
|
||||
throw new ezcGraphDatasetAverageInvalidKeysException();
|
||||
}
|
||||
|
||||
if ( ( $this->min === false ) || ( $this->min > $key ) )
|
||||
{
|
||||
$this->min = (float) $key;
|
||||
}
|
||||
|
||||
if ( ( $this->max === false ) || ( $this->max < $key ) )
|
||||
{
|
||||
$this->max = (float) $key;
|
||||
}
|
||||
|
||||
$points[] = new ezcGraphCoordinate( (float) $key, (float) $value );
|
||||
}
|
||||
|
||||
// Build transposed and normal Matrix out of coordiantes
|
||||
$a = new ezcGraphMatrix( count( $points ), $this->polynomOrder + 1 );
|
||||
$b = new ezcGraphMatrix( count( $points ), 1 );
|
||||
|
||||
for ( $i = 0; $i <= $this->properties['polynomOrder']; ++$i )
|
||||
{
|
||||
foreach ( $points as $nr => $point )
|
||||
{
|
||||
$a->set( $nr, $i, pow( $point->x, $i ) );
|
||||
$b->set( $nr, 0, $point->y );
|
||||
}
|
||||
}
|
||||
|
||||
$at = clone $a;
|
||||
$at->transpose();
|
||||
|
||||
$left = $at->multiply( $a );
|
||||
$right = $at->multiply( $b );
|
||||
|
||||
$this->polynom = $left->solveNonlinearEquatation( $right );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a polynom of the defined order witch matches the datapoints
|
||||
* using the least squares algorithm.
|
||||
*
|
||||
* @return ezcGraphPolynom Polynom
|
||||
*/
|
||||
public function getPolynom()
|
||||
{
|
||||
if ( $this->polynom === false )
|
||||
{
|
||||
$this->buildPolynom();
|
||||
}
|
||||
|
||||
return $this->polynom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the x coordinate for the current position
|
||||
*
|
||||
* @param int $position Position
|
||||
* @return float x coordinate
|
||||
*/
|
||||
protected function getKey()
|
||||
{
|
||||
$polynom = $this->getPolynom();
|
||||
return $this->min +
|
||||
( $this->max - $this->min ) / $this->resolution * $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given datapoint exists
|
||||
* Allows isset() using ArrayAccess.
|
||||
*
|
||||
* @param string $key The key of the datapoint to get.
|
||||
* @return bool Wether the key exists.
|
||||
*/
|
||||
public function offsetExists( $key )
|
||||
{
|
||||
$polynom = $this->getPolynom();
|
||||
return ( ( $key >= $this->min ) && ( $key <= $this->max ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value for the given datapoint
|
||||
* Get an datapoint value by ArrayAccess.
|
||||
*
|
||||
* @param string $key The key of the datapoint to get.
|
||||
* @return float The datapoint value.
|
||||
*/
|
||||
public function offsetGet( $key )
|
||||
{
|
||||
$polynom = $this->getPolynom();
|
||||
return $polynom->evaluate( $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws a ezcBasePropertyPermissionException because single datapoints
|
||||
* cannot be set in average datasets.
|
||||
*
|
||||
* @param string $key The kex of a datapoint to set.
|
||||
* @param float $value The value for the datapoint.
|
||||
* @throws ezcBasePropertyPermissionException
|
||||
* Always, because access is readonly.
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet( $key, $value )
|
||||
{
|
||||
throw new ezcBasePropertyPermissionException( $key, ezcBasePropertyPermissionException::READ );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently selected datapoint.
|
||||
*
|
||||
* This method is part of the Iterator interface to allow access to the
|
||||
* datapoints of this row by iterating over it like an array (e.g. using
|
||||
* foreach).
|
||||
*
|
||||
* @return string The currently selected datapoint.
|
||||
*/
|
||||
final public function current()
|
||||
{
|
||||
$polynom = $this->getPolynom();
|
||||
return $polynom->evaluate( $this->getKey() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next datapoint and selects it or false on the last datapoint.
|
||||
*
|
||||
* This method is part of the Iterator interface to allow access to the
|
||||
* datapoints of this row by iterating over it like an array (e.g. using
|
||||
* foreach).
|
||||
*
|
||||
* @return float datapoint if it exists, or false.
|
||||
*/
|
||||
final public function next()
|
||||
{
|
||||
if ( ++$this->position >= $this->resolution )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->current();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key of the currently selected datapoint.
|
||||
*
|
||||
* This method is part of the Iterator interface to allow access to the
|
||||
* datapoints of this row by iterating over it like an array (e.g. using
|
||||
* foreach).
|
||||
*
|
||||
* @return string The key of the currently selected datapoint.
|
||||
*/
|
||||
final public function key()
|
||||
{
|
||||
return (string) $this->getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the current datapoint is valid.
|
||||
*
|
||||
* This method is part of the Iterator interface to allow access to the
|
||||
* datapoints of this row by iterating over it like an array (e.g. using
|
||||
* foreach).
|
||||
*
|
||||
* @return bool If the current datapoint is valid
|
||||
*/
|
||||
final public function valid()
|
||||
{
|
||||
$polynom = $this->getPolynom();
|
||||
|
||||
if ( $this->min >= $this->max )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return ( ( $this->getKey() >= $this->min ) && ( $this->getKey() <= $this->max ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the very first datapoint and returns it.
|
||||
* This method is part of the Iterator interface to allow access to the
|
||||
* datapoints of this row by iterating over it like an array (e.g. using
|
||||
* foreach).
|
||||
*
|
||||
* @return float The very first datapoint.
|
||||
*/
|
||||
final public function rewind()
|
||||
{
|
||||
$this->position = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements in this dataset
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->resolution;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,295 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the abstract ezcGraphDataSet class
|
||||
*
|
||||
* @package Graph
|
||||
* @version 1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
* @access private
|
||||
*/
|
||||
/**
|
||||
* Basic class to contain the charts data
|
||||
*
|
||||
* @property string $label
|
||||
* Labels for datapoint and datapoint elements
|
||||
* @property ezcGraphColor $color
|
||||
* Colors for datapoint elements
|
||||
* @property int $symbol
|
||||
* Symbols for datapoint elements
|
||||
* @property bool $highlight
|
||||
* Status if datapoint element is hilighted
|
||||
* @property int $displayType
|
||||
* Display type of chart data
|
||||
* @property string $url
|
||||
* URL associated with datapoint
|
||||
* @property ezcGraphChartElementAxis $xAxis
|
||||
* Associate dataset with a different X axis then the default one
|
||||
* @property ezcGraphChartElementAxis $yAxis
|
||||
* Associate dataset with a different Y axis then the default one
|
||||
*
|
||||
* @version 1.3
|
||||
* @package Graph
|
||||
* @access private
|
||||
*/
|
||||
abstract class ezcGraphDataSet implements ArrayAccess, Iterator, Countable
|
||||
{
|
||||
|
||||
/**
|
||||
* Property array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $properties;
|
||||
|
||||
/**
|
||||
* Array which contains the data of the datapoint
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* Current datapoint element
|
||||
* needed for iteration over datapoint with ArrayAccess
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $current;
|
||||
|
||||
/**
|
||||
* Color palette used for datapoint colorization
|
||||
*
|
||||
* @var ezcGraphPalette
|
||||
*/
|
||||
protected $pallet;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
* @ignore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->properties['label'] = new ezcGraphDataSetStringProperty( $this );
|
||||
$this->properties['color'] = new ezcGraphDataSetColorProperty( $this );
|
||||
$this->properties['symbol'] = new ezcGraphDataSetIntProperty( $this );
|
||||
$this->properties['lineThickness'] = new ezcGraphDataSetIntProperty( $this );
|
||||
$this->properties['highlight'] = new ezcGraphDataSetBooleanProperty( $this );
|
||||
$this->properties['highlightValue'] = new ezcGraphDataSetStringProperty( $this );
|
||||
$this->properties['displayType'] = new ezcGraphDataSetIntProperty( $this );
|
||||
$this->properties['url'] = new ezcGraphDataSetStringProperty( $this );
|
||||
|
||||
$this->properties['xAxis'] = new ezcGraphDataSetAxisProperty( $this );
|
||||
$this->properties['yAxis'] = new ezcGraphDataSetAxisProperty( $this );
|
||||
|
||||
$this->properties['highlight']->default = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options write access
|
||||
*
|
||||
* @throws ezcBasePropertyNotFoundException
|
||||
* If Option could not be found
|
||||
* @throws ezcBaseValueException
|
||||
* If value is out of range
|
||||
* @param mixed $propertyName Option name
|
||||
* @param mixed $propertyValue Option value;
|
||||
* @return void
|
||||
* @ignore
|
||||
*/
|
||||
public function __set( $propertyName, $propertyValue )
|
||||
{
|
||||
switch ( $propertyName )
|
||||
{
|
||||
case 'hilight':
|
||||
$propertyName = 'highlight';
|
||||
case 'label':
|
||||
case 'url':
|
||||
case 'color':
|
||||
case 'symbol':
|
||||
case 'lineThickness':
|
||||
case 'highlight':
|
||||
case 'highlightValue':
|
||||
case 'displayType':
|
||||
case 'xAxis':
|
||||
case 'yAxis':
|
||||
$this->properties[$propertyName]->default = $propertyValue;
|
||||
break;
|
||||
|
||||
case 'palette':
|
||||
$this->palette = $propertyValue;
|
||||
$this->color->default = $this->palette->dataSetColor;
|
||||
$this->symbol->default = $this->palette->dataSetSymbol;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ezcBasePropertyNotFoundException( $propertyName );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Property get access.
|
||||
* Simply returns a given option.
|
||||
*
|
||||
* @param string $propertyName The name of the option to get.
|
||||
* @return mixed The option value.
|
||||
*
|
||||
* @throws ezcBasePropertyNotFoundException
|
||||
* If a the value for the property options is not an instance of
|
||||
*/
|
||||
public function __get( $propertyName )
|
||||
{
|
||||
if ( array_key_exists( $propertyName, $this->properties ) )
|
||||
{
|
||||
return $this->properties[$propertyName];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ezcBasePropertyNotFoundException( $propertyName );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given datapoint exists
|
||||
* Allows isset() using ArrayAccess.
|
||||
*
|
||||
* @param string $key The key of the datapoint to get.
|
||||
* @return bool Wether the key exists.
|
||||
*/
|
||||
public function offsetExists( $key )
|
||||
{
|
||||
return isset( $this->data[$key] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value for the given datapoint
|
||||
* Get an datapoint value by ArrayAccess.
|
||||
*
|
||||
* @param string $key The key of the datapoint to get.
|
||||
* @return float The datapoint value.
|
||||
*/
|
||||
public function offsetGet( $key )
|
||||
{
|
||||
return $this->data[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value for a datapoint.
|
||||
* Sets an datapoint using ArrayAccess.
|
||||
*
|
||||
* @param string $key The kex of a datapoint to set.
|
||||
* @param float $value The value for the datapoint.
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet( $key, $value )
|
||||
{
|
||||
$this->data[$key] = (float) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset an option.
|
||||
* Unsets an option using ArrayAccess.
|
||||
*
|
||||
* @param string $key The options to unset.
|
||||
* @return void
|
||||
*
|
||||
* @throws ezcBasePropertyNotFoundException
|
||||
* If a the value for the property options is not an instance of
|
||||
* @throws ezcBaseValueException
|
||||
* If a the value for a property is out of range.
|
||||
*/
|
||||
public function offsetUnset( $key )
|
||||
{
|
||||
unset( $this->data[$key] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently selected datapoint.
|
||||
*
|
||||
* This method is part of the Iterator interface to allow access to the
|
||||
* datapoints of this row by iterating over it like an array (e.g. using
|
||||
* foreach).
|
||||
*
|
||||
* @return string The currently selected datapoint.
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
$keys = array_keys( $this->data );
|
||||
if ( !isset( $this->current ) )
|
||||
{
|
||||
$this->current = 0;
|
||||
}
|
||||
|
||||
return $this->data[$keys[$this->current]];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next datapoint and selects it or false on the last datapoint.
|
||||
*
|
||||
* This method is part of the Iterator interface to allow access to the
|
||||
* datapoints of this row by iterating over it like an array (e.g. using
|
||||
* foreach).
|
||||
*
|
||||
* @return float datapoint if it exists, or false.
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
$keys = array_keys( $this->data );
|
||||
if ( ++$this->current >= count( $keys ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->data[$keys[$this->current]];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key of the currently selected datapoint.
|
||||
*
|
||||
* This method is part of the Iterator interface to allow access to the
|
||||
* datapoints of this row by iterating over it like an array (e.g. using
|
||||
* foreach).
|
||||
*
|
||||
* @return string The key of the currently selected datapoint.
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
$keys = array_keys( $this->data );
|
||||
return $keys[$this->current];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the current datapoint is valid.
|
||||
*
|
||||
* This method is part of the Iterator interface to allow access to the
|
||||
* datapoints of this row by iterating over it like an array (e.g. using
|
||||
* foreach).
|
||||
*
|
||||
* @return bool If the current datapoint is valid
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
$keys = array_keys( $this->data );
|
||||
return isset( $keys[$this->current] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the very first datapoint and returns it.
|
||||
* This method is part of the Iterator interface to allow access to the
|
||||
* datapoints of this row by iterating over it like an array (e.g. using
|
||||
* foreach).
|
||||
*
|
||||
* @return float The very first datapoint.
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
$this->current = 0;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,287 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the ezcGraphNumericDataSet class
|
||||
*
|
||||
* @package Graph
|
||||
* @version 1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
/**
|
||||
* Dataset for numeric data.
|
||||
*
|
||||
* Uses user defined functions for numeric data creation
|
||||
*
|
||||
* @property float $start
|
||||
* Start value for x axis values of function
|
||||
* @property float $end
|
||||
* End value for x axis values of function
|
||||
* @property callback $callback
|
||||
* Callback function which represents the mathmatical function to
|
||||
* show
|
||||
* @property int $resolution
|
||||
* Steps used to draw line in graph
|
||||
*
|
||||
* @version 1.3
|
||||
* @package Graph
|
||||
* @mainclass
|
||||
*/
|
||||
class ezcGraphNumericDataSet extends ezcGraphDataSet
|
||||
{
|
||||
/**
|
||||
* Position of the data iterator. Depends on the configured resolution.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $position = 0;
|
||||
|
||||
/**
|
||||
* Container to hold the properties
|
||||
*
|
||||
* @var array(string=>mixed)
|
||||
*/
|
||||
protected $properties;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param float $start Start value for x axis values of function
|
||||
* @param float $end End value for x axis values of function
|
||||
* @param callback $callback Callback function
|
||||
* @return void
|
||||
* @ignore
|
||||
*/
|
||||
public function __construct( $start = null, $end = null, $callback = null )
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->properties['start'] = null;
|
||||
$this->properties['end'] = null;
|
||||
$this->properties['callback'] = null;
|
||||
|
||||
if ( $start !== null )
|
||||
{
|
||||
$this->start = $start;
|
||||
}
|
||||
|
||||
if ( $end !== null )
|
||||
{
|
||||
$this->end = $end;
|
||||
}
|
||||
|
||||
if ( $callback !== null )
|
||||
{
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
$this->properties['resolution'] = 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options write access
|
||||
*
|
||||
* @throws ezcBasePropertyNotFoundException
|
||||
* If Option could not be found
|
||||
* @throws ezcBaseValueException
|
||||
* If value is out of range
|
||||
* @param mixed $propertyName Option name
|
||||
* @param mixed $propertyValue Option value;
|
||||
* @return mixed
|
||||
*/
|
||||
public function __set( $propertyName, $propertyValue )
|
||||
{
|
||||
switch ( $propertyName ) {
|
||||
case 'resolution':
|
||||
if ( !is_numeric( $propertyValue ) ||
|
||||
( $propertyValue < 1 ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'int > 1' );
|
||||
}
|
||||
|
||||
$this->properties['resolution'] = (int) $propertyValue;
|
||||
break;
|
||||
case 'start':
|
||||
case 'end':
|
||||
if ( !is_numeric( $propertyValue ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'float' );
|
||||
}
|
||||
|
||||
$this->properties[$propertyName] = (float) $propertyValue;
|
||||
break;
|
||||
case 'callback':
|
||||
if ( !is_callable( $propertyValue ) )
|
||||
{
|
||||
throw new ezcBaseValueException( $propertyName, $propertyValue, 'callback' );
|
||||
}
|
||||
|
||||
$this->properties[$propertyName] = $propertyValue;
|
||||
break;
|
||||
default:
|
||||
parent::__set( $propertyName, $propertyValue );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Property get access.
|
||||
* Simply returns a given option.
|
||||
*
|
||||
* @param string $propertyName The name of the option to get.
|
||||
* @return mixed The option value.
|
||||
*
|
||||
* @throws ezcBasePropertyNotFoundException
|
||||
* If a the value for the property options is not an instance of
|
||||
*/
|
||||
public function __get( $propertyName )
|
||||
{
|
||||
if ( array_key_exists( $propertyName, $this->properties ) )
|
||||
{
|
||||
return $this->properties[$propertyName];
|
||||
}
|
||||
return parent::__get( $propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the x coordinate for the current position
|
||||
*
|
||||
* @param int $position Position
|
||||
* @return float x coordinate
|
||||
*/
|
||||
protected function getKey()
|
||||
{
|
||||
return $this->start +
|
||||
( $this->end - $this->start ) / $this->resolution * $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given datapoint exists
|
||||
* Allows isset() using ArrayAccess.
|
||||
*
|
||||
* @param string $key The key of the datapoint to get.
|
||||
* @return bool Wether the key exists.
|
||||
*/
|
||||
public function offsetExists( $key )
|
||||
{
|
||||
return ( ( $key >= $this->start ) && ( $key <= $this->end ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value for the given datapoint
|
||||
* Get an datapoint value by ArrayAccess.
|
||||
*
|
||||
* @param string $key The key of the datapoint to get.
|
||||
* @return float The datapoint value.
|
||||
*/
|
||||
public function offsetGet( $key )
|
||||
{
|
||||
return call_user_func( $this->callback, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws a ezcBasePropertyPermissionException because single datapoints
|
||||
* cannot be set in average datasets.
|
||||
*
|
||||
* @param string $key The kex of a datapoint to set.
|
||||
* @param float $value The value for the datapoint.
|
||||
* @throws ezcBasePropertyPermissionException
|
||||
* Always, because access is readonly.
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet( $key, $value )
|
||||
{
|
||||
throw new ezcBasePropertyPermissionException( $key, ezcBasePropertyPermissionException::READ );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently selected datapoint.
|
||||
*
|
||||
* This method is part of the Iterator interface to allow access to the
|
||||
* datapoints of this row by iterating over it like an array (e.g. using
|
||||
* foreach).
|
||||
*
|
||||
* @return string The currently selected datapoint.
|
||||
*/
|
||||
final public function current()
|
||||
{
|
||||
return call_user_func( $this->callback, $this->getKey() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next datapoint and selects it or false on the last datapoint.
|
||||
*
|
||||
* This method is part of the Iterator interface to allow access to the
|
||||
* datapoints of this row by iterating over it like an array (e.g. using
|
||||
* foreach).
|
||||
*
|
||||
* @return float datapoint if it exists, or false.
|
||||
*/
|
||||
final public function next()
|
||||
{
|
||||
if ( $this->start === $this->end )
|
||||
{
|
||||
throw new ezcGraphDatasetAverageInvalidKeysException();
|
||||
}
|
||||
|
||||
if ( ++$this->position >= $this->resolution )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->current();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key of the currently selected datapoint.
|
||||
*
|
||||
* This method is part of the Iterator interface to allow access to the
|
||||
* datapoints of this row by iterating over it like an array (e.g. using
|
||||
* foreach).
|
||||
*
|
||||
* @return string The key of the currently selected datapoint.
|
||||
*/
|
||||
final public function key()
|
||||
{
|
||||
return (string) $this->getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the current datapoint is valid.
|
||||
*
|
||||
* This method is part of the Iterator interface to allow access to the
|
||||
* datapoints of this row by iterating over it like an array (e.g. using
|
||||
* foreach).
|
||||
*
|
||||
* @return bool If the current datapoint is valid
|
||||
*/
|
||||
final public function valid()
|
||||
{
|
||||
return ( ( $this->getKey() >= $this->start ) && ( $this->getKey() <= $this->end ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the very first datapoint and returns it.
|
||||
* This method is part of the Iterator interface to allow access to the
|
||||
* datapoints of this row by iterating over it like an array (e.g. using
|
||||
* foreach).
|
||||
*
|
||||
* @return float The very first datapoint.
|
||||
*/
|
||||
final public function rewind()
|
||||
{
|
||||
$this->position = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements in this dataset
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->resolution + 1;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the abstract ezcGraphDataSetIntProperty class
|
||||
*
|
||||
* @package Graph
|
||||
* @version 1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
/**
|
||||
* Class for axis properties of datasets
|
||||
*
|
||||
* @version 1.3
|
||||
* @package Graph
|
||||
*/
|
||||
class ezcGraphDataSetAxisProperty extends ezcGraphDataSetProperty
|
||||
{
|
||||
/**
|
||||
* Chacks if value is really an axis
|
||||
*
|
||||
* @param ezcGraphChartElementAxis $value
|
||||
* @return void
|
||||
*/
|
||||
protected function checkValue( &$value )
|
||||
{
|
||||
if ( ! $value instanceof ezcGraphChartElementAxis )
|
||||
{
|
||||
throw new ezcBaseValueException( 'default', $value, 'ezcGraphChartElementAxis' );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an option.
|
||||
*
|
||||
* Sets an option using ArrayAccess.
|
||||
*
|
||||
* This is deaktivated, because you need not set a different axis for some
|
||||
* data point.
|
||||
*
|
||||
* @param string $key The option to set.
|
||||
* @param mixed $value The value for the option.
|
||||
* @return void
|
||||
*
|
||||
* @throws ezcGraphInvalidAssignementException
|
||||
* Always
|
||||
*/
|
||||
public function offsetSet( $key, $value )
|
||||
{
|
||||
throw new ezcGraphInvalidAssignementException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the abstract ezcGraphDataSetBooleanProperty class
|
||||
*
|
||||
* @package Graph
|
||||
* @version 1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
/**
|
||||
* Class for integer properties of datasets
|
||||
*
|
||||
* @version 1.3
|
||||
* @package Graph
|
||||
*/
|
||||
class ezcGraphDataSetBooleanProperty extends ezcGraphDataSetProperty
|
||||
{
|
||||
/**
|
||||
* Converts value to an {@link ezcGraphColor} object
|
||||
*
|
||||
* @param & $value
|
||||
* @return void
|
||||
*/
|
||||
protected function checkValue( &$value )
|
||||
{
|
||||
$value = (bool) $value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the abstract ezcGraphDataSetColorProperty class
|
||||
*
|
||||
* @package Graph
|
||||
* @version 1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
/**
|
||||
* Class for color properties of datasets
|
||||
*
|
||||
* @version 1.3
|
||||
* @package Graph
|
||||
*/
|
||||
class ezcGraphDataSetColorProperty extends ezcGraphDataSetProperty
|
||||
{
|
||||
/**
|
||||
* Converts value to an {@link ezcGraphColor} object
|
||||
*
|
||||
* @param & $value
|
||||
* @return void
|
||||
*/
|
||||
protected function checkValue( &$value )
|
||||
{
|
||||
$value = ezcGraphColor::create( $value );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the abstract ezcGraphDataSetIntProperty class
|
||||
*
|
||||
* @package Graph
|
||||
* @version 1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
/**
|
||||
* Class for integer properties of datasets
|
||||
*
|
||||
* @version 1.3
|
||||
* @package Graph
|
||||
*/
|
||||
class ezcGraphDataSetIntProperty extends ezcGraphDataSetProperty
|
||||
{
|
||||
/**
|
||||
* Converts value to an {@link ezcGraphColor} object
|
||||
*
|
||||
* @param & $value
|
||||
* @return void
|
||||
*/
|
||||
protected function checkValue( &$value )
|
||||
{
|
||||
$value = (int) $value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the abstract ezcGraphDataSetStringProperty class
|
||||
*
|
||||
* @package Graph
|
||||
* @version 1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
/**
|
||||
* Class for string properties of datasets
|
||||
*
|
||||
* @version 1.3
|
||||
* @package Graph
|
||||
*/
|
||||
class ezcGraphDataSetStringProperty extends ezcGraphDataSetProperty
|
||||
{
|
||||
/**
|
||||
* Converts value to an {@link ezcGraphColor} object
|
||||
*
|
||||
* @param & $value
|
||||
* @return void
|
||||
*/
|
||||
protected function checkValue( &$value )
|
||||
{
|
||||
$value = (string) $value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user