/+junk/pygooglechart-py3k

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/pygooglechart-py3k

« back to all changes in this revision

Viewing changes to examples/labels.py

  • Committer: gak
  • Date: 2007-12-13 23:36:21 UTC
  • Revision ID: git-v1:401ff0db96d316ad470ef91cb18d4053f0d8bc93
Added label tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
    print chart.get_url()
 
40
    chart.download('label-cat-proximity.png')
 
41
 
 
42
def many_labels():
 
43
    chart = SimpleLineChart(settings.width, settings.height)
 
44
 
 
45
    for a in xrange(3):
 
46
        for axis_type in (Axis.LEFT, Axis.RIGHT, Axis.BOTTOM):
 
47
            index = chart.set_axis_range(axis_type, 0, random.random() * 100)
 
48
            chart.set_axis_style(index, colour=helper.random_colour(), \
 
49
                font_size=random.random() * 10 + 5)
 
50
 
 
51
    chart.add_data(helper.random_data())
 
52
    chart.download('label-many.png')
 
53
 
 
54
def main():
 
55
    cat_proximity()
 
56
    many_labels()
 
57
 
 
58
if __name__ == '__main__':
 
59
    main()
 
60