Commit 5b06e6519703e51cbedb1075149d2794d1d6dc91

Remove googlecharts plugin

Commit diff

vendor/plugins/googlecharts/History.txt

 
0== 1.1.0
1* fixed another bug fix related to the uri escaping required to download the file properly.
2== 1.0.0
3* fixed the (URI::InvalidURIError) issue
4== 0.2.0
5* added export options (file and image tag)
6* added support for all arguments to be passed as a string or an array
7
8== 0.1.0 2007-12-11
9* fixed the axis labels
10
11== 0.0.3 2007-12-11
12* added :chart_background alias and fixed a bug related to the background colors.
13
14== 0.0.2 2007-12-11
15* added support for more features and aliases
16
17== 0.0.1 2007-12-08
18
19* 1 major enhancement:
20 * Initial release
toggle raw diff

vendor/plugins/googlecharts/License.txt

 
0Copyright (c) 2007 Matt Aimonetti
1
2Permission is hereby granted, free of charge, to any person obtaining
3a copy of this software and associated documentation files (the
4"Software"), to deal in the Software without restriction, including
5without limitation the rights to use, copy, modify, merge, publish,
6distribute, sublicense, and/or sell copies of the Software, and to
7permit persons to whom the Software is furnished to do so, subject to
8the following conditions:
9
10The above copyright notice and this permission notice shall be
11included in all copies or substantial portions of the Software.
12
13THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
toggle raw diff

vendor/plugins/googlecharts/Manifest.txt

 
0History.txt
1License.txt
2Manifest.txt
3README.txt
4Rakefile
5config/hoe.rb
6config/requirements.rb
7lib/gchart.rb
8lib/gchart/aliases.rb
9lib/gchart/version.rb
10log/debug.log
11script/destroy
12script/generate
13script/txt2html
14setup.rb
15spec/gchart_spec.rb
16spec/spec.opts
17spec/spec_helper.rb
18tasks/deployment.rake
19tasks/environment.rake
20tasks/rspec.rake
21tasks/website.rake
22website/index.html
23website/index.txt
24website/javascripts/rounded_corners_lite.inc.js
25website/stylesheets/screen.css
26website/template.rhtml
toggle raw diff

vendor/plugins/googlecharts/README.txt

 
0The goal of this Gem is to make the creation of Google Charts a simple and easy task.
1
2Gchart.line( :size => '200x300',
3 :title => "example title",
4 :bg => 'efefef',
5 :legend => ['first data set label', 'second data set label'],
6 :data => [10, 30, 120, 45, 72])
7
8
9
10==Chart Type
11
12This gem supports the following types of charts:
13
14 * line,
15 * line_xy
16 * scatter
17 * bar
18 * venn
19 * pie
20 * pie_3d
21
22To create a chart, simply require Gchart and call any of the existing type:
23
24 require 'gchart'
25 Gchart.pie
26
27
28==Chart Title
29
30 To add a title to a chart pass the title to your chart:
31
32 Gchart.line(:title => 'Sexy Charts!')
33
34You can also specify the color and/or size
35
36 Gchart.line(:title => 'Sexy Charts!', :title_color => 'FF0000', :title_size => '20')
37
38==Colors
39
40Specify a color with at least a 6-letter string of hexadecimal values in the format RRGGBB. For example:
41
42 * FF0000 = red
43 * 00FF00 = green
44 * 0000FF = blue
45 * 000000 = black
46 * FFFFFF = white
47
48You can optionally specify transparency by appending a value between 00 and FF where 00 is completely transparent and FF completely opaque. For example:
49
50 * 0000FFFF = solid blue
51 * 0000FF00 = transparent blue
52
53If you need to use multiple colors, check the doc. Usually you just need to pass :attribute => 'FF0000,00FF00'
54
55Some charts have more options than other, make sure to refer to the documentation.
56
57===Background options:
58
59If you don't set the background option, your graph will be transparent.
60
61* You have 3 types of background http://code.google.com/apis/chart/#chart_or_background_fill
62
63- solid
64- gradient
65- stripes
66
67By default, if you set a background color, the fill will be solid:
68
69 Gchart.bar(:bg => 'efefef')
70
71However you can specify another fill type such as:
72
73 Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'})
74
75In the above code, we decided to have a gradient background, however since we only passed one color, the chart will start by the specified color and transition to white. By the default, the gradient angle is 0. Change it as follows:
76
77 Gchart.line(:title =>'bg example', :bg => {:color => 'efefef', :type => 'gradient', :angle => 90})
78
79For a more advance use of colors, refer to http://code.google.com/apis/chart/#linear_gradient
80
81 Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'})
82
83
84The same way you set the background color, you can also set the graph background:
85
86 Gchart.line(:graph_bg => 'cccccc')
87
88or both
89
90 Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'}, :graph_bg => 'cccccc', :title => 'Sexy Chart')
91
92
93Another type of fill is stripes http://code.google.com/apis/chart/#linear_stripes
94
95 Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'})
96
97You can customize the amount of stripes, colors and width by changing the color value.
98
99
100== Legend & Labels
101
102You probably will want to use a legend or labels for your graph.
103
104 Gchart.line(:legend => 'legend label')
105or
106 Gchart.line(:legend => ['legend label 1', 'legend label 2'])
107
108Will do the trick. You can also use the labels alias (makes more sense when using the pie charts)
109
110 chart = Gchart.pie(:labels => ['label 1', 'label 2'])
111
112== Multiple axis labels
113
114Multiple axis labels are available for line charts, bar charts and scatter plots.
115
116* x = bottom x-axis
117* t = top x-axis
118* y = left y-axis
119* r = right y-axis
120
121 Gchart.line(:label_axis => 'x,y,r')
122
123To add labels on these axis:
124
125 Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007'])
126
127
128== Data options
129
130Data are passed using an array or a nested array.
131
132 Gchart.bar(:data => [1,2,4,67,100,41,234])
133
134 Gchart.bar(:data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]])
135
136By default, the graph is drawn with your max value representing 100% of the height or width of the graph. You can change that my passing the max value.
137
138 Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 300)
139 Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 'auto')
140
141or if you want to use the real values from your dataset:
142
143 Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => false)
144
145
146You can also define a different encoding to add more granularity:
147
148 Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'simple')
149 Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'extended')
150 Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'text')
151
152
153==Pies:
154
155you have 2 type of pies:
156 - Gchart.pie() the standard 2D pie
157 _ Gchart.pie_3d() the fancy 3D pie
158
159To set labels, you can use one of these two options:
160
161 @legend = ['Matt_fu', 'Rob_fu']
162 Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data, :size => '400x200')
163 Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data, :size => '400x200')
164
165
166
167=== try yourself
168
169Gchart.bar( :data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]],
170 :title => 'SDRuby Fu level',
171 :legend => ['matt','patrick'],
172 :bg => {:color => '76A4FB', :type => 'gradient'},
173 :bar_colors => 'ff0000,00ff00')
174
175 "http://chart.apis.google.com/chart?chs=300x200&chdl=matt|patrick&chd=s:AAANUIv,JENCN9y&chtt=SDRuby+Fu+level&chf=bg,lg,0,76A4FB,0,ffffff,1&cht=bvs&chco=ff0000,00ff00"
176
177Gchart.pie(:data => [20,10,15,5,50], :title => 'SDRuby Fu level', :size => '400x200', :labels => ['matt', 'rob', 'patrick', 'ryan', 'jordan'])
178http://chart.apis.google.com/chart?cht=p&chs=400x200&chd=s:YMSG9&chtt=SDRuby+Fu+level&chl=matt|rob|patrick|ryan|jordan
toggle raw diff

vendor/plugins/googlecharts/Rakefile

 
0require 'config/requirements'
1require 'config/hoe' # setup Hoe + all gem configuration
2
3Dir['tasks/**/*.rake'].each { |rake| load rake }
toggle raw diff

vendor/plugins/googlecharts/config/hoe.rb

 
0require 'gchart/version'
1
2AUTHOR = 'Matt Aimonetti' # can also be an array of Authors
3EMAIL = "mattaimonetti@gmail.com"
4DESCRIPTION = "description of gem"
5GEM_NAME = 'googlecharts' # what ppl will type to install your gem
6RUBYFORGE_PROJECT = 'googlecharts' # The unix name for your project
7HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
8DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
9
10@config_file = "~/.rubyforge/user-config.yml"
11@config = nil
12RUBYFORGE_USERNAME = "matt_a"
13def rubyforge_username
14 unless @config
15 begin
16 @config = YAML.load(File.read(File.expand_path(@config_file)))
17 rescue
18 puts <<-EOS
19ERROR: No rubyforge config file found: #{@config_file}
20Run 'rubyforge setup' to prepare your env for access to Rubyforge
21 - See http://newgem.rubyforge.org/rubyforge.html for more details
22 EOS
23 exit
24 end
25 end
26 RUBYFORGE_USERNAME.replace @config["username"]
27end
28
29
30REV = nil
31# UNCOMMENT IF REQUIRED:
32# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
33VERS = GchartInfo::VERSION::STRING + (REV ? ".#{REV}" : "")
34RDOC_OPTS = ['--quiet', '--title', 'gchart documentation',
35 "--opname", "index.html",
36 "--line-numbers",
37 "--main", "README",
38 "--inline-source"]
39
40class Hoe
41 def extra_deps
42 @extra_deps.reject! { |x| Array(x).first == 'hoe' }
43 @extra_deps
44 end
45end
46
47# Generate all the Rake tasks
48# Run 'rake -T' to see list of generated tasks (from gem root directory)
49hoe = Hoe.new(GEM_NAME, VERS) do |p|
50 p.author = AUTHOR
51 p.description = DESCRIPTION
52 p.email = EMAIL
53 p.summary = DESCRIPTION
54 p.url = HOMEPATH
55 p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
56 p.test_globs = ["test/**/test_*.rb"]
57 p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
58
59 # == Optional
60 p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
61 #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
62
63 #p.spec_extras = {} # A hash of extra values to set in the gemspec.
64
65end
66
67CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
68PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
69hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
70hoe.rsync_args = '-av --delete --ignore-errors'
toggle raw diff

vendor/plugins/googlecharts/config/requirements.rb

 
0require 'fileutils'
1include FileUtils
2
3require 'rubygems'
4%w[rake hoe newgem rubigen].each do |req_gem|
5 begin
6 require req_gem
7 rescue LoadError
8 puts "This Rakefile could use '#{req_gem}' RubyGem."
9 puts "Installation: gem install #{req_gem} -y"
10 end
11end
12
13$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
14
15require 'gchart'
toggle raw diff

vendor/plugins/googlecharts/lib/gchart.rb

 
0$:.unshift File.dirname(__FILE__)
1require 'gchart/version'
2require "open-uri"
3require "uri"
4
5class Gchart
6
7 include GchartInfo
8
9 @@url = "http://chart.apis.google.com/chart?"
10 @@types = ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize']
11 @@simple_chars = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
12 @@chars = @@simple_chars + ['-', '.']
13 @@ext_pairs = @@chars.map { |char_1| @@chars.map { |char_2| char_1 + char_2 } }.flatten
14 @@file_name = 'chart.png'
15
16 attr_accessor :title, :type, :width, :height, :horizontal, :grouped, :legend, :data, :encoding, :max_value, :bar_colors,
17 :title_color, :title_size, :custom, :axis_with_labels, :axis_labels
18
19 class << self
20 # Support for Gchart.line(:title => 'my title', :size => '400x600')
21 def method_missing(m, options={})
22 # Extract the format and optional filename, then clean the hash
23 format = options[:format] || 'url'
24 @@file_name = options[:filename] unless options[:filename].nil?
25 options.delete(:format)
26 options.delete(:filename)
27 # create the chart and return it in the format asked for
28 if @@types.include?(m.to_s)
29 chart = new(options.merge!({:type => m}))
30 chart.send(format)
31 elsif m.to_s == 'version'
32 Gchart::VERSION::STRING
33 else
34 "#{m} is not a supported chart format, please use one of the following: #{supported_types}."
35 end
36 end
37
38 end
39
40 def initialize(options={})
41 @type = :line
42 @data = []
43 @width = 300
44 @height = 200
45 @horizontal = false
46 @grouped = false
47 @encoding = 'simple'
48 @max_value = 'auto'
49
50 # set the options value if definable
51 options.each do |attribute, value|
52 send("#{attribute.to_s}=", value) if self.respond_to?("#{attribute}=")
53 end
54 end
55
56 def self.supported_types
57 @@types.join(' ')
58 end
59
60 # Defines the Graph size using the following format:
61 # width X height
62 def size=(size='300x200')
63 @width, @height = size.split("x").map { |dimension| dimension.to_i }
64 end
65
66 def size
67 "#{@width}x#{@height}"
68 end
69
70 # Sets the orientation of a bar graph
71 def orientation=(orientation='h')
72 if orientation == 'h' || orientation == 'horizontal'
73 self.horizontal = true
74 elsif orientation == 'v' || orientation == 'vertical'
75 self.horizontal = false
76 end
77 end
78
79 # Sets the bar graph presentation (stacked or grouped)
80 def stacked=(option=true)
81 @grouped = option ? false : true
82 end
83
84 def bg=(options)
85 if options.is_a?(String)
86 @bg_color = options
87 elsif options.is_a?(Hash)
88 @bg_color = options[:color]
89 @bg_type = options[:type]
90 @bg_angle = options[:angle]
91 end
92 end
93
94 def graph_bg=(options)
95 if options.is_a?(String)
96 @chart_color = options
97 elsif options.is_a?(Hash)
98 @chart_color = options[:color]
99 @chart_type = options[:type]
100 @chart_angle = options[:angle]
101 end
102 end
103
104 def self.jstize(string)
105 string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s(16).upcase}"}
106 end
107 # load all the custom aliases
108 require 'gchart/aliases'
109
110 protected
111
112 # Returns the chart's generated PNG as a blob. (borrowed from John's gchart.rubyforge.org)
113 def fetch
114 open(query_builder) { |io| io.read }
115 end
116
117 # Writes the chart's generated PNG to a file. (borrowed from John's gchart.rubyforge.org)
118 def write(io_or_file=@@file_name)
119 return io_or_file.write(fetch) if io_or_file.respond_to?(:write)
120 open(io_or_file, "w+") { |io| io.write(fetch) }
121 end
122
123 # Format
124
125 def img_tag
126 "<img src='#{query_builder}'/>"
127 end
128
129 def url
130 query_builder
131 end
132
133 def file
134 write
135 end
136
137 #
138 def jstize(string)
139 Gchart.jstize(string)
140 end
141
142 private
143
144 # The title size cannot be set without specifying a color.
145 # A dark key will be used for the title color if no color is specified
146 def set_title
147 title_params = "chtt=#{title}"
148 unless (title_color.nil? && title_size.nil? )
149 title_params << "&chts=" + (color, size = (@title_color || '454545'), @title_size).compact.join(',')
150 end
151 title_params
152 end
153
154 def set_size
155 "chs=#{size}"
156 end
157
158 def set_data
159 data = send("#{@encoding}_encoding", @data)
160 "chd=#{data}"
161 end
162
163 def set_colors
164 bg_type = fill_type(@bg_type) || 's' if @bg_color
165 chart_type = fill_type(@chart_type) || 's' if @chart_color
166
167 "chf=" + {'bg' => fill_for(bg_type, @bg_color, @bg_angle), 'c' => fill_for(chart_type, @chart_color, @chart_angle)}.map{|k,v| "#{k},#{v}" unless v.nil?}.compact.join('|')
168 end
169
170 # set bar, line colors
171 def set_bar_colors
172 @bar_colors = @bar_colors.join(',') if @bar_colors.is_a?(Array)
173 "chco=#{@bar_colors}"
174 end
175
176 def fill_for(type=nil, color='', angle=nil)
177 unless type.nil?
178 case type
179 when 'lg'
180 angle ||= 0
181 color = "#{color},0,ffffff,1" if color.split(',').size == 1
182 "#{type},#{angle},#{color}"
183 when 'ls'
184 angle ||= 90
185 color = "#{color},0.2,ffffff,0.2" if color.split(',').size == 1
186 "#{type},#{angle},#{color}"
187 else
188 "#{type},#{color}"
189 end
190 end
191 end
192
193 # A chart can have one or many legends.
194 # Gchart.line(:legend => 'label')
195 # or
196 # Gchart.line(:legend => ['first label', 'last label'])
197 def set_legend
198 return set_labels if @type == :pie || @type == :pie_3d
199
200 if @legend.is_a?(Array)
201 "chdl=#{@legend.map{|label| "#{label}"}.join('|')}"
202 else
203 "chdl=#{@legend}"
204 end
205
206 end
207
208 def set_labels
209 if @legend.is_a?(Array)
210 "chl=#{@legend.map{|label| "#{label}"}.join('|')}"
211 else
212 "chl=#{@legend}"
213 end
214 end
215
216 def set_axis_with_labels
217 @axis_with_labels = @axis_with_labels.join(',') if @axis_with_labels.is_a?(Array)
218 "chxt=#{@axis_with_labels}"
219 end
220
221 def set_axis_labels
222 labels_arr = []
223 axis_labels.each_with_index do |labels,index|
224 if labels.is_a?(Array)
225 labels_arr << "#{index}:|#{labels.join('|')}"
226 else
227 labels_arr << "#{index}:|#{labels}"
228 end
229 end
230 "chxl=#{labels_arr.join('|')}"
231 end
232
233 def set_type
234 case @type
235 when :line
236 "cht=lc"
237 when :line_xy
238 "cht=lxy"
239 when :bar
240 "cht=b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s")
241 when :pie_3d
242 "cht=p3"
243 when :pie
244 "cht=p"
245 when :venn
246 "cht=v"
247 when :scatter
248 "cht=s"
249 end
250 end
251
252 def fill_type(type)
253 case type
254 when 'solid'
255 's'
256 when 'gradient'
257 'lg'
258 when 'stripes'
259 'ls'
260 end
261 end
262
263 # Wraps a single dataset inside another array to support more datasets
264 def prepare_dataset(ds)
265 ds = [ds] unless ds.first.is_a?(Array)
266 ds
267 end
268
269 def convert_to_simple_value(number)
270 if number.nil?
271 "_"
272 else
273 value = @@simple_chars[number.to_i]
274 value.nil? ? "_" : value
275 end
276 end
277
278 # http://code.google.com/apis/chart/#simple
279 # Simple encoding has a resolution of 62 different values.
280 # Allowing five pixels per data point, this is sufficient for line and bar charts up
281 # to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size.
282 def simple_encoding(dataset=[])
283 dataset = prepare_dataset(dataset)
284 @max_value = dataset.map{|ds| ds.max}.max if @max_value == 'auto'
285
286 if @max_value == false || @max_value == 'false' || @max_value == :false
287 "s:" + dataset.map { |ds| ds.map { |number| convert_to_simple_value(number) }.join }.join(',')
288 else
289 "s:" + dataset.map { |ds| ds.map { |number| convert_to_simple_value( (@@simple_chars.size - 1) * number / @max_value) }.join }.join(',')
290 end
291
292 end
293
294 # http://code.google.com/apis/chart/#text
295 # Text encoding has a resolution of 1,000 different values,
296 # using floating point numbers between 0.0 and 100.0. Allowing five pixels per data point,
297 # integers (1.0, 2.0, and so on) are sufficient for line and bar charts up to about 500 pixels.
298 # Include a single decimal place (35.7 for example) if you require higher resolution.
299 # Text encoding is suitable for all other types of chart regardless of size.
300 def text_encoding(dataset=[])
301 dataset = prepare_dataset(dataset)
302 "t:" + dataset.map{ |ds| ds.join(',') }.join('|')
303 end
304
305 def convert_to_extended_value(number)
306 if number.nil?
307 '__'
308 else
309 value = @@ext_pairs[number.to_i]
310 value.nil? ? "__" : value
311 end
312 end
313
314 # http://code.google.com/apis/chart/#extended
315 # Extended encoding has a resolution of 4,096 different values
316 # and is best used for large charts where a large data range is required.
317 def extended_encoding(dataset=[])
318
319