]>
src.bluestatic.org Git - isso.git/blob - GraphPie.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2002-2007 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 2 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 - 2007, Blue Static
41 class BSGraphPie
extends BSGraph
44 * Graphing data set; 2D array of
45 * array(NAME, PERCENT, COLOR)
48 protected $dataset = array();
50 // ###################################################################
52 * Graphs the actual graph and returns a byte stream
54 * @return string Byte stream
56 public function graph()
58 $colors = $this->_primeColors();
60 $diameter = $this->dimensions
['height'] - (5 * self
::PADDING
);
61 $radius = $diameter / 2;
62 $graphstart = self
::PADDING +
imagefontheight(5) + self
::PADDING
;
65 $this->_paintCanvas();
68 'x' => ($this->legend
? ($radius + self
::PADDING
) : ($this->dimensions
['width'] / 2)),
69 'y' => ($this->dimensions
['height'] / 2) + self
::PADDING
72 $legx = (2 * self
::PADDING
) +
$diameter;
76 foreach ($this->dataset
AS $plot)
78 $deg = (360 / 100) * $plot[1];
79 imagefilledarc($this->image
, $center['x'], $center['y'], $diameter, $diameter, $lastdeg, $deg +
$lastdeg, $plot[2], IMG_ARC_PIE
);
80 imagefilledarc($this->image
, $center['x'], $center['y'], $diameter, $diameter, $lastdeg, $deg +
$lastdeg, $colors['grey'], IMG_ARC_EDGED
| IMG_ARC_NOFILL
);
86 $legx +
1 + self
::SPACING
, $graphstart +
1 + self
::SPACING +
$boxoffset, // top left
87 $legx +
1 + self
::SPACING
, $graphstart +
1 + self
::SPACING +
$boxoffset +
$legendbox, // bottom left
88 $legx +
1 + self
::SPACING +
$legendbox, $graphstart +
1 + self
::SPACING +
$boxoffset +
$legendbox, // bottom right
89 $legx +
1 + self
::SPACING +
$legendbox, $graphstart +
1 + self
::SPACING +
$boxoffset // top right
91 imagefilledpolygon($this->image
, $box, 4, $plot[2]);
93 imagestring($this->image
, 2, ($legx +
1 + self
::SPACING +
$legendbox + self
::SPACING
), ($graphstart + self
::SPACING +
$boxoffset), $plot[0] . " ($plot[1]%)", $colors['black']);
95 $boxoffset +
= self
::SPACING +
$legendbox;
99 // draw the ellipse (do here so it cleans up the arc edges)
100 imageellipse($this->image
, $center['x'], $center['y'], $diameter, $diameter, $colors['grey']);
105 imageline($this->image
, $legx, $graphstart, $this->dimensions
['width'] - self
::PADDING
, $graphstart, $colors['black']); // top
106 imageline($this->image
, $legx, $graphstart, $legx, $legy = ($graphstart + self
::SPACING +
$boxoffset +
1), $colors['black']); // left
107 imageline($this->image
, $legx, $legy, $this->dimensions
['width'] - self
::PADDING
, $legy, $colors['black']); // bottom
108 imageline($this->image
, $this->dimensions
['width'] - self
::PADDING
, $graphstart, $this->dimensions
['width'] - self
::PADDING
, $legy, $colors['black']); // right
111 return $this->_imageFlush();
114 // ###################################################################
116 * Adds an entry to the data set without specifying a color to add.
117 * This is the standard method as the color should only be overridden
120 * @param string Data column name
121 * @param integer Percentage of 100
123 public function addDataSet($name, $percent)
125 $this->dataset
[] = array($name, $percent, $this->_fetchColor());
128 // ###################################################################
130 * Adds an entry ot the data set with specifying a color. This works
131 * the same as addDataSet() but requires an array() as the 3rd parameter
134 * @param string Data column name
135 * @param integer Percent of 100
136 * @param array Array of R,G,B values
138 public function addDataSetColor($name, $percent, $color)
140 $this->dataset
[] = array($name, $percent, imagecolorallocate($this->image
, $color[0], $color[1], $color[2]));