* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Array.php,v 1.8 2005/08/24 20:36:03 nosey Exp $ * @link http://pear.php.net/package/Image_Graph */ /** * Include file Image/Graph/Fill.php */ require_once 'Image/Graph/Fill.php'; /** * A sequential array of fillstyles. * * This is used for filling multiple objects within the same element with * different styles. This is done by adding multiple fillstyles to a FillArrray * structure. The fillarray will then when requested return the 'next' fillstyle * in sequential order. It is possible to specify ID tags to each fillstyle, * which is used to make sure some data uses a specific fillstyle (i.e. in a * multiple-/stackedbarchart you name the {@link Image_Graph_Dataset}s and uses * this name as ID tag when adding the dataset's associated fillstyle to the * fillarray. * * @category Images * @package Image_Graph * @subpackage Fill * @author Jesper Veggerby * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: 0.7.2 * @link http://pear.php.net/package/Image_Graph */ class Image_Graph_Fill_Array extends Image_Graph_Fill { /** * The fill array * @var array * @access private */ var $_fillStyles = array (); /** * Resets the fillstyle * * @access private */ function _reset() { reset($this->_fillStyles); } /** * Add a fill style to the array * * @param Image_Graph_Fill $style The style to add * @param string $id The id or name of the style */ function &add(& $style, $id = '') { if ($id == '') { $this->_fillStyles[] =& $style; } else { $this->_fillStyles[$id] =& $style; } reset($this->_fillStyles); return $style; } /** * Add a color to the array * * @param int $color The color * @param string $id The id or name of the color */ function addColor($color, $id = false) { if ($id !== false) { $this->_fillStyles[$id] = $color; } else { $this->_fillStyles[] = $color; } reset($this->_fillStyles); } /** * Return the fillstyle * * @return int A GD fillstyle * @access private */ function _getFillStyle($ID = false) { if (($ID === false) || (!isset($this->_fillStyles[$ID]))) { $ID = key($this->_fillStyles); if (!next($this->_fillStyles)) { reset($this->_fillStyles); } } $fillStyle =& $this->_fillStyles[$ID]; if (is_object($fillStyle)) { return $fillStyle->_getFillStyle($ID); } elseif ($fillStyle !== null) { return $fillStyle; } else { return parent::_getFillStyle($ID); } } } ?>