| 1 | #!/usr/bin/env python |
|---|
| 2 | """ |
|---|
| 3 | Copyright Gerald Kaszuba 2008 |
|---|
| 4 | |
|---|
| 5 | This program is free software: you can redistribute it and/or modify |
|---|
| 6 | it under the terms of the GNU General Public License as published by |
|---|
| 7 | the Free Software Foundation, either version 3 of the License, or |
|---|
| 8 | (at your option) any later version. |
|---|
| 9 | |
|---|
| 10 | This program is distributed in the hope that it will be useful, |
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | GNU General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | """ |
|---|
| 18 | |
|---|
| 19 | import os |
|---|
| 20 | import sys |
|---|
| 21 | import math |
|---|
| 22 | import random |
|---|
| 23 | |
|---|
| 24 | ROOT = os.path.dirname(os.path.abspath(__file__)) |
|---|
| 25 | sys.path.insert(0, os.path.join(ROOT, '..')) |
|---|
| 26 | |
|---|
| 27 | from pygooglechart import SimpleLineChart |
|---|
| 28 | from pygooglechart import Axis |
|---|
| 29 | |
|---|
| 30 | import settings |
|---|
| 31 | import helper |
|---|
| 32 | |
|---|
| 33 | def cat_proximity(): |
|---|
| 34 | """Cat proximity graph from http://xkcd.com/231/""" |
|---|
| 35 | chart = SimpleLineChart(int(settings.width * 1.5), settings.height) |
|---|
| 36 | chart.set_legend(['INTELLIGENCE', 'INSANITY OF STATEMENTS']) |
|---|
| 37 | |
|---|
| 38 | # intelligence |
|---|
| 39 | data_index = chart.add_data([100. / y for y in xrange(1, 15)]) |
|---|
| 40 | |
|---|
| 41 | # insanity of statements |
|---|
| 42 | chart.add_data([100. - 100 / y for y in xrange(1, 15)]) |
|---|
| 43 | |
|---|
| 44 | # line colours |
|---|
| 45 | chart.set_colours(['208020', '202080']) |
|---|
| 46 | |
|---|
| 47 | # "Near" and "Far" labels, they are placed automatically at either ends. |
|---|
| 48 | near_far_axis_index = chart.set_axis_labels(Axis.BOTTOM, ['FAR', 'NEAR']) |
|---|
| 49 | |
|---|
| 50 | # "Human Proximity to cat" label. Aligned to the center. |
|---|
| 51 | index = chart.set_axis_labels(Axis.BOTTOM, ['HUMAN PROXIMITY TO CAT']) |
|---|
| 52 | chart.set_axis_style(index, '202020', font_size=10, alignment=0) |
|---|
| 53 | chart.set_axis_positions(index, [50]) |
|---|
| 54 | |
|---|
| 55 | chart.download('label-cat-proximity.png') |
|---|
| 56 | |
|---|
| 57 | def many_labels(): |
|---|
| 58 | chart = SimpleLineChart(settings.width, settings.height) |
|---|
| 59 | |
|---|
| 60 | for a in xrange(3): |
|---|
| 61 | for axis_type in (Axis.LEFT, Axis.RIGHT, Axis.BOTTOM): |
|---|
| 62 | index = chart.set_axis_range(axis_type, 0, random.random() * 100) |
|---|
| 63 | chart.set_axis_style(index, colour=helper.random_colour(), \ |
|---|
| 64 | font_size=random.random() * 10 + 5) |
|---|
| 65 | |
|---|
| 66 | chart.add_data(helper.random_data()) |
|---|
| 67 | chart.download('label-many.png') |
|---|
| 68 | |
|---|
| 69 | def main(): |
|---|
| 70 | cat_proximity() |
|---|
| 71 | many_labels() |
|---|
| 72 | |
|---|
| 73 | if __name__ == '__main__': |
|---|
| 74 | main() |
|---|