googlecharts 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig ADDED
@@ -0,0 +1,4 @@
1
+ ]�b��XylU@�
2
+ ��vtl5�>�@Y.��2Q`C��pT�_8I'ǒ��R�Lu��D������z-�e��(��B�|���c�&9�k��8&���i�
3
+ <3�x�a1�/�UA�D�3m�[�@\[Wm⑜�?�1?�0)x?c LC�s��w�[!~_&n�YK4�?��Xs�dg��q�|>g�#kSU�"��^@3����U
4
+ ���J�ի�{�Yb)�������3��%�$D�2��}h7�S
data/History.txt ADDED
@@ -0,0 +1,7 @@
1
+ == 0.0.2 2007-12-11
2
+ * added support for more features and aliases
3
+
4
+ == 0.0.1 2007-12-08
5
+
6
+ * 1 major enhancement:
7
+ * 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,27 @@
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/version.rb
11
+ log/debug.log
12
+ script/destroy
13
+ script/generate
14
+ script/txt2html
15
+ setup.rb
16
+ spec/gchart_spec.rb
17
+ spec/spec.opts
18
+ spec/spec_helper.rb
19
+ tasks/deployment.rake
20
+ tasks/environment.rake
21
+ tasks/rspec.rake
22
+ tasks/website.rake
23
+ website/index.html
24
+ website/index.txt
25
+ website/javascripts/rounded_corners_lite.inc.js
26
+ website/stylesheets/screen.css
27
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,179 @@
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
+
11
+ ==Chart Type
12
+
13
+ This gem supports the following types of charts:
14
+
15
+ * line,
16
+ * line_xy
17
+ * scatter
18
+ * bar
19
+ * venn
20
+ * pie
21
+ * pie_3d
22
+
23
+ To create a chart, simply require Gchart and call any of the existing type:
24
+
25
+ require 'gchart'
26
+ Gchart.pie
27
+
28
+
29
+ ==Chart Title
30
+
31
+ To add a title to a chart pass the title to your chart:
32
+
33
+ Gchart.line(:title => 'Sexy Charts!')
34
+
35
+ You can also specify the color and/or size
36
+
37
+ Gchart.line(:title => 'Sexy Charts!', :title_color => 'FF0000', :title_size => '20')
38
+
39
+ ==Colors
40
+
41
+ Specify a color with at least a 6-letter string of hexadecimal values in the format RRGGBB. For example:
42
+
43
+ * FF0000 = red
44
+ * 00FF00 = green
45
+ * 0000FF = blue
46
+ * 000000 = black
47
+ * FFFFFF = white
48
+
49
+ You can optionally specify transparency by appending a value between 00 and FF where 00 is completely transparent and FF completely opaque. For example:
50
+
51
+ * 0000FFFF = solid blue
52
+ * 0000FF00 = transparent blue
53
+
54
+ If you need to use multiple colors, check the doc. Usually you just need to pass :attribute => 'FF0000,00FF00'
55
+
56
+ Some charts have more options than other, make sure to refer to the documentation.
57
+
58
+ ===Background options:
59
+
60
+ If you don't set the background option, your graph will be transparent.
61
+
62
+ * You have 3 types of background http://code.google.com/apis/chart/#chart_or_background_fill
63
+
64
+ - solid
65
+ - gradient
66
+ - stripes
67
+
68
+ By default, if you set a background color, the fill will be solid:
69
+
70
+ Gchart.bar(:bg => 'efefef')
71
+
72
+ However you can specify another fill type such as:
73
+
74
+ Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'})
75
+
76
+ 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:
77
+
78
+ Gchart.line(:title =>'bg example', :bg => {:color => 'efefef', :type => 'gradient', :angle => 90})
79
+
80
+ For a more advance use of colors, refer to http://code.google.com/apis/chart/#linear_gradient
81
+
82
+ Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'})
83
+
84
+
85
+ The same way you set the background color, you can also set the graph background:
86
+
87
+ Gchart.line(:graph_bg => 'cccccc')
88
+
89
+ or both
90
+
91
+ Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'}, :graph_bg => 'cccccc', :title => 'Sexy Chart')
92
+
93
+
94
+ Another type of fill is stripes http://code.google.com/apis/chart/#linear_stripes
95
+
96
+ Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'})
97
+
98
+ You can customize the amount of stripes, colors and width by changing the color value.
99
+
100
+
101
+ == Legend & Labels
102
+
103
+ You probably will want to use a legend or labels for your graph.
104
+
105
+ Gchart.line(:legend => 'legend label')
106
+ or
107
+ Gchart.line(:legend => ['legend label 1', 'legend label 2'])
108
+
109
+ Will do the trick. You can also use the labels alias (makes more sense when using the pie charts)
110
+
111
+ chart = Gchart.pie(:labels => ['label 1', 'label 2'])
112
+
113
+ == Multiple axis labels
114
+
115
+ Multiple axis labels are available for line charts, bar charts and scatter plots.
116
+
117
+ * x = bottom x-axis
118
+ * t = top x-axis
119
+ * y = left y-axis
120
+ * r = right y-axis
121
+
122
+ Gchart.line(:label_axis => 'x,y,r')
123
+
124
+ To add labels on these axis:
125
+
126
+ Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007'])
127
+
128
+
129
+ == Data options
130
+
131
+ Data are passed using an array or a nested array.
132
+
133
+ Gchart.bar(:data => [1,2,4,67,100,41,234])
134
+
135
+ Gchart.bar(:data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]])
136
+
137
+ 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.
138
+
139
+ Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 300)
140
+ Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 'auto')
141
+
142
+ or if you want to use the real values from your dataset:
143
+
144
+ Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => false)
145
+
146
+
147
+ You can also define a different encoding to add more granularity:
148
+
149
+ Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'simple')
150
+ Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'extended')
151
+ Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'text')
152
+
153
+
154
+ ==Pies:
155
+
156
+ you have 2 type of pies:
157
+ - Gchart.pie() the standard 2D pie
158
+ _ Gchart.pie_3d() the fancy 3D pie
159
+
160
+ To set labels, you can use one of these two options:
161
+
162
+ @legend = ['Matt_fu', 'Rob_fu']
163
+ Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data, :size => '400x200')
164
+ Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data, :size => '400x200')
165
+
166
+
167
+
168
+ === try yourself
169
+
170
+ Gchart.bar( :data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]],
171
+ :title => 'SDRuby Fu level',
172
+ :legend => ['matt','patrick'],
173
+ :bg => {:color => '76A4FB', :type => 'gradient'},
174
+ :bar_colors => 'ff0000,00ff00')
175
+
176
+ "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"
177
+
178
+ Gchart.pie(:data => [20,10,15,5,50], :title => 'SDRuby Fu level', :size => '400x200', :labels => ['matt', 'rob', 'patrick', 'ryan', 'jordan'])
179
+ http://chart.apis.google.com/chart?cht=p&chs=400x200&chd=s:YMSG9&chtt=SDRuby+Fu+level&chl=matt|rob|patrick|ryan|jordan
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
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,328 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'gchart/version'
3
+
4
+ class Gchart
5
+
6
+ include GchartInfo
7
+
8
+ @@url = "http://chart.apis.google.com/chart?"
9
+ @@types = ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d']
10
+ @@simple_chars = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
11
+ @@chars = @@simple_chars + ['-', '.']
12
+ @@ext_pairs = @@chars.map { |char_1| @@chars.map { |char_2| char_1 + char_2 } }.flatten
13
+
14
+ attr_accessor :title, :type, :width, :height, :horizontal, :grouped, :legend, :data, :encoding, :max_value, :bar_colors,
15
+ :title_color, :title_size, :custom, :axis_with_labels, :axis_labels
16
+
17
+ class << self
18
+ # Support for Gchart.line(:title => 'my title', :size => '400x600')
19
+ def method_missing(m, options={}, format='raw')
20
+ if @@types.include?(m.to_s)
21
+ chart = new(options.merge!({:type => m}))
22
+ chart.send(format)
23
+ else
24
+ "#{m} is not a supported chart format, please use one of the following: #{supported_types}."
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ def initialize(options={})
31
+ @type = :line
32
+ @data = []
33
+ @width = 300
34
+ @height = 200
35
+ @horizontal = false
36
+ @grouped = false
37
+ @encoding = 'simple'
38
+ @max_value = 'auto'
39
+
40
+ # set the options value if definable
41
+ options.each do |attribute, value|
42
+ send("#{attribute.to_s}=", value) if self.respond_to?("#{attribute}=")
43
+ end
44
+ end
45
+
46
+ def self.supported_types
47
+ @@types.join(' ')
48
+ end
49
+
50
+ # Defines the Graph size using the following format:
51
+ # width X height
52
+ def size=(size='300x200')
53
+ @width, @height = size.split("x").map { |dimension| dimension.to_i }
54
+ end
55
+
56
+ def size
57
+ "#{@width}x#{@height}"
58
+ end
59
+
60
+ # Sets the orientation of a bar graph
61
+ def orientation=(orientation='h')
62
+ if orientation == 'h' || orientation == 'horizontal'
63
+ self.horizontal = true
64
+ elsif orientation == 'v' || orientation == 'vertical'
65
+ self.horizontal = false
66
+ end
67
+ end
68
+
69
+ # Sets the bar graph presentation (stacked or grouped)
70
+ def stacked=(option=true)
71
+ @grouped = option ? false : true
72
+ end
73
+
74
+ def bg=(options)
75
+ if options.is_a?(String)
76
+ @bg_color = options
77
+ elsif options.is_a?(Hash)
78
+ @bg_color = options[:color]
79
+ @bg_type = options[:type]
80
+ @bg_angle = options[:angle]
81
+ end
82
+ end
83
+
84
+ def graph_bg=(options)
85
+ if options.is_a?(String)
86
+ @chart_color = options
87
+ elsif options.is_a?(Hash)
88
+ @chart_color = options[:color]
89
+ @chart_type = options[:type]
90
+ @chart_angle = options[:angle]
91
+ end
92
+ end
93
+
94
+ # load all the custom aliases
95
+ require 'gchart/aliases'
96
+
97
+ protected
98
+
99
+ # Format
100
+
101
+ def img_tag
102
+ "<img src='#{query_builder}'/>"
103
+ end
104
+
105
+ def raw
106
+ query_builder
107
+ end
108
+
109
+ #
110
+ def jstize(string)
111
+ string.gsub(' ', '+')
112
+ end
113
+
114
+ private
115
+
116
+ # The title size cannot be set without specifying a color.
117
+ # A dark key will be used for the title color if no color is specified
118
+ def set_title
119
+ title_params = "chtt=#{title}"
120
+ unless (title_color.nil? && title_size.nil? )
121
+ title_params << "&chts=" + (color, size = (@title_color || '454545'), @title_size).compact.join(',')
122
+ end
123
+ title_params
124
+ end
125
+
126
+ def set_size
127
+ "chs=#{size}"
128
+ end
129
+
130
+ def set_data
131
+ data = send("#{@encoding}_encoding", @data)
132
+ "chd=#{data}"
133
+ end
134
+
135
+ def set_colors
136
+ bg_type = fill_type(@bg_type) || 's' if @bg_color
137
+ chart_type = fill_type(@chart_type) || 's' if @chart_color
138
+
139
+ "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('|')
140
+ end
141
+
142
+ # set bar, line colors
143
+ def set_bar_colors
144
+ "chco=#{@bar_colors}"
145
+ end
146
+
147
+ def fill_for(type=nil, color='', angle=nil)
148
+ unless type.nil?
149
+ case type
150
+ when 'lg'
151
+ angle ||= 0
152
+ color = "#{color},0,ffffff,1" if color.split(',').size == 1
153
+ "#{type},#{angle},#{color}"
154
+ when 'ls'
155
+ angle ||= 90
156
+ color = "#{color},0.2,ffffff,0.2" if color.split(',').size == 1
157
+ "#{type},#{angle},#{color}"
158
+ else
159
+ "#{type},#{color}"
160
+ end
161
+ end
162
+ end
163
+
164
+ # A chart can have one or many legends.
165
+ # Gchart.line(:legend => 'label')
166
+ # or
167
+ # Gchart.line(:legend => ['first label', 'last label'])
168
+ def set_legend
169
+ return set_labels if @type == :pie || @type == :pie_3d
170
+
171
+ if @legend.is_a?(Array)
172
+ "chdl=#{@legend.map{|label| "#{label}"}.join('|')}"
173
+ else
174
+ "chdl=#{@legend}"
175
+ end
176
+
177
+ end
178
+
179
+ def set_labels
180
+ if @legend.is_a?(Array)
181
+ "chl=#{@legend.map{|label| "#{label}"}.join('|')}"
182
+ else
183
+ "chl=#{@legend}"
184
+ end
185
+ end
186
+
187
+ def set_axis_with_labels
188
+ "chxt=#{@axis_with_labels}"
189
+ end
190
+
191
+ def set_axis_labels
192
+ labels_arr = []
193
+ axis_labels.each_with_index{|labels,index| labels_arr << "#{index}:#{labels}"}
194
+ "chxl=#{labels_arr.join('|')}"
195
+ #"chxl=0:Jan|July|Jan|July|Jan|1:0|100|2:A|B|C|3:2005|2006|2007"
196
+ end
197
+
198
+ def set_type
199
+ case @type
200
+ when :line
201
+ "cht=lc"
202
+ when :line_xy
203
+ "cht=lxy"
204
+ when :bar
205
+ "cht=b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s")
206
+ when :pie_3d
207
+ "cht=p3"
208
+ when :pie
209
+ "cht=p"
210
+ when :venn
211
+ "cht=v"
212
+ when :scatter
213
+ "cht=s"
214
+ end
215
+ end
216
+
217
+ def fill_type(type)
218
+ case type
219
+ when 'solid'
220
+ 's'
221
+ when 'gradient'
222
+ 'lg'
223
+ when 'stripes'
224
+ 'ls'
225
+ end
226
+ end
227
+
228
+ # Wraps a single dataset inside another array to support more datasets
229
+ def prepare_dataset(ds)
230
+ ds = [ds] unless ds.first.is_a?(Array)
231
+ ds
232
+ end
233
+
234
+ def convert_to_simple_value(number)
235
+ if number.nil?
236
+ "_"
237
+ else
238
+ value = @@simple_chars[number.to_i]
239
+ value.nil? ? "_" : value
240
+ end
241
+ end
242
+
243
+ # http://code.google.com/apis/chart/#simple
244
+ # Simple encoding has a resolution of 62 different values.
245
+ # Allowing five pixels per data point, this is sufficient for line and bar charts up
246
+ # to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size.
247
+ def simple_encoding(dataset=[])
248
+ dataset = prepare_dataset(dataset)
249
+ @max_value = dataset.map{|ds| ds.max}.max if @max_value == 'auto'
250
+
251
+ if @max_value == false || @max_value == 'false' || @max_value == :false
252
+ "s:" + dataset.map { |ds| ds.map { |number| convert_to_simple_value(number) }.join }.join(',')
253
+ else
254
+ "s:" + dataset.map { |ds| ds.map { |number| convert_to_simple_value( (@@simple_chars.size - 1) * number / @max_value) }.join }.join(',')
255
+ end
256
+
257
+ end
258
+
259
+ # http://code.google.com/apis/chart/#text
260
+ # Text encoding has a resolution of 1,000 different values,
261
+ # using floating point numbers between 0.0 and 100.0. Allowing five pixels per data point,
262
+ # integers (1.0, 2.0, and so on) are sufficient for line and bar charts up to about 500 pixels.
263
+ # Include a single decimal place (35.7 for example) if you require higher resolution.
264
+ # Text encoding is suitable for all other types of chart regardless of size.
265
+ def text_encoding(dataset=[])
266
+ dataset = prepare_dataset(dataset)
267
+ "t:" + dataset.map{ |ds| ds.join(',') }.join('|')
268
+ end
269
+
270
+ def convert_to_extended_value(number)
271
+ if number.nil?
272
+ '__'
273
+ else
274
+ value = @@ext_pairs[number.to_i]
275
+ value.nil? ? "__" : value
276
+ end
277
+ end
278
+
279
+ # http://code.google.com/apis/chart/#extended
280
+ # Extended encoding has a resolution of 4,096 different values
281
+ # and is best used for large charts where a large data range is required.
282
+ def extended_encoding(dataset=[])
283
+
284
+ dataset = prepare_dataset(dataset)
285
+ @max_value = dataset.map{|ds| ds.max}.max if @max_value == 'auto'
286
+
287
+ if @max_value == false || @max_value == 'false' || @max_value == :false
288
+ "e:" + dataset.map { |ds| ds.map { |number| convert_to_extended_value(number)}.join }.join(',')
289
+ else
290
+ "e:" + dataset.map { |ds| ds.map { |number| convert_to_extended_value( (@@ext_pairs.size - 1) * number / @max_value) }.join }.join(',')
291
+ end
292
+
293
+ end
294
+
295
+
296
+ def query_builder
297
+ query_params = instance_variables.map do |var|
298
+ case var
299
+ # Set the graph size
300
+ when '@width'
301
+ set_size unless @width.nil? || @height.nil?
302
+ when '@type'
303
+ set_type
304
+ when '@title'
305
+ set_title unless @title.nil?
306
+ when '@legend'
307
+ set_legend unless @legend.nil?
308
+ when '@bg_color'
309
+ set_colors
310
+ when '@chart_color'
311
+ set_colors
312
+ when '@data'
313
+ set_data unless @data == []
314
+ when '@bar_colors'
315
+ set_bar_colors
316
+ when '@axis_with_labels'
317
+ set_axis_with_labels
318
+ when '@axis_labels'
319
+ set_axis_labels
320
+ when '@custom'
321
+ @custom
322
+ end
323
+ end.compact
324
+
325
+ jstize(@@url + query_params.join('&'))
326
+ end
327
+
328
+ end