googlecharts 1.3.6 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ log/*
3
+ .manifest
4
+ pkg
data/README ADDED
File without changes
@@ -0,0 +1,290 @@
1
+ The goal of this Gem is to make the creation of Google Charts a simple and easy task.
2
+
3
+ Gchart.line( :size => '200x300',
4
+ :title => "example title",
5
+ :bg => 'efefef',
6
+ :legend => ['first data set label', 'second data set label'],
7
+ :data => [10, 30, 120, 45, 72])
8
+
9
+
10
+ Check out the [full documentation over there](http://googlecharts.rubyforge.org/)
11
+
12
+ This gem is fully tested using Rspec, check the rspec folder for more examples.
13
+
14
+ See at the bottom of this file who reported using this gem.
15
+
16
+ Chart Type
17
+ -------------
18
+
19
+ This gem supports the following types of charts:
20
+
21
+ * line,
22
+ * line_xy
23
+ * sparkline
24
+ * scatter
25
+ * bar
26
+ * venn
27
+ * pie
28
+ * pie_3d
29
+ * google meter
30
+
31
+ Googlecharts also supports graphical themes and you can easily load your own.
32
+
33
+ To create a chart, simply require Gchart and call any of the existing type:
34
+
35
+ require 'gchart'
36
+ Gchart.pie
37
+
38
+
39
+ Chart Title
40
+ -------------
41
+
42
+ To add a title to a chart pass the title to your chart:
43
+
44
+ Gchart.line(:title => 'Sexy Charts!')
45
+
46
+ You can also specify the color and/or size
47
+
48
+ Gchart.line(:title => 'Sexy Charts!', :title_color => 'FF0000', :title_size => '20')
49
+
50
+ Colors
51
+ -------------
52
+
53
+ Specify a color with at least a 6-letter string of hexadecimal values in the format RRGGBB. For example:
54
+
55
+ * FF0000 = red
56
+ * 00FF00 = green
57
+ * 0000FF = blue
58
+ * 000000 = black
59
+ * FFFFFF = white
60
+
61
+ You can optionally specify transparency by appending a value between 00 and FF where 00 is completely transparent and FF completely opaque. For example:
62
+
63
+ * 0000FFFF = solid blue
64
+ * 0000FF00 = transparent blue
65
+
66
+ If you need to use multiple colors, check the doc. Usually you just need to pass :attribute => 'FF0000,00FF00'
67
+
68
+ Some charts have more options than other, make sure to refer to the documentation.
69
+
70
+ Background options:
71
+ -------------
72
+
73
+ If you don't set the background option, your graph will be transparent.
74
+
75
+ * You have 3 types of background http://code.google.com/apis/chart/#chart_or_background_fill
76
+
77
+ - solid
78
+ - gradient
79
+ - stripes
80
+
81
+ By default, if you set a background color, the fill will be solid:
82
+
83
+ Gchart.bar(:bg => 'efefef')
84
+
85
+ However you can specify another fill type such as:
86
+
87
+ Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'})
88
+
89
+ In 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:
90
+
91
+ Gchart.line(:title =>'bg example', :bg => {:color => 'efefef', :type => 'gradient', :angle => 90})
92
+
93
+ For a more advance use of colors, refer to http://code.google.com/apis/chart/#linear_gradient
94
+
95
+ Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'})
96
+
97
+
98
+ The same way you set the background color, you can also set the graph background:
99
+
100
+ Gchart.line(:graph_bg => 'cccccc')
101
+
102
+ or both
103
+
104
+ Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'}, :graph_bg => 'cccccc', :title => 'Sexy Chart')
105
+
106
+
107
+ Another type of fill is stripes http://code.google.com/apis/chart/#linear_stripes
108
+
109
+ Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'})
110
+
111
+ You can customize the amount of stripes, colors and width by changing the color value.
112
+
113
+
114
+ Themes
115
+ --------
116
+
117
+ Googlecharts comes with 4 themes: keynote, thirty7signals, pastel and greyscale. (ganked from [Gruff](http://github.com/topfunky/gruff/tree/master)
118
+
119
+
120
+ Gchart.line(
121
+ :theme => :keynote,
122
+ :data => [[0,40,10,70,20],[41,10,80,50,40],[20,60,30,60,80],[5,23,35,10,56],[80,90,5,30,60]],
123
+ :title => 'keynote'
124
+ )
125
+
126
+ * keynote
127
+
128
+ ![keynote](http://chart.apis.google.com/chart?chtt=keynote&chco=6886B4,FDD84E,72AE6E,D1695E,8A6EAF,EFAA43&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo&chf=c,s,FFFFFF|bg,s,000000)
129
+
130
+ * thirty7signals
131
+
132
+ ![37signals](http://chart.apis.google.com/chart?chtt=thirty7signals&chco=FFF804,336699,339933,ff0000,cc99cc,cf5910&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo&chf=bg,s,FFFFFF)
133
+
134
+ * pastel
135
+
136
+ ![pastel](http://chart.apis.google.com/chart?chtt=pastel&chco=a9dada,aedaa9,daaea9,dadaa9,a9a9da&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo)
137
+
138
+ * greyscale
139
+
140
+ ![greyscale](http://chart.apis.google.com/chart?chtt=greyscale&chco=282828,383838,686868,989898,c8c8c8,e8e8e8&chs=300x200&cht=lc&chd=s:AbGvN,bG2hb,NoUo2,DPXGl,29DUo)
141
+
142
+
143
+ You can also use your own theme. Create a yml file using the same format as the themes located in lib/themes.yml
144
+
145
+ Load your theme(s):
146
+
147
+ Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/another_test_theme.yml")
148
+
149
+ And use the standard method signature to use your own theme:
150
+
151
+ Gchart.line(:theme => :custom_theme, :data => [[0, 40, 10, 70, 20],[41, 10, 80, 50]], :title => 'greyscale')
152
+
153
+
154
+
155
+ Legend & Labels
156
+ -------------
157
+
158
+ You probably will want to use a legend or labels for your graph.
159
+
160
+ Gchart.line(:legend => 'legend label')
161
+ or
162
+ Gchart.line(:legend => ['legend label 1', 'legend label 2'])
163
+
164
+ Will do the trick. You can also use the labels alias (makes more sense when using the pie charts)
165
+
166
+ chart = Gchart.pie(:labels => ['label 1', 'label 2'])
167
+
168
+ Multiple axis labels
169
+ -------------
170
+
171
+ Multiple axis labels are available for line charts, bar charts and scatter plots.
172
+
173
+ * x = bottom x-axis
174
+ * t = top x-axis
175
+ * y = left y-axis
176
+ * r = right y-axis
177
+
178
+ Gchart.line(:label_axis => 'x,y,r')
179
+
180
+ To add labels on these axis:
181
+
182
+ Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007'])
183
+
184
+
185
+ Data options
186
+ -------------
187
+
188
+ Data are passed using an array or a nested array.
189
+
190
+ Gchart.bar(:data => [1,2,4,67,100,41,234])
191
+
192
+ Gchart.bar(:data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]])
193
+
194
+ By 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.
195
+
196
+ Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 300)
197
+ Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 'auto')
198
+
199
+ or if you want to use the real values from your dataset:
200
+
201
+ Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => false)
202
+
203
+
204
+ You can also define a different encoding to add more granularity:
205
+
206
+ Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'simple')
207
+ Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'extended')
208
+ Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'text')
209
+
210
+
211
+ Pies:
212
+ -------------
213
+
214
+ you have 2 type of pies:
215
+ - Gchart.pie() the standard 2D pie
216
+ _ Gchart.pie_3d() the fancy 3D pie
217
+
218
+ To set labels, you can use one of these two options:
219
+
220
+ @legend = ['Matt_fu', 'Rob_fu']
221
+ Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data, :size => '400x200')
222
+ Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data, :size => '400x200')
223
+
224
+ Bars:
225
+ -------------
226
+
227
+ A bar chart can accept options to set the width of the bars, spacing between bars and spacing between bar groups. To set these, you can either provide a string, array or hash.
228
+
229
+ The Google API sets these options in the order of width, spacing, and group spacing, with both spacing values being optional. So, if you provide a string or array, provide them in that order:
230
+
231
+ Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6') # width of 25, spacing of 6
232
+ Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6,12') # width of 25, spacing of 6, group spacing of 12
233
+ Gchart.bar(:data => @data, :bar_width_and_spacing => [25,6]) # width of 25, spacing of 6
234
+ Gchart.bar(:data => @data, :bar_width_and_spacing => 25) # width of 25
235
+
236
+ The hash lets you set these values directly, with the Google default values set for any options you don't include:
237
+
238
+ Gchart.bar(:data => @data, :bar_width_and_spacing => {:width => 19})
239
+ Gchart.bar(:data => @data, :bar_width_and_spacing => {:spacing => 10, :group_spacing => 12})
240
+
241
+ Sparklines:
242
+ -------------
243
+
244
+ A sparkline chart has exactly the same parameters as a line chart. The only difference is that the axes lines are not drawn for sparklines by default.
245
+
246
+
247
+ Google-o-meter
248
+ -------------
249
+
250
+ A Google-o-meter has a few restrictions. It may only use a solid filled background and it may only have one label.
251
+
252
+ try yourself
253
+ -------------
254
+
255
+ Gchart.bar( :data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]],
256
+ :title => 'SD Ruby Fu level',
257
+ :legend => ['matt','patrick'],
258
+ :bg => {:color => '76A4FB', :type => 'gradient'},
259
+ :bar_colors => 'ff0000,00ff00')
260
+
261
+ "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"
262
+
263
+ Gchart.pie(:data => [20,10,15,5,50], :title => 'SDRuby Fu level', :size => '400x200', :labels => ['matt', 'rob', 'patrick', 'ryan', 'jordan'])
264
+ http://chart.apis.google.com/chart?cht=p&chs=400x200&chd=s:YMSG9&chtt=SDRuby+Fu+level&chl=matt|rob|patrick|ryan|jordan
265
+
266
+
267
+ People reported using this gem:
268
+ ---------------------
269
+
270
+ ![github](http://img.skitch.com/20080627-r14subqdx2ye3w13qefbx974gc.png)
271
+
272
+ * [http://github.com](http://github.com)
273
+
274
+ ![stafftool.com](http://stafftool.com/images/masthead_screen.gif)
275
+
276
+ * [http://stafftool.com/](http://stafftool.com/) Takeo (contributor)
277
+
278
+ ![graffletopia.com](http://img.skitch.com/20080627-g2pp89h7gdbh15m1rr8hx48jep.jpg)
279
+
280
+ * [graffleropia.com](http://graffletopia.com) Mokolabs (contributor)
281
+
282
+ ![gumgum](http://img.skitch.com/20080627-kc1weqsbkmxeqhwiyriq3n6g8k.jpg)
283
+
284
+ * [http://gumgum.com](http://gumgum.com) Mattetti (Author)
285
+
286
+ ![http://img.skitch.com/20080627-n48j8pb2r7irsewfeh4yp3da12.jpg]
287
+
288
+ * [http://feedflix.com/](http://feedflix.com/) [lifehacker article](http://lifehacker.com/395610/feedflix-creates-detailed-charts-from-your-netflix-use)
289
+
290
+ * [California State University, Chico](http://www.csuchico.edu/)
data/Rakefile CHANGED
@@ -1,32 +1,20 @@
1
- require 'config/requirements'
2
- require 'config/hoe' # setup Hoe + all gem configuration
1
+ require 'rubygems'
2
+ require 'rake'
3
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
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gemspec|
7
+ gemspec.name = "googlecharts"
8
+ gemspec.summary = "Generate charts using Google API & Ruby"
9
+ gemspec.description = "Generate charts using Google API & Ruby"
10
+ gemspec.email = "mattaimonetti@gmail.com"
11
+ gemspec.homepage = "http://googlecharts.rubyforge.org/"
12
+ gemspec.authors = ["Matt Aimonetti"]
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
17
+ end
13
18
 
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
19
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
20
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.4.0
@@ -3,20 +3,23 @@ require 'gchart/version'
3
3
  require 'gchart/theme'
4
4
  require "open-uri"
5
5
  require "uri"
6
+ require "cgi"
7
+ require 'enumerator'
6
8
 
7
9
  class Gchart
8
10
 
9
11
  include GchartInfo
10
12
 
11
13
  @@url = "http://chart.apis.google.com/chart?"
12
- @@types = ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize', 'sparkline', 'meter']
14
+ @@types = ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize', 'sparkline', 'meter', 'map']
13
15
  @@simple_chars = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
14
16
  @@chars = @@simple_chars + ['-', '.']
15
17
  @@ext_pairs = @@chars.map { |char_1| @@chars.map { |char_2| char_1 + char_2 } }.flatten
16
18
  @@file_name = 'chart.png'
17
19
 
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
+ attr_accessor :title, :type, :width, :height, :horizontal, :grouped, :legend, :data, :encoding, :min_value, :max_value, :bar_colors,
21
+ :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :class,
22
+ :range_markers, :geographical_area, :map_colors, :country_codes, :axis_range
20
23
 
21
24
  # Support for Gchart.line(:title => 'my title', :size => '400x600')
22
25
  def self.method_missing(m, options={})
@@ -28,6 +31,8 @@ class Gchart
28
31
  @@file_name = options[:filename] unless options[:filename].nil?
29
32
  options.delete(:format)
30
33
  options.delete(:filename)
34
+ #update map_colors to be bar_colors
35
+ options.update(:bar_colors => options[:map_colors]) if options.has_key?(:map_colors)
31
36
  # create the chart and return it in the format asked for
32
37
  if @@types.include?(m.to_s)
33
38
  chart = new(options.merge!({:type => m}))
@@ -109,6 +114,26 @@ class Gchart
109
114
  end
110
115
  end
111
116
 
117
+ # returns the full data range as an array
118
+ # it also sets the data range if not defined
119
+ def full_data_range(ds)
120
+ return [@min, @max] unless (@min.nil? || @max.nil?)
121
+ @max = (max_value.nil? || max_value == 'auto') ? ds.compact.map{|mds| mds.compact.max}.max : max_value
122
+ if (min_value.nil? || min_value == 'auto')
123
+ min_ds_value = ds.compact.map{|mds| mds.compact.min}.min || 0
124
+ @min = (min_ds_value < 0) ? min_ds_value : 0
125
+ else
126
+ @min = min_value
127
+ end
128
+ @axis_range = [[@min,@max]]
129
+ end
130
+
131
+ def dataset
132
+ @dataset ||= prepare_dataset(data)
133
+ full_data_range(@dataset) unless @axis_range
134
+ @dataset
135
+ end
136
+
112
137
  def self.jstize(string)
113
138
  string.gsub(' ', '+').gsub(/\[|\{|\}|\||\\|\^|\[|\]|\`|\]/) {|c| "%#{c[0].to_s(16).upcase}"}
114
139
  end
@@ -155,7 +180,7 @@ class Gchart
155
180
  #
156
181
  def jstize(string)
157
182
  Gchart.jstize(string)
158
- end
183
+ end
159
184
 
160
185
  private
161
186
 
@@ -174,7 +199,7 @@ class Gchart
174
199
  end
175
200
 
176
201
  def set_data
177
- data = send("#{@encoding}_encoding", @data)
202
+ data = send("#{@encoding}_encoding")
178
203
  "chd=#{data}"
179
204
  end
180
205
 
@@ -191,6 +216,11 @@ class Gchart
191
216
  "chco=#{@bar_colors}"
192
217
  end
193
218
 
219
+ def set_country_codes
220
+ @country_codes = @country_codes.join() if @country_codes.is_a?(Array)
221
+ "chld=#{@country_codes}"
222
+ end
223
+
194
224
  # set bar spacing
195
225
  # chbh=
196
226
  # <bar width in pixels>,
@@ -213,6 +243,21 @@ class Gchart
213
243
  "chbh=#{width_and_spacing_values}"
214
244
  end
215
245
 
246
+ def set_range_markers
247
+ markers = case @range_markers
248
+ when Hash
249
+ set_range_marker(@range_markers)
250
+ when Array
251
+ range_markers.collect{|marker| set_range_marker(marker)}.join('|')
252
+ end
253
+ "chm=#{markers}"
254
+ end
255
+
256
+ def set_range_marker(options)
257
+ orientation = ['vertical', 'Vertical', 'V', 'v', 'R'].include?(options[:orientation]) ? 'R' : 'r'
258
+ "#{orientation},#{options[:color]},0,#{options[:start_position]},#{options[:stop_position]}#{',1' if options[:overlaid?]}"
259
+ end
260
+
216
261
  def fill_for(type=nil, color='', angle=nil)
217
262
  unless type.nil?
218
263
  case type
@@ -238,7 +283,7 @@ class Gchart
238
283
  return set_labels if @type == :pie || @type == :pie_3d || @type == :meter
239
284
 
240
285
  if @legend.is_a?(Array)
241
- "chdl=#{@legend.map{|label| "#{label}"}.join('|')}"
286
+ "chdl=#{@legend.map{|label| "#{CGI::escape(label)}"}.join('|')}"
242
287
  else
243
288
  "chdl=#{@legend}"
244
289
  end
@@ -270,6 +315,24 @@ class Gchart
270
315
  "chxl=#{labels_arr.join('|')}"
271
316
  end
272
317
 
318
+ # http://code.google.com/apis/chart/labels.html#axis_range
319
+ # Specify a range for axis labels
320
+ def set_axis_range
321
+ # a passed axis_range should look like:
322
+ # [[10,100]] or [[10,100,4]] or [[10,100], [20,300]]
323
+ # in the second example, 4 is the interval
324
+ dataset # just making sure we processed the data before
325
+ if axis_range && axis_range.respond_to?(:each) && axis_range.first.respond_to?(:each)
326
+ 'chxr=' + axis_range.enum_for(:each_with_index).map{|range, index| [index, range[0], range[1], range[2]].compact.join(',')}.join("|")
327
+ else
328
+ nil
329
+ end
330
+ end
331
+
332
+ def set_geographical_area
333
+ "chtm=#{@geographical_area}"
334
+ end
335
+
273
336
  def set_type
274
337
  case @type
275
338
  when :line
@@ -290,6 +353,8 @@ class Gchart
290
353
  "cht=ls"
291
354
  when :meter
292
355
  "cht=gom"
356
+ when :map
357
+ "cht=t"
293
358
  end
294
359
  end
295
360
 
@@ -323,8 +388,7 @@ class Gchart
323
388
  # Simple encoding has a resolution of 62 different values.
324
389
  # Allowing five pixels per data point, this is sufficient for line and bar charts up
325
390
  # 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)
391
+ def simple_encoding
328
392
  @max_value = dataset.compact.map{|ds| ds.compact.max}.max if @max_value == 'auto'
329
393
 
330
394
  if @max_value == false || @max_value == 'false' || @max_value == :false || @max_value == 0
@@ -336,14 +400,19 @@ class Gchart
336
400
  end
337
401
 
338
402
  # 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('|')
403
+ # Text encoding with data scaling lets you specify arbitrary positive or
404
+ # negative floating point numbers, in combination with a scaling parameter
405
+ # that lets you specify a custom range for your chart. This chart is useful
406
+ # when you don't want to worry about limiting your data to a specific range,
407
+ # or do the calculations to scale your data down or up to fit nicely inside
408
+ # a chart.
409
+ #
410
+ # Valid values range from (+/-)9.999e(+/-)100, and only four non-zero digits are supported (that is, 123400, 1234, 12.34, and 0.1234 are valid, but 12345, 123.45 and 123400.5 are not).
411
+ #
412
+ # This encoding is not available for maps.
413
+ #
414
+ def text_encoding
415
+ "t:" + dataset.map{ |ds| ds.join(',') }.join('|') + "&chds=#{@min},#{@max}"
347
416
  end
348
417
 
349
418
  def convert_to_extended_value(number)
@@ -354,16 +423,15 @@ class Gchart
354
423
  value.nil? ? "__" : value
355
424
  end
356
425
  end
426
+
357
427
 
358
428
  # http://code.google.com/apis/chart/#extended
359
429
  # Extended encoding has a resolution of 4,096 different values
360
430
  # 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)
431
+ def extended_encoding
364
432
  @max_value = dataset.compact.map{|ds| ds.compact.max}.max if @max_value == 'auto'
365
433
 
366
- if @max_value == false || @max_value == 'false' || @max_value == :false
434
+ if @max_value == false || @max_value == 'false' || @max_value == :false || @max_value == 0
367
435
  "e:" + dataset.map { |ds| ds.map { |number| number.nil? ? '__' : convert_to_extended_value(number)}.join }.join(',')
368
436
  else
369
437
  "e:" + dataset.map { |ds| ds.map { |number| number.nil? ? '__' : convert_to_extended_value( (@@ext_pairs.size - 1) * number / @max_value) }.join }.join(',')
@@ -373,8 +441,11 @@ class Gchart
373
441
 
374
442
 
375
443
  def query_builder(options="")
376
- query_params = instance_variables.map do |var|
444
+ dataset
445
+ query_params = instance_variables.sort.map do |var|
377
446
  case var
447
+ when '@data'
448
+ set_data unless @data == []
378
449
  # Set the graph size
379
450
  when '@width'
380
451
  set_size unless @width.nil? || @height.nil?
@@ -388,16 +459,22 @@ class Gchart
388
459
  set_colors
389
460
  when '@chart_color'
390
461
  set_colors if @bg_color.nil?
391
- when '@data'
392
- set_data unless @data == []
393
462
  when '@bar_colors'
394
463
  set_bar_colors
395
464
  when '@bar_width_and_spacing'
396
465
  set_bar_width_and_spacing
397
466
  when '@axis_with_labels'
398
467
  set_axis_with_labels
468
+ when '@axis_range'
469
+ set_axis_range if dataset
399
470
  when '@axis_labels'
400
471
  set_axis_labels
472
+ when '@range_markers'
473
+ set_range_markers
474
+ when '@geographical_area'
475
+ set_geographical_area
476
+ when '@country_codes'
477
+ set_country_codes
401
478
  when '@custom'
402
479
  @custom
403
480
  end