1<?php
2
3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5/**
6 * Image_Graph - PEAR PHP OO Graph Rendering Utility.
7 *
8 * PHP version 5
9 *
10 * LICENSE: This library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or (at your
13 * option) any later version. This library is distributed in the hope that it
14 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
16 * General Public License for more details. You should have received a copy of
17 * the GNU Lesser General Public License along with this library; if not, write
18 * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 * 02111-1307 USA
20 *
21 * @category   Images
22 * @package    Image_Graph
23 * @subpackage Line
24 * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
25 * @author     Stefan Neufeind <pear.neufeind@speedpartner.de>
26 * @copyright  2003-2009 The PHP Group
27 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
28 * @version    SVN: $Id: Array.php 291170 2009-11-23 03:50:22Z neufeind $
29 * @link       http://pear.php.net/package/Image_Graph
30 */
31
32/**
33 * Include file Image/Graph/Common.php
34 */
35require_once 'Image/Graph/Common.php';
36
37/**
38 * A sequential array of linestyles.
39 *
40 * This is used for multiple objects within the same element with different line
41 * styles. This is done by adding multiple line styles to a LineArrray
42 * structure. The linearray will then when requested return the 'next' linestyle
43 * in sequential order. It is possible to specify ID tags to each linestyle,
44 * which is used to make sure some data uses a specific linestyle (i.e. in a
45 * multiple-/stackedbarchart you name the {@link Image_Graph_Dataset}s and uses
46 * this name as ID tag when adding the dataset's associated linestyle to the
47 * linearray.
48 *
49 * @category   Images
50 * @package    Image_Graph
51 * @subpackage Line
52 * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
53 * @author     Stefan Neufeind <pear.neufeind@speedpartner.de>
54 * @copyright  2003-2009 The PHP Group
55 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
56 * @version    Release: 0.8.0
57 * @link       http://pear.php.net/package/Image_Graph
58 */
59class Image_Graph_Line_Array extends Image_Graph_Common
60{
61
62    /**
63     * The fill array
64     * @var array
65     * @access private
66     */
67    var $_lineStyles = array ();
68
69    /**
70     * Add a line style to the array
71     *
72     * @param Image_Graph_Line &$style The style to add
73     * @param ???              $id     ???
74     *
75     * @return void
76     */
77    function add(& $style, $id = false)
78    {
79        if (is_a($style, 'Image_Graph_Element')) {
80            parent::add($style);
81        }
82        if ($id === false) {
83            $this->_lineStyles[] =& $style;
84        } else {
85            $this->_lineStyles[$id] =& $style;
86        }
87        reset($this->_lineStyles);
88
89    }
90
91    /**
92     * Add a color to the array
93     *
94     * @param int    $color The color
95     * @param string $id    The id or name of the color
96     *
97     * @return void
98     */
99    function addColor($color, $id = false)
100    {
101        if ($id !== false) {
102            $this->_lineStyles[$id] = $color;
103        } else {
104            $this->_lineStyles[] = $color;
105        }
106        reset($this->_lineStyles);
107    }
108
109    /**
110     * Return the linestyle
111     *
112     * @param ??? $ID ???
113     *
114     * @return int A GD Linestyle
115     * @access private
116     */
117    function _getLineStyle($ID = false)
118    {
119        if (($ID === false) || (!isset($this->_lineStyles[$ID]))) {
120            $ID = key($this->_lineStyles);
121            if (!next($this->_lineStyles)) {
122                reset($this->_lineStyles);
123            }
124        }
125        $lineStyle =& $this->_lineStyles[$ID];
126
127        if (is_object($lineStyle)) {
128            return $lineStyle->_getLineStyle($ID);
129        } elseif ($lineStyle !== null) {
130            return $lineStyle;
131        } else {
132            return parent::_getLineStyle($ID);
133        }
134    }
135
136}
137
138?>
139