2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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: pie chart
30 * Graphing System: Pie Chart
32 * This framework creates pie charts as PNG image strings. Simply add to
33 * the data set and graph to get the byte stream returned.
35 * @author Iris Studios, Inc.
36 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
44 * Framework registry object
51 * Graphing data set; 2D array of
52 * array(NAME, PERCENT, COLOR)
56 var $dataset = array();
66 * The dimensions of the image
70 var $dimensions = array('width' => 550, 'height' => 350);
73 * Add a legend to the graph
84 var $title = 'ISSO Pie Chart';
86 // ###################################################################
90 function __construct(&$registry)
92 $this->registry
=& $registry;
94 $this->image
= imagecreate($this->dimensions
['width'], $this->dimensions
['height']);
97 // ###################################################################
101 function Graph_Pie(&$registry)
103 $this->__construct($registry);
106 // ###################################################################
108 * Graphs the actual graph and returns a byte stream
112 * @return string Byte stream
116 $colours['black'] = imagecolorallocate($this->image
, 0, 0, 0);
117 $colours['white'] = imagecolorallocate($this->image
, 255, 255, 255);
120 imagefill($this->image
, 0, 0, $colours['white']);
123 imagestring($this->image
, 5, ($this->dimensions
['width'] - (imagefontwidth(5) * strlen($this->title
))) / 2, 10, $this->title
, $colours['black']);
125 $center = array('x' => ($this->dimensions
['width'] / 2), 'y' => ($this->dimensions
['height'] / 2) +
10);
126 $radius = ($this->dimensions
['height'] - 55);
129 imageline($this->image
, 0, 0, 0, $this->dimensions
['height'], $colours['black']); // left
130 imageline($this->image
, 0, $this->dimensions
['height'] - 1, $this->dimensions
['width'], $this->dimensions
['height'] - 1, $colours['black']); // bottom
131 imageline($this->image
, $this->dimensions
['width'] - 1, 0, $this->dimensions
['width'] - 1, $this->dimensions
['height'], $colours['black']); // right
132 imageline($this->image
, 0, 0, $this->dimensions
['width'], 0, $colours['black']); // top
136 foreach ($this->dataset
AS $plot)
138 $deg = (360 / 100) * $plot[1];
139 imagefilledarc($this->image
, $center['x'], $center['y'], $radius, $radius, $lastdeg, $deg +
$lastdeg, $plot[2], IMG_ARC_PIE
);
140 //imagefilledarc($this->image, $center['x'], $center['y'], $radius, $radius, $lastdeg, $deg + $lastdeg, $colours['black'], IMG_ARC_EDGED | IMG_ARC_NOFILL);
144 // draw the ellipse (do here so it cleans up the arc edges)
145 imageellipse($this->image
, $center['x'], $center['y'], $radius, $radius, $colours['black']);
147 imagepng($this->image
);
152 // ###################################################################
154 * Sets the width and height of an image
158 * @param integer Width (pixels)
159 * @param integer Height (pixels)
161 function set_dimensions($width, $height)
163 $this->dimensions
['width'] = intval($width);
164 $this->dimensions
['height'] = intval($height);
166 $this->image
= imagecreate($this->dimensions
['width'], $this->dimensions
['height']);
169 // ###################################################################
171 * Adds an entry to the data set without specifying a colour to add.
172 * This is the standard method as the colour should only be overridden
177 * @param string Data column name
178 * @param integer Percentage of 100
180 function add_data_set($name, $percent)
182 $this->dataset
[] = array($name, intval($percent), $this->fetch_colour());
185 // ###################################################################
187 * Adds an entry ot the data set with specifying a colour. This works
188 * the same as add_data_st() but requires an array() as the 3rd parameter
193 * @param string Data column name
194 * @param integer Percent of 100
195 * @param array Array of R,G,B values
197 function add_data_set_colour($name, $percent, $colour)
199 $this->dataset
[] = array($name, intval($percent), imagecolorallocate($this->image
, $colour[0], $colour[1], $colour[2]));
202 // ###################################################################
204 * Fetches a colour from the allocated colour list and returns the value
208 * @return integer Allocated colour resource
210 function fetch_colour()
212 static $colourlist = array(
218 $colour = $colourlist[ intval($allocated) ];
221 return imagecolorallocate($this->image
, $colour[0], $colour[1], $colour[2]);
225 /*=====================================================================*\
226 || ###################################################################
229 || ###################################################################
230 \*=====================================================================*/