1 | # This program is free software; you can redistribute it and/or modify
|
---|
2 | # it under the terms of the GNU General Public License as published by
|
---|
3 | # the Free Software Foundation; version 2 of the License.
|
---|
4 | #
|
---|
5 | # This program is distributed in the hope that it will be useful,
|
---|
6 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
7 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
8 | # GNU General Public License for more details.
|
---|
9 | #
|
---|
10 | # Author: Emanuel Fonseca
|
---|
11 | # Email: emdfonseca<at>gmail<dot>com
|
---|
12 | # Date: 25 August 2008
|
---|
13 | #
|
---|
14 | # Author: Eugene Kin Chee Yip
|
---|
15 | # Date: 7 Nov 2008
|
---|
16 |
|
---|
17 | class varieties(dict):
|
---|
18 | def __init__(self, type = None, alpha = None, colour = None, text = None, fontsize = None, values = None):
|
---|
19 | self.set_type(type)
|
---|
20 | self.set_alpha(alpha)
|
---|
21 | self.set_colour(colour)
|
---|
22 | self.set_text(text)
|
---|
23 | self.set_fontsize(fontsize)
|
---|
24 | self.set_values(values)
|
---|
25 |
|
---|
26 | def set_type(self, type):
|
---|
27 | if type:
|
---|
28 | self['type'] = type
|
---|
29 |
|
---|
30 | def set_alpha(self, alpha):
|
---|
31 | if alpha:
|
---|
32 | self['alpha'] = alpha
|
---|
33 |
|
---|
34 | def set_colour(self, colour):
|
---|
35 | if colour:
|
---|
36 | self['colour'] = colour
|
---|
37 |
|
---|
38 | def set_gradient_fill(self, gradient_fill):
|
---|
39 | self['gradient-fill'] = gradient_fill
|
---|
40 |
|
---|
41 |
|
---|
42 | def set_halo_size(self, size):
|
---|
43 | self['halo-size'] = size
|
---|
44 |
|
---|
45 | def set_width(self, width):
|
---|
46 | self['width'] = width
|
---|
47 |
|
---|
48 | def set_dot_size(self, size):
|
---|
49 | self['dot-size'] = size
|
---|
50 |
|
---|
51 |
|
---|
52 |
|
---|
53 | def set_text(self, text):
|
---|
54 | if text:
|
---|
55 | self['text'] = text
|
---|
56 |
|
---|
57 | def set_fontsize(self, fontsize):
|
---|
58 | if fontsize:
|
---|
59 | self['font-size'] = fontsize
|
---|
60 |
|
---|
61 | def set_values(self, values):
|
---|
62 | if values:
|
---|
63 | self['values'] = values
|
---|
64 |
|
---|
65 | def append_keys(self, colour = None, text = None, fontsize = None):
|
---|
66 | try:
|
---|
67 | self['keys'].append(bar_stack_key(colour, text, fontsize))
|
---|
68 | except:
|
---|
69 | self['keys'] = [bar_stack_key(colour, text, fontsize)]
|
---|
70 |
|
---|
71 |
|
---|
72 | def append_values(self, values):
|
---|
73 | try:
|
---|
74 | self['values'].append(values)
|
---|
75 | except:
|
---|
76 | self['values'] = [values]
|
---|
77 |
|
---|
78 | def append_stack(self, values):
|
---|
79 | self.append_values(values)
|
---|
80 |
|
---|
81 |
|
---|
82 |
|
---|
83 | def set_line_style(self, on, off):
|
---|
84 | self['line-style'] = line_style(on, off)
|
---|
85 |
|
---|
86 | def set_tooltip(self, text):
|
---|
87 | self['tip'] = text
|
---|
88 |
|
---|
89 | def set_no_labels(self, no_labels):
|
---|
90 | self['no-labels'] = no_labels
|
---|
91 |
|
---|
92 | def set_loop(self):
|
---|
93 | self['loop'] = True
|
---|
94 |
|
---|
95 | def set_on_click(self, javascript_call):
|
---|
96 | self['on-click'] = javascript_call
|
---|
97 |
|
---|
98 |
|
---|
99 |
|
---|
100 |
|
---|
101 | ##########################################
|
---|
102 | # key class for bar stack
|
---|
103 | class bar_stack_key(dict):
|
---|
104 | def __init__(self, colour = None, text = None, fontsize = None):
|
---|
105 | self.set_colour(colour)
|
---|
106 | self.set_text(text)
|
---|
107 | self.set_fontsize(fontsize)
|
---|
108 |
|
---|
109 | def set_colour(self, colour):
|
---|
110 | if colour:
|
---|
111 | self['colour'] = colour
|
---|
112 |
|
---|
113 | def set_text(self, text):
|
---|
114 | if text:
|
---|
115 | self['text'] = text
|
---|
116 |
|
---|
117 | def set_fontsize(self, fontsize):
|
---|
118 | if fontsize:
|
---|
119 | self['font-size'] = fontsize
|
---|
120 |
|
---|
121 |
|
---|
122 | ##########################################
|
---|
123 | # value class for custom data points
|
---|
124 | class value(dict):
|
---|
125 | def __init__(self, val = None, colour = None, tooltip = None):
|
---|
126 | self.set_val(val)
|
---|
127 | self.set_colour(colour)
|
---|
128 | self.set_tooltip(tooltip)
|
---|
129 |
|
---|
130 | def set_val(self, val):
|
---|
131 | if val:
|
---|
132 | self['value'] = val
|
---|
133 |
|
---|
134 | def set_colour(self, colour):
|
---|
135 | if colour:
|
---|
136 | self['colour'] = colour
|
---|
137 |
|
---|
138 | def set_tooltip(self, tooltip):
|
---|
139 | if tooltip:
|
---|
140 | self['tip'] = tooltip
|
---|
141 |
|
---|
142 | class dot_value(value):
|
---|
143 | pass
|
---|
144 |
|
---|
145 | class bar_value(value):
|
---|
146 | def __init__(self, (top, bottom), colour = None, tooltip = None):
|
---|
147 | value.__init__(self, colour = colour, tooltip = tooltip)
|
---|
148 | self.set_top_value(top)
|
---|
149 | self.set_bottom_value(bottom)
|
---|
150 |
|
---|
151 | def set_top_value(self, top):
|
---|
152 | self['top'] = top
|
---|
153 |
|
---|
154 | def set_bottom_value(self, bottom):
|
---|
155 | self['bottom'] = bottom
|
---|
156 |
|
---|
157 | class bar_3d_value(bar_value):
|
---|
158 | def __init__(self, top, colour = None, tooltip = None):
|
---|
159 | value.__init__(self, colour = colour, tooltip = tooltip)
|
---|
160 | self.set_top_value(top)
|
---|
161 |
|
---|
162 | def set_top_value(self, top):
|
---|
163 | self['top'] = top
|
---|
164 |
|
---|
165 |
|
---|
166 | class bar_glass_value(bar_3d_value):
|
---|
167 | pass
|
---|
168 |
|
---|
169 | class bar_sketch_value(bar_3d_value):
|
---|
170 | pass
|
---|
171 |
|
---|
172 | class hbar_value(value):
|
---|
173 | def __init__(self, (left, right), colour = None, tooltip = None):
|
---|
174 | value.__init__(self, colour = colour, tooltip = tooltip)
|
---|
175 | self.set_left_value(left)
|
---|
176 | self.set_right_value(right)
|
---|
177 |
|
---|
178 | def set_left_value(self, left):
|
---|
179 | self['left'] = left
|
---|
180 |
|
---|
181 | def set_right_value(self, right):
|
---|
182 | self['right'] = right
|
---|
183 |
|
---|
184 | class bar_stack_value(value):
|
---|
185 | def __init__(self, val, colour = None, tooltip = None):
|
---|
186 | value.__init__(self, colour = colour, tooltip = tooltip)
|
---|
187 | self.set_value(val)
|
---|
188 |
|
---|
189 | def set_value(self, val):
|
---|
190 | if val:
|
---|
191 | self['val'] = val
|
---|
192 |
|
---|
193 | class pie_value(value):
|
---|
194 | def __init__(self, val, label = None, colour = None, tooltip = None):
|
---|
195 | value.__init__(self, val, colour, tooltip)
|
---|
196 | self.set_label(label)
|
---|
197 |
|
---|
198 | def set_label(self, (label, colour, fontsize)):
|
---|
199 | if label:
|
---|
200 | self['label'] = label
|
---|
201 | if colour:
|
---|
202 | self['label-colour'] = colour
|
---|
203 | if fontsize:
|
---|
204 | self['font-size'] = fontsize
|
---|
205 |
|
---|
206 |
|
---|
207 |
|
---|
208 | class scatter_value(value):
|
---|
209 | def __init__(self, (x, y), colour = None, tooltip = None):
|
---|
210 | value.__init__(self, colour = colour, tooltip = tooltip)
|
---|
211 | self.set_x_value(x)
|
---|
212 | self.set_y_value(y)
|
---|
213 |
|
---|
214 | def set_x_value(self, x):
|
---|
215 | self['x'] = x
|
---|
216 |
|
---|
217 | def set_y_value(self, y):
|
---|
218 | self['y'] = y
|
---|
219 |
|
---|
220 |
|
---|
221 | ##########################################
|
---|
222 | # line style class for charts with lines
|
---|
223 | class line_style(dict):
|
---|
224 | def __init__(self, on = None, off = None, style = 'dash'):
|
---|
225 | self.set_style(style)
|
---|
226 | self.set_on(on)
|
---|
227 | self.set_off(off)
|
---|
228 |
|
---|
229 | def set_style(self, style):
|
---|
230 | self['style'] = style
|
---|
231 |
|
---|
232 | def set_on(self, on):
|
---|
233 | if on:
|
---|
234 | self['on'] = on
|
---|
235 |
|
---|
236 | def set_off(self, off):
|
---|
237 | if off:
|
---|
238 | self['off'] = off
|
---|
239 |
|
---|
240 | ##########################################
|
---|
241 | # label classes
|
---|
242 | class x_axis_labels(dict):
|
---|
243 | def __init__(self, labels = None, steps = None, colour = None, size = None, rotate = None):
|
---|
244 | self.set_labels(labels)
|
---|
245 | self.set_steps(steps)
|
---|
246 | self.set_colour(colour)
|
---|
247 | self.set_size(size)
|
---|
248 | self.set_rotate(rotate)
|
---|
249 |
|
---|
250 | def set_labels(self, labels):
|
---|
251 | if labels:
|
---|
252 | self['labels'] = labels
|
---|
253 |
|
---|
254 | def set_steps(self, steps):
|
---|
255 | if steps:
|
---|
256 | self['steps'] = steps
|
---|
257 |
|
---|
258 | def set_colour(self, colour):
|
---|
259 | if colour:
|
---|
260 | self['colour'] = colour
|
---|
261 |
|
---|
262 | def set_size(self, size):
|
---|
263 | if size:
|
---|
264 | self['size'] = size
|
---|
265 |
|
---|
266 | def set_rotate(self, rotate):
|
---|
267 | if rotate:
|
---|
268 | self['rotate'] = rotate
|
---|
269 |
|
---|
270 | class x_axis_label(dict):
|
---|
271 | def __init__(self, text = None, colour = None, size = None, rotate = None):
|
---|
272 | self.set_text(text)
|
---|
273 | self.set_colour(colour)
|
---|
274 | self.set_size(size)
|
---|
275 | self.set_rotate(rotate)
|
---|
276 |
|
---|
277 | def set_text(self, text):
|
---|
278 | if text:
|
---|
279 | self['text'] = text
|
---|
280 |
|
---|
281 | def set_colour(self, colour):
|
---|
282 | if colour:
|
---|
283 | self['colour'] = colour
|
---|
284 |
|
---|
285 | def set_size(self, size):
|
---|
286 | if size:
|
---|
287 | self['size'] = size
|
---|
288 |
|
---|
289 | def set_rotate(self, rotate):
|
---|
290 | if rotate:
|
---|
291 | self['rotate'] = rotate
|
---|
292 |
|
---|
293 |
|
---|
294 |
|
---|
295 |
|
---|
296 | ##########################################
|
---|
297 | # Chart classes
|
---|
298 |
|
---|
299 | # Line Charts
|
---|
300 | class Line(varieties):
|
---|
301 | def __init__(self, alpha = None, colour = None, text = None, fontsize = None, values = None):
|
---|
302 | varieties.__init__(self, 'line', alpha, colour, text, fontsize, values)
|
---|
303 |
|
---|
304 | class Line_Dot(varieties):
|
---|
305 | def __init__(self, alpha = None, colour = None, text = None, fontsize = None, values = None):
|
---|
306 | varieties.__init__(self, 'line_dot', alpha, colour, text, fontsize, values)
|
---|
307 |
|
---|
308 | class Line_Hollow(varieties):
|
---|
309 | def __init__(self, alpha = None, colour = None, text = None, fontsize = None, values = None):
|
---|
310 | varieties.__init__(self, 'line_hollow', alpha, colour, text, fontsize, values)
|
---|
311 |
|
---|
312 |
|
---|
313 |
|
---|
314 | # Bar Charts
|
---|
315 | class Bar(varieties):
|
---|
316 | def __init__(self, alpha = None, colour = None, text = None, fontsize = None, values = None):
|
---|
317 | varieties.__init__(self, 'bar', alpha, colour, text, fontsize, values)
|
---|
318 |
|
---|
319 | class Bar_Filled(varieties):
|
---|
320 | def __init__(self, alpha = None, colour = None, text = None, fontsize = None, values = None, outline = None):
|
---|
321 | varieties.__init__(self, 'bar_filled', alpha, colour, text, fontsize, values)
|
---|
322 | if outline:
|
---|
323 | self['outline-colour'] = outline
|
---|
324 |
|
---|
325 | class Bar_Glass(varieties):
|
---|
326 | def __init__(self, alpha = None, colour = None, text = None, fontsize = None, values = None):
|
---|
327 | varieties.__init__(self, 'bar_glass', alpha, colour, text, fontsize, values)
|
---|
328 |
|
---|
329 | class Bar_3d(varieties):
|
---|
330 | def __init__(self, alpha = None, colour = None, text = None, fontsize = None, values = None):
|
---|
331 | varieties.__init__(self, 'bar_3d', alpha, colour, text, fontsize, values)
|
---|
332 |
|
---|
333 | class Bar_Sketch(varieties):
|
---|
334 | def __init__(self, alpha = None, colour = None, text = None, fontsize = None, values = None, outline = None):
|
---|
335 | varieties.__init__(self, 'bar_sketch', alpha, colour, text, fontsize, values)
|
---|
336 | if outline:
|
---|
337 | self['outline-colour'] = outline
|
---|
338 |
|
---|
339 | class HBar(varieties):
|
---|
340 | def __init__(self, alpha = None, colour = None, text = None, fontsize = None, values = None):
|
---|
341 | varieties.__init__(self, 'hbar', alpha, colour, text, fontsize, values)
|
---|
342 |
|
---|
343 |
|
---|
344 | class Bar_Stack(varieties):
|
---|
345 | def __init__(self, alpha = None, colour = None, text = None, fontsize = None, values = None, colours = None):
|
---|
346 | varieties.__init__(self, 'bar_stack', alpha, colour, text, fontsize, values)
|
---|
347 | if colours:
|
---|
348 | self['colours'] = colours
|
---|
349 |
|
---|
350 | # Area Charts
|
---|
351 | class Area_Line(varieties):
|
---|
352 | def __init__(self, alpha = None, colour = None, text = None, fontsize = None, values = None, fill = None, fill_alpha = None):
|
---|
353 | varieties.__init__(self, 'area_line', alpha, colour, text, fontsize, values)
|
---|
354 | if fill_alpha:
|
---|
355 | self['fill-alpha'] = fill_alpha
|
---|
356 | if fill:
|
---|
357 | self['fill'] = fill
|
---|
358 |
|
---|
359 | class Area_Hollow(varieties):
|
---|
360 | def __init__(self, alpha = None, colour = None, text = None, fontsize = None, values = None, fill = None, fill_alpha = None):
|
---|
361 | varieties.__init__(self, 'area_hollow', alpha, colour, text, fontsize, values)
|
---|
362 | if fill_alpha:
|
---|
363 | self['fill-alpha'] = fill_alpha
|
---|
364 | if fill:
|
---|
365 | self['fill'] = fill
|
---|
366 |
|
---|
367 | # Pie Chart
|
---|
368 | class Pie(varieties):
|
---|
369 | def __init__(self, alpha = None, colour = None, text = None, fontsize = None, values = None, start_angle = None, animate = None, colours = None, label_colour = None):
|
---|
370 | varieties.__init__(self, 'pie', alpha, colour, text, fontsize, values)
|
---|
371 | if start_angle:
|
---|
372 | self['start-angle'] = start_angle
|
---|
373 | if animate:
|
---|
374 | self['animate'] = animate
|
---|
375 | if colours:
|
---|
376 | self['colours'] = colours
|
---|
377 | if label_colour:
|
---|
378 | self['label-colour'] = label_colour
|
---|
379 |
|
---|
380 | # Scatter Charts
|
---|
381 | class Scatter(varieties):
|
---|
382 | def __init__(self, alpha = None, colour = None, text = None, fontsize = None, values = None, colours = None):
|
---|
383 | varieties.__init__(self, 'scatter', alpha, colour, text, fontsize, values)
|
---|
384 |
|
---|
385 | class Scatter_Line(varieties):
|
---|
386 | def __init__(self, alpha = None, colour = None, text = None, fontsize = None, values = None, colours = None):
|
---|
387 | varieties.__init__(self, 'scatter_line', alpha, colour, text, fontsize, values)
|
---|
388 |
|
---|
389 |
|
---|
390 |
|
---|
391 |
|
---|