-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.txt
207 lines (149 loc) · 6 KB
/
README.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
################################################################################
# GChartWrapper - v0.9
# Copyright (C) 2009 Justin Quick <justquick@gmail.com>
#
# This program is free software. See attached LICENSE.txt for more info
################################################################################
GChartWrapper - Google Chart API Wrapper
The wrapper can render the URL of the Google chart based on your parameters.
With the chart you can render an HTML img tag to insert into webpages on the fly,
show it directly in a webbrowser, or save the chart PNG to disk.
################################################################################
Changelog:
-- 0.9 --
Switched to New BSD License
-- 0.8 --
Reverse functionality
>>> G = GChart.fromurl('http://chart.apis.google.com/chart?ch...')
<GChartWrapper.GChart instance at...>
Chaining fixes
Restuctured Axes functions
Centralized and added unittests
Enhanced unicode support
Demos pages w/ source code
-- 0.7 --
Full py3k compliance
Color name lookup from the css names: http://www.w3schools.com/css/css_colornames.asp
>>> G = Pie3D(range(1,5))
>>> G.color('green')
New charts Note,Text,Pin,Bubble
Updated Django templatetags to allow context inclusion and new charts
Added some more templating examples
-- 0.6 --
The wrapper now supports chaining
The old way:
>>> G = Pie3D(range(1,5))
>>> G.label('A','B','C','D')
>>> G.color('00dd00')
>>> print G
The new way with chaining
>>> print Pie3D(range(1,5)).label('A','B','C','D').color('00dd00')
New chart PieC for concentric pie charts
################################################################################
Doc TOC:
1.1 General
1.2 Constructing
1.3 Rendering and Viewing
2.1 Django extension
2.2 Static data
2.3 Dynamic data
3.1 Other Templating Langs
4.1 Test framework
5.1 API documentation
1.1 General
Customizable charts can be generated using the Google Chart API available
at http://code.google.com/apis/chart/. The GChart Wrapper allows Pythonic access
to the parameters of constructing the charts and displaying the URLs generated.
1.2 Constructing
class GChart(Dict):
"""Main chart class
Chart type must be valid for cht parameter
Dataset can be any python iterable and be multi dimensional
Kwargs will be put into chart API params if valid"""
def __init__(self, ctype=None, dataset=[], **kwargs):
The chart takes any iterable python data type (now including numpy arrays)
and does the encoding for you
# Datasets
>>> dataset = (1, 2, 3)
# Also 2 dimensional
>>> dataset = [[3,4], [5,6], [7,8]]
Initialize the chart with a valid type (see API reference) and dataset
# 3D Piechart
>>> GChart('p3', dataset)
<GChart p3 (1, 2, 3)>
# Encoding (simple/text/extended)
>>> G = GChart('p3', dataset, encoding='text')
# maxValue (for encoding values)
>>> G = GChart('p3', dataset, maxValue=100)
# Size
>>> G = GChart('p3', dataset, size=(300,150))
# OR directly pass in API parameters
>>> G = GChart('p3', dataset, chtt='My Cool Chart', chl='A|B|C')
1.3 Rendering and Viewing
The wrapper has many useful ways to take the URL of your chart and output it
into different formats like...
# As the chart URL itself using __str__
>>> str(G)
'http://chart.apis.google.com/chart?...'
# As an HTML <img> tag, kw arguments can be valid tag attributes
>>> G.img(height=500,id="chart")
'<img alt="" title="" src="http://chart.apis.google.com/chart?..." id="chart" height="500" >'
# Save chart to a file as PNG image, returns filename
>>> G.save('my-cool-chart')
'my-cool-chart.png'
# Now fetch the PngImageFile using the PIL module for manipulation
>>> G.image()
<PngImagePlugin.PngImageFile instance at 0xb795ee4c>
# Now that you have the image instance, the world is your oyster
# Try saving image as JPEG,GIF,etc.
>>> G.image().save('my-cool-chart.jpg','JPEG')
# Show URL directly in default web browser
>>> G.show()
2.1 Django Extension
Newer versions of the wrapper contain templatetags for generating charts in
Django templates. This allows for dynamic insertion of data for viewing on any
web application. Install the module first using `python setup.py install` then
place 'GChartWrapper.charts' in your INSTALLED_APPS and then you are ready to go.
Just include the '{% load charts %}' tag in your templates before making charts.
In the templating folder there is a folder called djangoproj which is an example
Django project to get you started.
2.2 Static data
Then try out some static data in your templates
{% chart Line GurMrabsClgubaolGvzCrgrefOrnhgvshyvforggregunahtyl %}
{% title 'The Zen of Python' 00cc00 36 %}
{% color 00cc00 %}
{% endchart %}
Or try a bubble
{% bubble icon_text_big snack bb $2.99 ffbb00 black as img %}
2.3 Dynamic data
The module supports dynamic insertion of any variable within the context like so
# View code
def example(request):
return render_to_response('example.html',{'dataset':range(50)})
# example.html template code
{% chart Line dataset %}
{% color 00cc00 %}
{% endchart %}
Look to example.html in the djangoproj for more detailed examples
3.1 Other Templating Languages
Other examples of using the chartwrapper in templating languages
Currently under development
Cheetah - done
Mako - done
Jinja2 - working, gonna b rough
Genshi?
Airspeed?
More to come...
4.1 Test framework
The module also comes with a test framework with sample charts available in
GChartWrapper/testing.py. The tests are executed through GChartWrapper/tests.py
Usage
$ python tests.py [<mode>]
Where mode is one of the following:
unit - Runs unit test cases for all charts to see if checksums match
save - Saves images of all charts in 'tests' folder
demo - Creates html demo pages (needs pygments)
url - Prints urls of all charts [default]
5.1 API Documentation
The Epydoc API information is generated in HTML format and available in the
docs folder under index.html