/+junk/pygooglechart-py3k

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/pygooglechart-py3k
10 by gak
Added label tests
1
#!/usr/bin/env python
2
3
import os
4
import sys
5
import math
6
import random
7
8
ROOT = os.path.dirname(os.path.abspath(__file__))
9
sys.path.insert(0, os.path.join(ROOT, '..'))
10
11
from pygooglechart import SimpleLineChart
12
from pygooglechart import Axis
13
14
import settings
15
import helper
16
17
def cat_proximity():
18
    """Cat proximity graph from http://xkcd.com/231/"""
19
    chart = SimpleLineChart(int(settings.width * 1.5), settings.height)
20
    chart.set_legend(['INTELLIGENCE', 'INSANITY OF STATEMENTS'])
21
22
    # intelligence
23
    data_index = chart.add_data([100. / y for y in xrange(1, 15)])
24
25
    # insanity of statements
26
    chart.add_data([100. - 100 / y for y in xrange(1, 15)])
27
28
    # line colours
29
    chart.set_colours(['208020', '202080'])
30
31
    # "Near" and "Far" labels, they are placed automatically at either ends.
32
    near_far_axis_index = chart.set_axis_labels(Axis.BOTTOM, ['FAR', 'NEAR'])
33
34
    # "Human Proximity to cat" label. Aligned to the center.
35
    index = chart.set_axis_labels(Axis.BOTTOM, ['HUMAN PROXIMITY TO CAT'])
36
    chart.set_axis_style(index, '202020', font_size=10, alignment=0)
37
    chart.set_axis_positions(index, [50])
38
39
    chart.download('label-cat-proximity.png')
40
41
def many_labels():
42
    chart = SimpleLineChart(settings.width, settings.height)
43
44
    for a in xrange(3):
45
        for axis_type in (Axis.LEFT, Axis.RIGHT, Axis.BOTTOM):
46
            index = chart.set_axis_range(axis_type, 0, random.random() * 100)
47
            chart.set_axis_style(index, colour=helper.random_colour(), \
48
                font_size=random.random() * 10 + 5)
49
50
    chart.add_data(helper.random_data())
51
    chart.download('label-many.png')
52
53
def main():
54
    cat_proximity()
55
    many_labels()
56
57
if __name__ == '__main__':
58
    main()
59