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