[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/library/ezc/Graph/src/interfaces/ -> palette.php (source)

   1  <?php
   2  /**
   3   * File containing the abstract ezcGraphPalette 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   */
  10  /**
  11   * Abstract class to contain pallet definitions
  12   * 
  13   * @version 1.5
  14   * @package Graph
  15   * @mainclass
  16   */
  17  abstract class ezcGraphPalette
  18  {
  19      /**
  20       * Indicates which color should be used for the next dataset
  21       * 
  22       * @var integer
  23       */
  24      protected $colorIndex = -1;
  25  
  26      /**
  27       * Indicates which symbol should be used for the nect dataset
  28       * 
  29       * @var integer
  30       */
  31      protected $symbolIndex = -1;
  32  
  33      /**
  34       * Axiscolor 
  35       * 
  36       * @var ezcGraphColor
  37       */
  38      protected $axisColor;
  39  
  40      /**
  41       * Color of grid lines
  42       * 
  43       * @var ezcGraphColor
  44       */
  45      protected $majorGridColor;
  46  
  47      /**
  48       * Color of minor grid lines
  49       * 
  50       * @var ezcGraphColor
  51       */
  52      protected $minorGridColor;
  53  
  54      /**
  55       * Array with colors for datasets
  56       * 
  57       * @var array
  58       */
  59      protected $dataSetColor;
  60  
  61      /**
  62       * Array with symbols for datasets 
  63       * 
  64       * @var array
  65       */
  66      protected $dataSetSymbol;
  67  
  68      /**
  69       * Name of font to use
  70       * 
  71       * @var string
  72       */
  73      protected $fontName;
  74  
  75      /**
  76       * Fontcolor 
  77       * 
  78       * @var ezcGraphColor
  79       */
  80      protected $fontColor;
  81  
  82      /**
  83       * Backgroundcolor 
  84       * 
  85       * @var ezcGraphColor
  86       */
  87      protected $chartBackground;
  88  
  89      /**
  90       * Bordercolor the chart
  91       * 
  92       * @var ezcGraphColor
  93       */
  94      protected $chartBorderColor;
  95  
  96      /**
  97       * Borderwidth for the chart
  98       * 
  99       * @var integer
 100       * @access protected
 101       */
 102      protected $chartBorderWidth = 0;
 103  
 104      /**
 105       * Backgroundcolor for elements
 106       * 
 107       * @var ezcGraphColor
 108       */
 109      protected $elementBackground;
 110  
 111      /**
 112       * Bordercolor for elements
 113       * 
 114       * @var ezcGraphColor
 115       */
 116      protected $elementBorderColor;
 117  
 118      /**
 119       * Borderwidth for elements
 120       * 
 121       * @var integer
 122       * @access protected
 123       */
 124      protected $elementBorderWidth = 0;
 125  
 126      /**
 127       * Padding in elements
 128       * 
 129       * @var integer
 130       */
 131      protected $padding = 1;
 132  
 133      /**
 134       * Margin of elements
 135       * 
 136       * @var integer
 137       */
 138      protected $margin = 0;
 139  
 140      /**
 141       * Ensure value to be a color
 142       * 
 143       * @param mixed $color Color to transform into a ezcGraphColor object
 144       * @return ezcGraphColor
 145       */
 146      protected function checkColor( &$color )
 147      {
 148          if ( $color == null )
 149          {
 150              return ezcGraphColor::fromHex( '#000000FF' );
 151          }
 152          elseif ( !( $color instanceof ezcGraphColor ) )
 153          {
 154              $color = ezcGraphColor::create( $color );
 155          }
 156  
 157          return $color;
 158      }
 159  
 160      /**
 161       * Manually reset the color counter to use the first color again
 162       * 
 163       * @access public
 164       */
 165      public function resetColorCounter()
 166      {
 167          $this->colorIndex = -1;
 168          $this->symbolIndex = -1;
 169      }
 170  
 171      /**
 172       * Returns the requested property
 173       * 
 174       * @param string $propertyName Name of property
 175       * @return mixed
 176       * @ignore
 177       */
 178      public function __get( $propertyName )
 179      {
 180          switch ( $propertyName )
 181          {
 182              case 'axisColor':
 183              case 'majorGridColor':
 184              case 'minorGridColor':
 185              case 'fontColor':
 186              case 'chartBackground':
 187              case 'chartBorderColor':
 188              case 'elementBackground':
 189              case 'elementBorderColor':
 190                  return ( $this->$propertyName = $this->checkColor( $this->$propertyName ) );
 191              
 192              case 'dataSetColor':
 193                  $this->colorIndex = ( ( $this->colorIndex + 1 ) % count( $this->dataSetColor ) );
 194                  return $this->checkColor( $this->dataSetColor[ $this->colorIndex ] );
 195              case 'dataSetSymbol':
 196                  $this->symbolIndex = ( ( $this->symbolIndex + 1 ) % count( $this->dataSetSymbol ) );
 197                  return $this->dataSetSymbol[ $this->symbolIndex ];
 198  
 199              case 'fontName':
 200              case 'chartBorderWidth':
 201              case 'elementBorderWidth':
 202              case 'padding':
 203              case 'margin':
 204                  return $this->$propertyName;
 205  
 206              default:
 207                  throw new ezcBasePropertyNotFoundException( $propertyName );
 208          }
 209      }
 210  
 211      /**
 212       * __set 
 213       * 
 214       * @param mixed $propertyName Property name
 215       * @param mixed $propertyValue Property value
 216       * @access public
 217       * @ignore
 218       */
 219      public function __set( $propertyName, $propertyValue )
 220      {
 221          switch ( $propertyName )
 222          {
 223              case 'axisColor':
 224              case 'majorGridColor':
 225              case 'minorGridColor':
 226              case 'fontColor':
 227              case 'chartBackground':
 228              case 'chartBorderColor':
 229              case 'elementBackground':
 230              case 'elementBorderColor':
 231                  $this->$propertyName = ezcGraphColor::create( $propertyValue );
 232                  break;
 233  
 234              case 'dataSetColor':
 235                  if ( !is_array( $propertyValue ) )
 236                  {
 237                      throw new ezcBaseValueException( $propertyName, $propertyValue, 'array( ezcGraphColor )' );
 238                  }
 239  
 240                  $this->dataSetColor = array();
 241                  foreach ( $propertyValue as $value )
 242                  {
 243                      $this->dataSetColor[] = ezcGraphColor::create( $value );
 244                  }
 245                  $this->colorIndex = -1;
 246                  break;
 247              case 'dataSetSymbol':
 248                  if ( !is_array( $propertyValue ) )
 249                  {
 250                      throw new ezcBaseValueException( $propertyName, $propertyValue, 'array( (int) ezcGraph::SYMBOL_TYPE )' );
 251                  }
 252  
 253                  $this->dataSetSymbol = array();
 254                  foreach ( $propertyValue as $value )
 255                  {
 256                      $this->dataSetSymbol[] = (int) $value;
 257                  }
 258                  $this->symbolIndex = -1;
 259                  break;
 260  
 261              case 'fontName':
 262                  $this->$propertyName = (string) $propertyValue;
 263                  break;
 264  
 265              case 'chartBorderWidth':
 266              case 'elementBorderWidth':
 267              case 'padding':
 268              case 'margin':
 269                  if ( !is_numeric( $propertyValue ) ||
 270                       ( $propertyValue < 0 ) )
 271                  {
 272                      throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 0' );
 273                  }
 274  
 275                  $this->$propertyName = (int) $propertyValue;
 276                  break;
 277          
 278              default:
 279                  throw new ezcBasePropertyNotFoundException( $propertyName );
 280          }
 281      }
 282  }
 283  
 284  ?>


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