]>
src.bluestatic.org Git - isso.git/blob - Graph.php
2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright ©2002-[#]year[#] Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
23 * Graphing System (Graph.php)
31 * This is an abstract class that all other graphing systems extend. It takes
32 * care of things like scales, data sets, and dimensions.
35 * @copyright Copyright (c)2002 - [#]year[#], Blue Static
40 abstract class BSGraph
43 * Graphing data set; 2D array of plot information
46 protected $dataset = array();
52 protected $image = null;
55 * The dimensions of the image
58 protected $dimensions = array('width' => 550, 'height' => 350);
61 * Add a legend to the graph?
64 protected $legend = true;
70 protected $title = 'ISSO Pie Chart';
72 // ###################################################################
76 public function __construct()
81 // ###################################################################
83 * Sets the width and height by using scale factors of 550x350; you
84 * can specify a positive value to multiply by that many times or a
85 * negative one to divide
87 * @param float Scale factor
89 public function setScale($scale)
91 $this->dimensions
['width'] = 550;
92 $this->dimensions
['height'] = 350;
96 $this->dimensions
['width'] *= $scale;
97 $this->dimensions
['height'] *= $scale;
101 $scale = abs($scale);
102 $this->dimensions
['width'] /= $scale;
103 $this->dimensions
['height'] /= $scale;
106 if (!is_null($this->image
))
108 imagedestroy($this->image
);
111 $this->image
= imagecreate($this->dimensions
['width'], $this->dimensions
['height']);
114 // ###################################################################
116 * Sets whether or not a legend is created for the graph
118 * @param bool Draw a legend?
120 public function setLegend($yesno)
122 $this->legend
= (bool)$yesno;
125 // ###################################################################
127 * Sets the title of the chart to be drawn above the graph
129 * @param string Title of the chart
131 public function setTitle($title)
133 $this->title
= $title;
136 // ###################################################################
138 * Graphs the actual data and returns then sends the image result to
141 public abstract function graph();
143 // ###################################################################
145 * Adds an entry to the data set without specifying a color to add.
146 * This is the standard method as the color should only be overridden
149 * @param string Data column name
150 * @param integer Amount
152 public abstract function addDataSet($name, $amount);
154 // ###################################################################
156 * Adds an entry ot the data set with specifying a color. This works
157 * the same as addDataSet() but requires an array() as the 3rd parameter
160 * @param string Data column name
161 * @param integer Percent of 100
162 * @param array Array of R,G,B values
164 public abstract function addDataSetColor($name, $amount, $color);
166 // ###################################################################
168 * Fetches a color from the allocated color list and returns the value
170 * @return integer Allocated color resource
172 protected function _fetchColor()
174 static $colorlist = array(
184 array(170, 169, 174),
188 static $allocated = 0;
190 $color = $colorlist["$allocated"];
193 return imagecolorallocate($this->image, $color[0], $color[1], $color[2]);
197 /*=====================================================================*
198 || ###################################################################
201 || ###################################################################
202 \*=====================================================================*/