/+junk/pygooglechart-py3k

To get this branch, use:
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
22 by gak
- pygooglechart.py converted to unix line breaks
12
from pygooglechart import SparkLineChart
45 by gak
- Added filled line graph to examples
13
from pygooglechart import Axis
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.
14
15
import settings
16
import helper
17
18
def simple_random():
19 by gak
Added automatic scaling patch from Trent Mick
19
    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.
20
    chart.add_data(helper.random_data())
21
    chart.download('line-simple-random.png')
22
23
def xy_random():
22 by gak
- pygooglechart.py converted to unix line breaks
24
    chart = XYLineChart(settings.width, settings.height,
19 by gak
Added automatic scaling patch from Trent Mick
25
                        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.
26
    chart.add_data(helper.random_data())
27
    chart.add_data(helper.random_data())
28
    chart.download('line-xy-random.png')
29
30
def xy_rect():
19 by gak
Added automatic scaling patch from Trent Mick
31
    chart = XYLineChart(settings.width, settings.height,
32
                        x_range=(0, 100), y_range=(0, 100))
15 by gak
Added more examples
33
    chart.add_data([10, 90, 90, 10, 10])
34
    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.
35
    chart.download('line-xy-rect.png')
36
37
def xy_circle():
19 by gak
Added automatic scaling patch from Trent Mick
38
    chart = XYLineChart(settings.width, settings.height,
39
                        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.
40
    steps = 40
41
    xradius = 25
42
    yradius = 45
43
    xmid = 50
44
    ymid = 50
45
    xlist = []
46
    ylist = []
47
    for angle in xrange(0, steps + 1):
48
        angle = float(angle) / steps * math.pi * 2
49
        xlist.append(math.cos(angle) * xradius + xmid)
50
        ylist.append(math.sin(angle) * yradius + ymid)
51
    chart.add_data(xlist)
52
    chart.add_data(ylist)
53
    chart.download('line-xy-circle.png')
54
22 by gak
- pygooglechart.py converted to unix line breaks
55
def sparklines():
56
    chart = SparkLineChart(settings.width, settings.height)
57
    chart.add_data(helper.random_data())
58
    chart.download('line-sparkline.png')
59
45 by gak
- Added filled line graph to examples
60
def fill():
61
62
    # Set the vertical range to 0 to 50
63
    max_y = 50
64
    chart = SimpleLineChart(200, 125, y_range=[0, max_y])
65
66
    # First value is the highest Y value. Two of them are needed to be
67
    # plottable.
68
    chart.add_data([max_y] * 2)
69
70
    # 3 sets of real data
71
    chart.add_data([28, 30, 31, 33, 35, 36, 42, 48, 43, 37, 32, 24, 28])
72
    chart.add_data([16, 18, 18, 21, 23, 23, 29, 36, 31, 25, 20, 12, 17])
73
    chart.add_data([7, 9, 9, 12, 14, 14, 20, 27, 21, 15, 10, 3, 7])
74
75
    # Last value is the lowest in the Y axis.
76
    chart.add_data([0] * 2)
77
78
    # Black lines
79
    chart.set_colours(['000000'] * 5)
80
81
    # Filled colours
82
    # from the top to the first real data
83
    chart.add_fill_range('76A4FB', 0, 1)
84
85
    # Between the 3 data values
86
    chart.add_fill_range('224499', 1, 2)
87
    chart.add_fill_range('FF0000', 2, 3)
88
    
89
    # from the last real data to the
90
    chart.add_fill_range('80C65A', 3, 4)
91
92
    # Some axis data
93
    chart.set_axis_labels(Axis.LEFT, ['', max_y / 2, max_y])
94
    chart.set_axis_labels(Axis.BOTTOM, ['Sep', 'Oct', 'Nov', 'Dec'])
95
96
    chart.download('line-fill.png')
97
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.
98
def main():
99
    simple_random()
100
    xy_random()
101
    xy_rect()
102
    xy_circle()
22 by gak
- pygooglechart.py converted to unix line breaks
103
    sparklines()
45 by gak
- Added filled line graph to examples
104
    fill()
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.
105
106
if __name__ == '__main__':
107
    main()
108