[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/library/ezc/Graph/src/datasets/ -> base.php (source)

   1  <?php
   2  /**
   3   * File containing the abstract ezcGraphDataSet class
   4   *
   5   * @package Graph
   6   * @version 1.5
   7   * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
   8   * @license http://ez.no/licenses/new_bsd New BSD License
   9   * @access private
  10   */
  11  /**
  12   * Basic class to contain the charts data
  13   *
  14   * @property string $label
  15   *           Labels for datapoint and datapoint elements
  16   * @property ezcGraphColor $color
  17   *           Colors for datapoint elements
  18   * @property int $symbol
  19   *           Symbols for datapoint elements
  20   * @property string $highlightValue
  21   *           Displayed string if a data point is highlighted
  22   * @property bool $highlight
  23   *           Status if datapoint element is hilighted
  24   * @property int $displayType
  25   *           Display type of chart data
  26   * @property string $url
  27   *           URL associated with datapoint
  28   * @property ezcGraphChartElementAxis $xAxis
  29   *           Associate dataset with a different X axis then the default one
  30   * @property ezcGraphChartElementAxis $yAxis
  31   *           Associate dataset with a different Y axis then the default one
  32   *
  33   * @version 1.5
  34   * @package Graph
  35   * @mainclass
  36   */
  37  abstract class ezcGraphDataSet implements ArrayAccess, Iterator, Countable
  38  {
  39  
  40      /**
  41       * Property array
  42       * 
  43       * @var array
  44       */
  45      protected $properties;
  46  
  47      /**
  48       * Array which contains the data of the datapoint
  49       * 
  50       * @var array
  51       */
  52      protected $data;
  53  
  54      /**
  55       * Current datapoint element
  56       * needed for iteration over datapoint with ArrayAccess
  57       * 
  58       * @var mixed
  59       */
  60      protected $current;
  61  
  62      /**
  63       * Color palette used for datapoint colorization
  64       * 
  65       * @var ezcGraphPalette
  66       */
  67      protected $pallet;
  68  
  69      /**
  70       * Array keys
  71       * 
  72       * @var array
  73       */
  74      protected $keys;
  75  
  76      /**
  77       * Constructor
  78       * 
  79       * @return void
  80       * @ignore
  81       */
  82      public function __construct()
  83      {
  84          $this->properties['label'] = new ezcGraphDataSetStringProperty( $this );
  85          $this->properties['color'] = new ezcGraphDataSetColorProperty( $this );
  86          $this->properties['symbol'] = new ezcGraphDataSetIntProperty( $this );
  87          $this->properties['lineThickness'] = new ezcGraphDataSetIntProperty( $this );
  88          $this->properties['highlight'] = new ezcGraphDataSetBooleanProperty( $this );
  89          $this->properties['highlightValue'] = new ezcGraphDataSetStringProperty( $this );
  90          $this->properties['displayType'] = new ezcGraphDataSetIntProperty( $this );
  91          $this->properties['url'] = new ezcGraphDataSetStringProperty( $this );
  92  
  93          $this->properties['xAxis'] = new ezcGraphDataSetAxisProperty( $this );
  94          $this->properties['yAxis'] = new ezcGraphDataSetAxisProperty( $this );
  95  
  96          $this->properties['highlight']->default = false;
  97      }
  98  
  99      /**
 100       * Options write access
 101       * 
 102       * @throws ezcBasePropertyNotFoundException
 103       *          If Option could not be found
 104       * @throws ezcBaseValueException
 105       *          If value is out of range
 106       * @param mixed $propertyName   Option name
 107       * @param mixed $propertyValue  Option value;
 108       * @return void
 109       * @ignore
 110       */
 111      public function __set( $propertyName, $propertyValue )
 112      {
 113          switch ( $propertyName )
 114          {
 115              case 'hilight':
 116                  $propertyName = 'highlight';
 117              case 'label':
 118              case 'url':
 119              case 'color':
 120              case 'symbol':
 121              case 'lineThickness':
 122              case 'highlight':
 123              case 'highlightValue':
 124              case 'displayType':
 125              case 'xAxis':
 126              case 'yAxis':
 127                  $this->properties[$propertyName]->default = $propertyValue;
 128                  break;
 129  
 130              case 'palette':
 131                  $this->palette = $propertyValue;
 132                  $this->color->default = $this->palette->dataSetColor;
 133                  $this->symbol->default = $this->palette->dataSetSymbol;
 134                  break;
 135  
 136              default:
 137                  throw new ezcBasePropertyNotFoundException( $propertyName );
 138                  break;
 139          }
 140      }
 141  
 142      /**
 143       * Property get access.
 144       * Simply returns a given option.
 145       * 
 146       * @param string $propertyName The name of the option to get.
 147       * @return mixed The option value.
 148       *
 149       * @throws ezcBasePropertyNotFoundException
 150       *         If a the value for the property options is not an instance of
 151       */
 152      public function __get( $propertyName )
 153      {
 154          if ( array_key_exists( $propertyName, $this->properties ) )
 155          {
 156              return $this->properties[$propertyName];
 157          }
 158          else 
 159          {
 160              throw new ezcBasePropertyNotFoundException( $propertyName );
 161          }
 162      }
 163      
 164      /**
 165       * Returns true if the given datapoint exists
 166       * Allows isset() using ArrayAccess.
 167       * 
 168       * @param string $key The key of the datapoint to get.
 169       * @return bool Wether the key exists.
 170       */
 171      public function offsetExists( $key )
 172      {
 173          return isset( $this->data[$key] );
 174      }
 175  
 176      /**
 177       * Returns the value for the given datapoint
 178       * Get an datapoint value by ArrayAccess.
 179       * 
 180       * @param string $key The key of the datapoint to get.
 181       * @return float The datapoint value.
 182       */
 183      public function offsetGet( $key )
 184      {
 185          return $this->data[$key];
 186      }
 187  
 188      /**
 189       * Sets the value for a datapoint.
 190       * Sets an datapoint using ArrayAccess.
 191       * 
 192       * @param string $key The kex of a datapoint to set.
 193       * @param float $value The value for the datapoint.
 194       * @return void
 195       */
 196      public function offsetSet( $key, $value )
 197      {
 198          $this->data[$key] = (float) $value;
 199      }
 200  
 201      /**
 202       * Unset an option.
 203       * Unsets an option using ArrayAccess.
 204       * 
 205       * @param string $key The options to unset.
 206       * @return void
 207       *
 208       * @throws ezcBasePropertyNotFoundException
 209       *         If a the value for the property options is not an instance of
 210       * @throws ezcBaseValueException
 211       *         If a the value for a property is out of range.
 212       */
 213      public function offsetUnset( $key )
 214      {
 215          unset( $this->data[$key] );
 216      }
 217  
 218      /**
 219       * Returns the currently selected datapoint.
 220       *
 221       * This method is part of the Iterator interface to allow access to the 
 222       * datapoints of this row by iterating over it like an array (e.g. using
 223       * foreach).
 224       * 
 225       * @return string The currently selected datapoint.
 226       */
 227      public function current()
 228      {
 229          if ( !isset( $this->current ) )
 230          {
 231              $this->keys    = array_keys( $this->data );
 232              $this->current = 0;
 233          }
 234  
 235          return $this->data[$this->keys[$this->current]];
 236      }
 237  
 238      /**
 239       * Returns the next datapoint and selects it or false on the last datapoint.
 240       *
 241       * This method is part of the Iterator interface to allow access to the 
 242       * datapoints of this row by iterating over it like an array (e.g. using
 243       * foreach).
 244       *
 245       * @return float datapoint if it exists, or false.
 246       */
 247      public function next()
 248      {
 249          if ( ++$this->current >= count( $this->keys ) )
 250          {
 251              return false;
 252          }
 253          else 
 254          {
 255              return $this->data[$this->keys[$this->current]];
 256          }
 257      }
 258  
 259      /**
 260       * Returns the key of the currently selected datapoint.
 261       *
 262       * This method is part of the Iterator interface to allow access to the 
 263       * datapoints of this row by iterating over it like an array (e.g. using
 264       * foreach).
 265       * 
 266       * @return string The key of the currently selected datapoint.
 267       */
 268      public function key()
 269      {
 270          return $this->keys[$this->current];
 271      }
 272  
 273      /**
 274       * Returns if the current datapoint is valid.
 275       *
 276       * This method is part of the Iterator interface to allow access to the 
 277       * datapoints of this row by iterating over it like an array (e.g. using
 278       * foreach).
 279       *
 280       * @return bool If the current datapoint is valid
 281       */
 282      public function valid()
 283      {
 284          return isset( $this->keys[$this->current] );
 285      }
 286  
 287      /**
 288       * Selects the very first datapoint and returns it.
 289       * This method is part of the Iterator interface to allow access to the 
 290       * datapoints of this row by iterating over it like an array (e.g. using
 291       * foreach).
 292       *
 293       * @return float The very first datapoint.
 294       */
 295      public function rewind()
 296      {
 297          $this->keys    = array_keys( $this->data );
 298          $this->current = 0;
 299      }
 300  }
 301  
 302  ?>


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7