]>
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 [ 'black' ] = imagecolorallocate ( $this- > image
, 0 , 0 , 0 );
60 $colors [ 'white' ] = imagecolorallocate ( $this- > image
, 255 , 255 , 255 );
61 $colors [ 'grey' ] = imagecolorallocate ( $this- > image
, 121 , 121 , 123 );
65 $diameter = $this- > dimensions
[ 'height' ] - ( 5 * $graphpadding );
66 $radius = $diameter / 2 ;
67 $graphstart = $graphpadding +
imagefontheight ( 5 ) +
$graphpadding ;
71 imagefill ( $this- > image
, 0 , 0 , $colors [ 'white' ]);
74 imagestring ( $this- > image
, 5 , ( $this- > dimensions
[ 'width' ] - ( imagefontwidth ( 5 ) * strlen ( $this- > title
))) / 2 , $graphpadding , $this- > title
, $colors [ 'black' ]);
77 'x' => ( $this- > legend
? ( $radius +
$graphpadding ) : ( $this- > dimensions
[ 'width' ] / 2 )),
78 'y' => ( $this- > dimensions
[ 'height' ] / 2 ) +
$graphpadding
82 imageline ( $this- > image
, 0 , 0 , 0 , $this- > dimensions
[ 'height' ], $colors [ 'black' ]); // left
83 imageline ( $this- > image
, 0 , $this- > dimensions
[ 'height' ] - 1 , $this- > dimensions
[ 'width' ], $this- > dimensions
[ 'height' ] - 1 , $colors [ 'black' ]); // bottom
84 imageline ( $this- > image
, $this- > dimensions
[ 'width' ] - 1 , 0 , $this- > dimensions
[ 'width' ] - 1 , $this- > dimensions
[ 'height' ], $colors [ 'black' ]); // right
85 imageline ( $this- > image
, 0 , 0 , $this- > dimensions
[ 'width' ], 0 , $colors [ 'black' ]); // top
87 $legx = ( 2 * $graphpadding ) +
$diameter ;
91 foreach ( $this- > dataset
AS $plot )
93 $deg = ( 360 / 100 ) * $plot [ 1 ];
94 imagefilledarc ( $this- > image
, $center [ 'x' ], $center [ 'y' ], $diameter , $diameter , $lastdeg , $deg +
$lastdeg , $plot [ 2 ], IMG_ARC_PIE
);
95 imagefilledarc ( $this- > image
, $center [ 'x' ], $center [ 'y' ], $diameter , $diameter , $lastdeg , $deg +
$lastdeg , $colors [ 'grey' ], IMG_ARC_EDGED
| IMG_ARC_NOFILL
);
101 $legx +
1 +
$graphspacing , $graphstart +
1 +
$graphspacing +
$boxoffset , // top left
102 $legx +
1 +
$graphspacing , $graphstart +
1 +
$graphspacing +
$boxoffset +
$legendbox , // bottom left
103 $legx +
1 +
$graphspacing +
$legendbox , $graphstart +
1 +
$graphspacing +
$boxoffset +
$legendbox , // bottom right
104 $legx +
1 +
$graphspacing +
$legendbox , $graphstart +
1 +
$graphspacing +
$boxoffset // top right
106 imagefilledpolygon ( $this- > image
, $box , 4 , $plot [ 2 ]);
108 imagestring ( $this- > image
, 2 , ( $legx +
1 +
$graphspacing +
$legendbox +
$graphspacing ), ( $graphstart +
$graphspacing +
$boxoffset ), $plot [ 0 ] . " ( $plot [1]%)" , $colors [ 'black' ]);
110 $boxoffset +
= $graphspacing +
$legendbox ;
114 // draw the ellipse (do here so it cleans up the arc edges)
115 imageellipse ( $this- > image
, $center [ 'x' ], $center [ 'y' ], $diameter , $diameter , $colors [ 'grey' ]);
120 imageline ( $this- > image
, $legx , $graphstart , $this- > dimensions
[ 'width' ] - $graphpadding , $graphstart , $colors [ 'black' ]); // top
121 imageline ( $this- > image
, $legx , $graphstart , $legx , $legy = ( $graphstart +
$graphspacing +
$boxoffset +
1 ), $colors [ 'black' ]); // left
122 imageline ( $this- > image
, $legx , $legy , $this- > dimensions
[ 'width' ] - $graphpadding , $legy , $colors [ 'black' ]); // bottom
123 imageline ( $this- > image
, $this- > dimensions
[ 'width' ] - $graphpadding , $graphstart , $this- > dimensions
[ 'width' ] - $graphpadding , $legy , $colors [ 'black' ]); // right
127 imagepng ( $this- > image
);
128 $data = ob_get_contents ();
131 $data = ob_get_clean ();
139 // ###################################################################
141 * Adds an entry to the data set without specifying a color to add.
142 * This is the standard method as the color should only be overridden
145 * @param string Data column name
146 * @param integer Percentage of 100
148 public function addDataSet ( $name , $percent )
150 $this- > dataset
[] = array ( $name , intval ( $percent ), $this- > _fetchColor ());
153 // ###################################################################
155 * Adds an entry ot the data set with specifying a color. This works
156 * the same as addDataSet() but requires an array() as the 3rd parameter
159 * @param string Data column name
160 * @param integer Percent of 100
161 * @param array Array of R,G,B values
163 public function addDataSetColor ( $name , $percent , $color )
165 $this- > dataset
[] = array ( $name , intval ( $percent ), imagecolorallocate ( $this- > image
, $color [ 0 ], $color [ 1 ], $color [ 2 ]));
169 /*=====================================================================*\
170 || ###################################################################
173 || ###################################################################
174 \*=====================================================================*/