laszpio-googlecharts 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt ADDED
@@ -0,0 +1,48 @@
1
+ == 1.3.6
2
+ * support nil values. The Google Charts API specifies that a single underscore (_) can be used to omit a value from a line chart with 'simple' data encoding, and a double underscore (__) can do the same for a chart with 'extended' data encoding. (Matt Moyer)
3
+ * allow a label to appear on a google-o-meter via the :legend option. (hallettj)
4
+
5
+ == 1.3.5
6
+ * added code to properly escape image tag URLs (mokolabs)
7
+ * added themes support + 4 default themes (keynote, thirty7signals, pastel, greyscale) chart.line(:theme=>:keynote) (jakehow)
8
+
9
+ == 1.3.4
10
+ * updated documentation and cleaned it up (mokolabs)
11
+ * added support for custom class, id and alt tags when using the image_tag format (i.e Gchart.line(:data => [0, 26], :format => 'image_tag')) (mokolabs)
12
+
13
+ == 1.3.2 - 1.3.3
14
+ * changes required by github
15
+
16
+ == 1.3.1
17
+ * added width and spacing options
18
+
19
+ == 1.3.0
20
+ * added support for google-o-meter
21
+ * fixed a bug when the max value of a data set was 0
22
+
23
+ == 1.2.0
24
+ * added support for sparklines
25
+
26
+ == 1.1.0
27
+ * fixed another bug fix related to the uri escaping required to download the file properly.
28
+
29
+ == 1.0.0
30
+ * fixed the (URI::InvalidURIError) issue
31
+
32
+ == 0.2.0
33
+ * added export options (file and image tag)
34
+ * added support for all arguments to be passed as a string or an array
35
+
36
+ == 0.1.0 2007-12-11
37
+ * fixed the axis labels
38
+
39
+ == 0.0.3 2007-12-11
40
+ * added :chart_background alias and fixed a bug related to the background colors.
41
+
42
+ == 0.0.2 2007-12-11
43
+ * added support for more features and aliases
44
+
45
+ == 0.0.1 2007-12-08
46
+
47
+ * 1 major enhancement:
48
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Matt Aimonetti
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,18 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ lib/gchart.rb
9
+ lib/gchart/aliases.rb
10
+ lib/gchart/theme.rb
11
+ lib/gchart/version.rb
12
+ setup.rb
13
+ spec/gchart_spec.rb
14
+ spec/theme_spec.rb
15
+ spec/spec.opts
16
+ spec/spec_helper.rb
17
+ tasks/environment.rake
18
+ tasks/rspec.rake
data/README.txt ADDED
@@ -0,0 +1,9 @@
1
+ CHECK README.markdown (open as a text file)
2
+
3
+ Or check:
4
+
5
+ http://googlecharts.rubyforge.org
6
+
7
+ and/or
8
+
9
+ http://github.com/laszpio/googlecharts
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
5
+
6
+ desc %{Update ".manifest" with the latest list of project filenames. Respect\
7
+ .gitignore by excluding everything that git ignores. Update `files` and\
8
+ `test_files` arrays in "*.gemspec" file if it's present.}
9
+ task :manifest do
10
+ list = Dir['**/*'].sort
11
+ spec_file = Dir['*.gemspec'].first
12
+ list -= [spec_file] if spec_file
13
+
14
+ File.read('.gitignore').each_line do |glob|
15
+ glob = glob.chomp.sub(/^\//, '')
16
+ list -= Dir[glob]
17
+ list -= Dir["#{glob}/**/*"] if File.directory?(glob) and !File.symlink?(glob)
18
+ puts "excluding #{glob}"
19
+ end
20
+
21
+ if spec_file
22
+ spec = File.read spec_file
23
+ spec.gsub! /^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx do
24
+ assignment = $1
25
+ bunch = $2 ? list.grep(/^test\//) : list
26
+ '%s%%w(%s)' % [assignment, bunch.join(' ')]
27
+ end
28
+
29
+ File.open(spec_file, 'w') {|f| f << spec }
30
+ end
31
+ File.open('.manifest', 'w') {|f| f << list.join("\n") }
32
+ end
data/config/hoe.rb ADDED
@@ -0,0 +1,71 @@
1
+ require 'gchart/version'
2
+
3
+ AUTHOR = 'Matt Aimonetti' # can also be an array of Authors
4
+ EMAIL = "mattaimonetti@gmail.com"
5
+ DESCRIPTION = "description of gem"
6
+ GEM_NAME = 'googlecharts' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'googlecharts' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "matt_a"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = GchartInfo::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'gchart documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.author = AUTHOR
52
+ p.description = DESCRIPTION
53
+ p.email = EMAIL
54
+ p.summary = DESCRIPTION
55
+ p.url = HOMEPATH
56
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
57
+ p.test_globs = ["test/**/test_*.rb"]
58
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
59
+
60
+ # == Optional
61
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
62
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
63
+
64
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
65
+
66
+ end
67
+
68
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
69
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
70
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
71
+ hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,16 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile could use '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ end
12
+ end
13
+
14
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
15
+
16
+ require 'gchart'
data/lib/gchart.rb ADDED
@@ -0,0 +1,417 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'gchart/version'
3
+ require 'gchart/theme'
4
+ require "open-uri"
5
+ require "uri"
6
+
7
+ class Gchart
8
+
9
+ include GchartInfo
10
+
11
+ @@url = "http://chart.apis.google.com/chart?"
12
+ @@types = ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize', 'sparkline', 'meter']
13
+ @@simple_chars = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
14
+ @@chars = @@simple_chars + ['-', '.']
15
+ @@ext_pairs = @@chars.map { |char_1| @@chars.map { |char_2| char_1 + char_2 } }.flatten
16
+ @@file_name = 'chart.png'
17
+
18
+ attr_accessor :title, :type, :width, :height, :horizontal, :grouped, :legend, :data, :encoding, :max_value, :bar_colors,
19
+ :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :class
20
+
21
+ # Support for Gchart.line(:title => 'my title', :size => '400x600')
22
+ def self.method_missing(m, options={})
23
+ # Start with theme defaults if a theme is set
24
+ theme = options[:theme]
25
+ options = theme ? GChart::Theme.load(theme).to_options.merge(options) : options
26
+ # Extract the format and optional filename, then clean the hash
27
+ format = options[:format] || 'url'
28
+ @@file_name = options[:filename] unless options[:filename].nil?
29
+ options.delete(:format)
30
+ options.delete(:filename)
31
+ # create the chart and return it in the format asked for
32
+ if @@types.include?(m.to_s)
33
+ chart = new(options.merge!({:type => m}))
34
+ chart.send(format)
35
+ elsif m.to_s == 'version'
36
+ Gchart::VERSION::STRING
37
+ else
38
+ "#{m} is not a supported chart format, please use one of the following: #{supported_types}."
39
+ end
40
+ end
41
+
42
+ def initialize(options={})
43
+ @type = :line
44
+ @data = []
45
+ @width = 300
46
+ @height = 200
47
+ @horizontal = false
48
+ @grouped = false
49
+ @encoding = 'simple'
50
+ @max_value = 'auto'
51
+ # Sets the alt tag when chart is exported as image tag
52
+ @alt = 'Google Chart'
53
+ # Sets the CSS id selector when chart is exported as image tag
54
+ @id = false
55
+ # Sets the CSS class selector when chart is exported as image tag
56
+ @class = false
57
+
58
+ # set the options value if definable
59
+ options.each do |attribute, value|
60
+ send("#{attribute.to_s}=", value) if self.respond_to?("#{attribute}=")
61
+ end
62
+ end
63
+
64
+ def self.supported_types
65
+ @@types.join(' ')
66
+ end
67
+
68
+ # Defines the Graph size using the following format:
69
+ # width X height
70
+ def size=(size='300x200')
71
+ @width, @height = size.split("x").map { |dimension| dimension.to_i }
72
+ end
73
+
74
+ def size
75
+ "#{@width}x#{@height}"
76
+ end
77
+
78
+ # Sets the orientation of a bar graph
79
+ def orientation=(orientation='h')
80
+ if orientation == 'h' || orientation == 'horizontal'
81
+ self.horizontal = true
82
+ elsif orientation == 'v' || orientation == 'vertical'
83
+ self.horizontal = false
84
+ end
85
+ end
86
+
87
+ # Sets the bar graph presentation (stacked or grouped)
88
+ def stacked=(option=true)
89
+ @grouped = option ? false : true
90
+ end
91
+
92
+ def bg=(options)
93
+ if options.is_a?(String)
94
+ @bg_color = options
95
+ elsif options.is_a?(Hash)
96
+ @bg_color = options[:color]
97
+ @bg_type = options[:type]
98
+ @bg_angle = options[:angle]
99
+ end
100
+ end
101
+
102
+ def graph_bg=(options)
103
+ if options.is_a?(String)
104
+ @chart_color = options
105
+ elsif options.is_a?(Hash)
106
+ @chart_color = options[:color]
107
+ @chart_type = options[:type]
108
+ @chart_angle = options[:angle]
109
+ end
110
+ end
111
+
112
+ def self.jstize(string)
113
+ string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s(16).upcase}"}
114
+ end
115
+ # load all the custom aliases
116
+ require 'gchart/aliases'
117
+
118
+ protected
119
+
120
+ # Returns the chart's generated PNG as a blob. (borrowed from John's gchart.rubyforge.org)
121
+ def fetch
122
+ open(query_builder) { |io| io.read }
123
+ end
124
+
125
+ # Writes the chart's generated PNG to a file. (borrowed from John's gchart.rubyforge.org)
126
+ def write(io_or_file=@@file_name)
127
+ return io_or_file.write(fetch) if io_or_file.respond_to?(:write)
128
+ open(io_or_file, "w+") { |io| io.write(fetch) }
129
+ end
130
+
131
+ # Format
132
+
133
+ def image_tag
134
+ image = "<img"
135
+ image += " id=\"#{@id}\"" if @id
136
+ image += " class=\"#{@class}\"" if @class
137
+ image += " src=\"#{query_builder(:html)}\""
138
+ image += " width=\"#{@width}\""
139
+ image += " height=\"#{@height}\""
140
+ image += " alt=\"#{@alt}\""
141
+ image += " title=\"#{@title}\"" if @title
142
+ image += " />"
143
+ end
144
+
145
+ alias_method :img_tag, :image_tag
146
+
147
+ def url
148
+ query_builder
149
+ end
150
+
151
+ def file
152
+ write
153
+ end
154
+
155
+ #
156
+ def jstize(string)
157
+ Gchart.jstize(string)
158
+ end
159
+
160
+ private
161
+
162
+ # The title size cannot be set without specifying a color.
163
+ # A dark key will be used for the title color if no color is specified
164
+ def set_title
165
+ title_params = "chtt=#{title}"
166
+ unless (title_color.nil? && title_size.nil? )
167
+ title_params << "&chts=" + (color, size = (@title_color || '454545'), @title_size).compact.join(',')
168
+ end
169
+ title_params
170
+ end
171
+
172
+ def set_size
173
+ "chs=#{size}"
174
+ end
175
+
176
+ def set_data
177
+ data = send("#{@encoding}_encoding", @data)
178
+ "chd=#{data}"
179
+ end
180
+
181
+ def set_colors
182
+ bg_type = fill_type(@bg_type) || 's' if @bg_color
183
+ chart_type = fill_type(@chart_type) || 's' if @chart_color
184
+
185
+ "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('|')
186
+ end
187
+
188
+ # set bar, line colors
189
+ def set_bar_colors
190
+ @bar_colors = @bar_colors.join(',') if @bar_colors.is_a?(Array)
191
+ "chco=#{@bar_colors}"
192
+ end
193
+
194
+ # set bar spacing
195
+ # chbh=
196
+ # <bar width in pixels>,
197
+ # <optional space between bars in a group>,
198
+ # <optional space between groups>
199
+ def set_bar_width_and_spacing
200
+ width_and_spacing_values = case @bar_width_and_spacing
201
+ when String
202
+ @bar_width_and_spacing
203
+ when Array
204
+ @bar_width_and_spacing.join(',')
205
+ when Hash
206
+ width = @bar_width_and_spacing[:width] || 23
207
+ spacing = @bar_width_and_spacing[:spacing] || 4
208
+ group_spacing = @bar_width_and_spacing[:group_spacing] || 8
209
+ [width,spacing,group_spacing].join(',')
210
+ else
211
+ @bar_width_and_spacing.to_s
212
+ end
213
+ "chbh=#{width_and_spacing_values}"
214
+ end
215
+
216
+ def fill_for(type=nil, color='', angle=nil)
217
+ unless type.nil?
218
+ case type
219
+ when 'lg'
220
+ angle ||= 0
221
+ color = "#{color},0,ffffff,1" if color.split(',').size == 1
222
+ "#{type},#{angle},#{color}"
223
+ when 'ls'
224
+ angle ||= 90
225
+ color = "#{color},0.2,ffffff,0.2" if color.split(',').size == 1
226
+ "#{type},#{angle},#{color}"
227
+ else
228
+ "#{type},#{color}"
229
+ end
230
+ end
231
+ end
232
+
233
+ # A chart can have one or many legends.
234
+ # Gchart.line(:legend => 'label')
235
+ # or
236
+ # Gchart.line(:legend => ['first label', 'last label'])
237
+ def set_legend
238
+ return set_labels if @type == :pie || @type == :pie_3d || @type == :meter
239
+
240
+ if @legend.is_a?(Array)
241
+ "chdl=#{@legend.map{|label| "#{label}"}.join('|')}"
242
+ else
243
+ "chdl=#{@legend}"
244
+ end
245
+
246
+ end
247
+
248
+ def set_labels
249
+ if @legend.is_a?(Array)
250
+ "chl=#{@legend.map{|label| "#{label}"}.join('|')}"
251
+ else
252
+ "chl=#{@legend}"
253
+ end
254
+ end
255
+
256
+ def set_axis_with_labels
257
+ @axis_with_labels = @axis_with_labels.join(',') if @axis_with_labels.is_a?(Array)
258
+ "chxt=#{@axis_with_labels}"
259
+ end
260
+
261
+ def set_axis_labels
262
+ labels_arr = []
263
+ axis_labels.each_with_index do |labels,index|
264
+ if labels.is_a?(Array)
265
+ labels_arr << "#{index}:|#{labels.join('|')}"
266
+ else
267
+ labels_arr << "#{index}:|#{labels}"
268
+ end
269
+ end
270
+ "chxl=#{labels_arr.join('|')}"
271
+ end
272
+
273
+ def set_type
274
+ case @type
275
+ when :line
276
+ "cht=lc"
277
+ when :line_xy
278
+ "cht=lxy"
279
+ when :bar
280
+ "cht=b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s")
281
+ when :pie_3d
282
+ "cht=p3"
283
+ when :pie
284
+ "cht=p"
285
+ when :venn
286
+ "cht=v"
287
+ when :scatter
288
+ "cht=s"
289
+ when :sparkline
290
+ "cht=ls"
291
+ when :meter
292
+ "cht=gom"
293
+ end
294
+ end
295
+
296
+ def fill_type(type)
297
+ case type
298
+ when 'solid'
299
+ 's'
300
+ when 'gradient'
301
+ 'lg'
302
+ when 'stripes'
303
+ 'ls'
304
+ end
305
+ end
306
+
307
+ # Wraps a single dataset inside another array to support more datasets
308
+ def prepare_dataset(ds)
309
+ ds = [ds] unless ds.first.is_a?(Array)
310
+ ds
311
+ end
312
+
313
+ def convert_to_simple_value(number)
314
+ if number.nil?
315
+ "_"
316
+ else
317
+ value = @@simple_chars[number.to_i]
318
+ value.nil? ? "_" : value
319
+ end
320
+ end
321
+
322
+ # http://code.google.com/apis/chart/#simple
323
+ # Simple encoding has a resolution of 62 different values.
324
+ # Allowing five pixels per data point, this is sufficient for line and bar charts up
325
+ # to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size.
326
+ def simple_encoding(dataset=[])
327
+ dataset = prepare_dataset(dataset)
328
+ @max_value = dataset.compact.map{|ds| ds.compact.max}.max if @max_value == 'auto'
329
+
330
+ if @max_value == false || @max_value == 'false' || @max_value == :false || @max_value == 0
331
+ "s:" + dataset.map { |ds| ds.map { |number| number.nil? ? '_' : convert_to_simple_value(number) }.join }.join(',')
332
+ else
333
+ "s:" + dataset.map { |ds| ds.map { |number| number.nil? ? '_' : convert_to_simple_value( (@@simple_chars.size - 1) * number / @max_value) }.join }.join(',')
334
+ end
335
+
336
+ end
337
+
338
+ # http://code.google.com/apis/chart/#text
339
+ # Text encoding has a resolution of 1,000 different values,
340
+ # using floating point numbers between 0.0 and 100.0. Allowing five pixels per data point,
341
+ # integers (1.0, 2.0, and so on) are sufficient for line and bar charts up to about 500 pixels.
342
+ # Include a single decimal place (35.7 for example) if you require higher resolution.
343
+ # Text encoding is suitable for all other types of chart regardless of size.
344
+ def text_encoding(dataset=[])
345
+ dataset = prepare_dataset(dataset)
346
+ "t:" + dataset.map{ |ds| ds.join(',') }.join('|')
347
+ end
348
+
349
+ def convert_to_extended_value(number)
350
+ if number.nil?
351
+ '__'
352
+ else
353
+ value = @@ext_pairs[number.to_i]
354
+ value.nil? ? "__" : value
355
+ end
356
+ end
357
+
358
+ # http://code.google.com/apis/chart/#extended
359
+ # Extended encoding has a resolution of 4,096 different values
360
+ # and is best used for large charts where a large data range is required.
361
+ def extended_encoding(dataset=[])
362
+
363
+ dataset = prepare_dataset(dataset)
364
+ @max_value = dataset.compact.map{|ds| ds.compact.max}.max if @max_value == 'auto'
365
+
366
+ if @max_value == false || @max_value == 'false' || @max_value == :false
367
+ "e:" + dataset.map { |ds| ds.map { |number| number.nil? ? '__' : convert_to_extended_value(number)}.join }.join(',')
368
+ else
369
+ "e:" + dataset.map { |ds| ds.map { |number| number.nil? ? '__' : convert_to_extended_value( (@@ext_pairs.size - 1) * number / @max_value) }.join }.join(',')
370
+ end
371
+
372
+ end
373
+
374
+
375
+ def query_builder(options="")
376
+ query_params = instance_variables.map do |var|
377
+ case var
378
+ # Set the graph size
379
+ when '@width'
380
+ set_size unless @width.nil? || @height.nil?
381
+ when '@type'
382
+ set_type
383
+ when '@title'
384
+ set_title unless @title.nil?
385
+ when '@legend'
386
+ set_legend unless @legend.nil?
387
+ when '@bg_color'
388
+ set_colors
389
+ when '@chart_color'
390
+ set_colors if @bg_color.nil?
391
+ when '@data'
392
+ set_data unless @data == []
393
+ when '@bar_colors'
394
+ set_bar_colors
395
+ when '@bar_width_and_spacing'
396
+ set_bar_width_and_spacing
397
+ when '@axis_with_labels'
398
+ set_axis_with_labels
399
+ when '@axis_labels'
400
+ set_axis_labels
401
+ when '@custom'
402
+ @custom
403
+ end
404
+ end.compact
405
+
406
+ # Use ampersand as default delimiter
407
+ unless options == :html
408
+ delimiter = '&'
409
+ # Escape ampersand for html image tags
410
+ else
411
+ delimiter = '&amp;'
412
+ end
413
+
414
+ jstize(@@url + query_params.join(delimiter))
415
+ end
416
+
417
+ end