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(): |
|
|
19
by gak
Added automatic scaling patch from Trent Mick |
17 |
chart = SimpleLineChart(settings.width, settings.height, y_range=(0, 100)) |
|
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. |
18 |
chart.add_data(helper.random_data()) |
19 |
chart.download('line-simple-random.png') |
|
20 |
||
21 |
def xy_random(): |
|
|
19
by gak
Added automatic scaling patch from Trent Mick |
22 |
chart = XYLineChart(settings.width, settings.height, |
23 |
x_range=(0, 100), y_range=(0, 100)) |
|
|
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. |
24 |
chart.add_data(helper.random_data()) |
25 |
chart.add_data(helper.random_data()) |
|
26 |
chart.download('line-xy-random.png') |
|
27 |
||
28 |
def xy_rect(): |
|
|
19
by gak
Added automatic scaling patch from Trent Mick |
29 |
chart = XYLineChart(settings.width, settings.height, |
30 |
x_range=(0, 100), y_range=(0, 100)) |
|
|
15
by gak
Added more examples |
31 |
chart.add_data([10, 90, 90, 10, 10]) |
32 |
chart.add_data([10, 10, 90, 90, 10]) |
|
|
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. |
33 |
chart.download('line-xy-rect.png') |
34 |
||
35 |
def xy_circle(): |
|
|
19
by gak
Added automatic scaling patch from Trent Mick |
36 |
chart = XYLineChart(settings.width, settings.height, |
37 |
x_range=(0, 100), y_range=(0, 100)) |
|
|
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. |
38 |
steps = 40 |
39 |
xradius = 25 |
|
40 |
yradius = 45 |
|
41 |
xmid = 50 |
|
42 |
ymid = 50 |
|
43 |
xlist = [] |
|
44 |
ylist = [] |
|
45 |
for angle in xrange(0, steps + 1): |
|
46 |
angle = float(angle) / steps * math.pi * 2 |
|
47 |
xlist.append(math.cos(angle) * xradius + xmid) |
|
48 |
ylist.append(math.sin(angle) * yradius + ymid) |
|
49 |
chart.add_data(xlist) |
|
50 |
chart.add_data(ylist) |
|
51 |
chart.download('line-xy-circle.png') |
|
52 |
||
53 |
def main(): |
|
54 |
simple_random() |
|
55 |
xy_random() |
|
56 |
xy_rect() |
|
57 |
xy_circle() |
|
58 |
||
59 |
if __name__ == '__main__': |
|
60 |
main() |
|
61 |