bzr branch
http://gegoxaren.bato24.eu/bzr/%2Bjunk/pygooglechart-py3k
7
by gak
version bump, added BadContentTypeException, added a few examples, added COPYING licence, code is more PEP8 friendly, download() checks for content type and raises on bad http codes, add_data returns the index of the dataset, Line doesn't allow being an instance. |
1 |
#!/usr/bin/env python
|
2 |
||
3 |
import os |
|
4 |
import sys |
|
5 |
import math |
|
6 |
||
7 |
ROOT = os.path.dirname(os.path.abspath(__file__)) |
|
8 |
sys.path.insert(0, os.path.join(ROOT, '..')) |
|
9 |
||
10 |
from pygooglechart import SimpleLineChart |
|
11 |
from pygooglechart import XYLineChart |
|
12 |
||
13 |
import settings |
|
14 |
import helper |
|
15 |
||
16 |
def simple_random(): |
|
17 |
chart = SimpleLineChart(settings.width, settings.height) |
|
18 |
chart.add_data(helper.random_data()) |
|
19 |
chart.download('line-simple-random.png') |
|
20 |
||
21 |
def xy_random(): |
|
22 |
chart = XYLineChart(settings.width, settings.height) |
|
23 |
chart.add_data(helper.random_data()) |
|
24 |
chart.add_data(helper.random_data()) |
|
25 |
chart.download('line-xy-random.png') |
|
26 |
||
27 |
def xy_rect(): |
|
28 |
chart = XYLineChart(settings.width, settings.height) |
|
29 |
chart.add_data([0, 100, 100, 0, 0]) |
|
30 |
chart.add_data([0, 0, 100, 100, 0]) |
|
31 |
chart.download('line-xy-rect.png') |
|
32 |
||
33 |
def xy_circle(): |
|
34 |
chart = XYLineChart(settings.width, settings.height) |
|
35 |
steps = 40 |
|
36 |
xradius = 25 |
|
37 |
yradius = 45 |
|
38 |
xmid = 50 |
|
39 |
ymid = 50 |
|
40 |
xlist = [] |
|
41 |
ylist = [] |
|
42 |
for angle in xrange(0, steps + 1): |
|
43 |
angle = float(angle) / steps * math.pi * 2 |
|
44 |
xlist.append(math.cos(angle) * xradius + xmid) |
|
45 |
ylist.append(math.sin(angle) * yradius + ymid) |
|
46 |
chart.add_data(xlist) |
|
47 |
chart.add_data(ylist) |
|
48 |
chart.download('line-xy-circle.png') |
|
49 |
||
50 |
def main(): |
|
51 |
simple_random() |
|
52 |
xy_random() |
|
53 |
xy_rect() |
|
54 |
xy_circle() |
|
55 |
||
56 |
if __name__ == '__main__': |
|
57 |
main() |
|
58 |