]>
src.bluestatic.org Git - isso.git/blob - GraphPie.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: Pie Chart (GraphPie.php)
28 require_once('ISSO/Graph.php');
31 * Graphing System: Pie Chart
33 * This framework creates pie charts as PNG image strings. Simply add to
34 * the data set and graph to get the byte stream returned.
37 * @copyright Copyright (c)2002 - [#]year[#], Blue Static
42 class BSGraphPie
extends BSGraph
45 * Graphing data set; 2D array of
46 * array(NAME, PERCENT, COLOR)
49 protected $dataset = array();
51 // ###################################################################
53 * Graphs the actual graph and returns a byte stream
55 * @return string Byte stream
57 public function graph()
59 $colors = $this->_primeColors();
61 $diameter = $this->dimensions
['height'] - (5 * self
::PADDING
);
62 $radius = $diameter / 2;
63 $graphstart = self
::PADDING +
imagefontheight(5) + self
::PADDING
;
66 $this->_paintCanvas();
69 'x' => ($this->legend
? ($radius + self
::PADDING
) : ($this->dimensions
['width'] / 2)),
70 'y' => ($this->dimensions
['height'] / 2) + self
::PADDING
73 $legx = (2 * self
::PADDING
) +
$diameter;
77 foreach ($this->dataset
AS $plot)
79 $deg = (360 / 100) * $plot[1];
80 imagefilledarc($this->image
, $center['x'], $center['y'], $diameter, $diameter, $lastdeg, $deg +
$lastdeg, $plot[2], IMG_ARC_PIE
);
81 imagefilledarc($this->image
, $center['x'], $center['y'], $diameter, $diameter, $lastdeg, $deg +
$lastdeg, $colors['grey'], IMG_ARC_EDGED
| IMG_ARC_NOFILL
);
87 $legx +
1 + self
::SPACING
, $graphstart +
1 + self
::SPACING +
$boxoffset, // top left
88 $legx +
1 + self
::SPACING
, $graphstart +
1 + self
::SPACING +
$boxoffset +
$legendbox, // bottom left
89 $legx +
1 + self
::SPACING +
$legendbox, $graphstart +
1 + self
::SPACING +
$boxoffset +
$legendbox, // bottom right
90 $legx +
1 + self
::SPACING +
$legendbox, $graphstart +
1 + self
::SPACING +
$boxoffset // top right
92 imagefilledpolygon($this->image
, $box, 4, $plot[2]);
94 imagestring($this->image
, 2, ($legx +
1 + self
::SPACING +
$legendbox + self
::SPACING
), ($graphstart + self
::SPACING +
$boxoffset), $plot[0] . " ($plot[1]%)", $colors['black']);
96 $boxoffset +
= self
::SPACING +
$legendbox;
100 // draw the ellipse (do here so it cleans up the arc edges)
101 imageellipse($this->image
, $center['x'], $center['y'], $diameter, $diameter, $colors['grey']);
106 imageline($this->image
, $legx, $graphstart, $this->dimensions
['width'] - self
::PADDING
, $graphstart, $colors['black']); // top
107 imageline($this->image
, $legx, $graphstart, $legx, $legy = ($graphstart + self
::SPACING +
$boxoffset +
1), $colors['black']); // left
108 imageline($this->image
, $legx, $legy, $this->dimensions
['width'] - self
::PADDING
, $legy, $colors['black']); // bottom
109 imageline($this->image
, $this->dimensions
['width'] - self
::PADDING
, $graphstart, $this->dimensions
['width'] - self
::PADDING
, $legy, $colors['black']); // right
112 return $this->_imageFlush();
115 // ###################################################################
117 * Adds an entry to the data set without specifying a color to add.
118 * This is the standard method as the color should only be overridden
121 * @param string Data column name
122 * @param integer Percentage of 100
124 public function addDataSet($name, $percent)
126 $this->dataset
[] = array($name, $percent, $this->_fetchColor());
129 // ###################################################################
131 * Adds an entry ot the data set with specifying a color. This works
132 * the same as addDataSet() but requires an array() as the 3rd parameter
135 * @param string Data column name
136 * @param integer Percent of 100
137 * @param array Array of R,G,B values
139 public function addDataSetColor($name, $percent, $color)
141 $this->dataset
[] = array($name, $percent, imagecolorallocate($this->image
, $color[0], $color[1], $color[2]));
145 /*=====================================================================*\
146 || ###################################################################
149 || ###################################################################
150 \*=====================================================================*/