source: code/Website/php-ofc-library/ofc_pie.php@ 7849

Last change on this file since 7849 was 7849, checked in by dennisw, 15 years ago
File size: 4.1 KB
Line 
1<?php
2
3class pie_value
4{
5 function pie_value( $value, $label )
6 {
7 $this->value = $value;
8 $this->label = $label;
9 }
10
11 function set_colour( $colour )
12 {
13 $this->colour = $colour;
14 }
15
16 function set_label( $label, $label_colour, $font_size )
17 {
18 $this->label = $label;
19
20 $tmp = 'label-colour';
21 $this->$tmp = $label_colour;
22
23 $tmp = 'font-size';
24 $this->$tmp = $font_size;
25
26 }
27
28 function set_tooltip( $tip )
29 {
30 $this->tip = $tip;
31 }
32
33 function on_click( $event )
34 {
35 $tmp = 'on-click';
36 $this->$tmp = $event;
37 }
38
39
40 /**
41 * An object that inherits from base_pie_animation
42 */
43 function add_animation( $animation )
44 {
45 if( !isset( $this->animate ) )
46 $this->animate = array();
47
48 $this->animate[] = $animation;
49
50 return $this;
51 }
52}
53
54class base_pie_animation{}
55
56/**
57 * fade the pie slice from $alpha (pie set_alpha) to 100% opaque.
58 */
59class pie_fade extends base_pie_animation
60{
61 function pie_fade()
62 {
63 $this->type="fade";
64 }
65}
66
67/**
68 * Bounce the pie slice out a little
69 */
70class pie_bounce extends base_pie_animation
71{
72 /**
73 * @param $distance as integer, distance to bounce in pixels
74 */
75 function pie_bounce( $distance )
76 {
77 $this->type="bounce";
78 $this->distance = $distance;
79 }
80}
81
82/**
83 * Make a pie chart and fill it with pie slices
84 */
85class pie
86{
87 function pie()
88 {
89 $this->type = 'pie';
90 }
91
92 function set_colours( $colours )
93 {
94 $this->colours = $colours;
95 }
96
97 /**
98 * Sugar wrapped around set_colours
99 */
100 function colours( $colours )
101 {
102 $this->set_colours( $colours );
103 return $this;
104 }
105
106 /**
107 * @param $alpha as float (0-1) 0.75 = 3/4 visible
108 */
109 function set_alpha( $alpha )
110 {
111 $this->alpha = $alpha;
112 }
113
114 /**
115 *sugar wrapped set_alpha
116 **/
117 function alpha( $alpha )
118 {
119 $this->set_alpha( $alpha );
120 return $this;
121 }
122
123 /**
124 * @param $v as array containing one of
125 * - null
126 * - real or integer number
127 * - a pie_value object
128 */
129 function set_values( $v )
130 {
131 $this->values = $v;
132 }
133
134 /**
135 * sugar for set_values
136 */
137 function values( $v )
138 {
139 $this->set_values( $v );
140 return $this;
141 }
142
143 /**
144 * HACK to keep old code working.
145 */
146 function set_animate( $bool )
147 {
148 if( $bool )
149 $this->add_animation( new pie_fade() );
150
151 }
152
153 /**
154 * An object that inherits from base_pie_animation
155 */
156 function add_animation( $animation )
157 {
158 if( !isset( $this->animate ) )
159 $this->animate = array();
160
161 $this->animate[] = $animation;
162
163 return $this;
164 }
165
166 /**
167 * @param $angle as real number
168 */
169 function set_start_angle( $angle )
170 {
171 $tmp = 'start-angle';
172 $this->$tmp = $angle;
173 }
174
175 /**
176 * sugar for set_start_angle
177 */
178 function start_angle($angle)
179 {
180 $this->set_start_angle( $angle );
181 return $this;
182 }
183
184 /**
185 * @param $tip as string. The tooltip text. May contain magic varibles
186 */
187 function set_tooltip( $tip )
188 {
189 $this->tip = $tip;
190 }
191
192 /**
193 * sugar for set_tooltip
194 */
195 function tooltip( $tip )
196 {
197 $this->set_tooltip( $tip );
198 return $this;
199 }
200
201 function set_gradient_fill()
202 {
203 $tmp = 'gradient-fill';
204 $this->$tmp = true;
205 }
206
207 function gradient_fill()
208 {
209 $this->set_gradient_fill();
210 return $this;
211 }
212
213 /**
214 * By default each label is the same colour as the slice,
215 * but you can ovveride that behaviour using this method.
216 *
217 * @param $label_colour as string HEX colour;
218 */
219 function set_label_colour( $label_colour )
220 {
221 $tmp = 'label-colour';
222 $this->$tmp = $label_colour;
223 }
224
225 function label_colour( $label_colour )
226 {
227 $this->set_label_colour( $label_colour );
228 return $this;
229 }
230
231 /**
232 * Turn off the labels
233 */
234 function set_no_labels()
235 {
236 $tmp = 'no-labels';
237 $this->$tmp = true;
238 }
239
240 function on_click( $event )
241 {
242 $tmp = 'on-click';
243 $this->$tmp = $event;
244 }
245
246 /**
247 * Fix the radius of the pie chart. Take a look at the magic variable #radius#
248 * for helping figure out what radius to set it to.
249 *
250 * @param $radius as number
251 */
252 function radius( $radius )
253 {
254 $this->radius = $radius;
255 return $this;
256 }
257}
Note: See TracBrowser for help on using the repository browser.