betelgeuse-googlecharts 1.4.1

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.
@@ -0,0 +1,571 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ require File.dirname(__FILE__) + '/../lib/gchart'
3
+
4
+ Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/test_theme.yml")
5
+
6
+ # Time to add your specs!
7
+ # http://rspec.rubyforge.org/
8
+ describe "generating a default Gchart" do
9
+
10
+ before(:each) do
11
+ @chart = Gchart.line
12
+ end
13
+
14
+ it "should include the Google URL" do
15
+ @chart.include?("http://chart.apis.google.com/chart?").should be_true
16
+ end
17
+
18
+ it "should have a default size" do
19
+ @chart.include?('chs=300x200').should be_true
20
+ end
21
+
22
+ it "should be able to have a custom size" do
23
+ Gchart.line(:size => '400x600').include?('chs=400x600').should be_true
24
+ Gchart.line(:width => 400, :height => 600).include?('chs=400x600').should be_true
25
+ end
26
+
27
+ it "should have query parameters in predictable order" do
28
+ Gchart.line(:axis_with_labels => 'x,y,r', :size => '400x600').should match(/chxr=.+chxt=.+cht=.+chs=/)
29
+ end
30
+
31
+ it "should have a type" do
32
+ @chart.include?('cht=lc').should be_true
33
+ end
34
+
35
+ it 'should use theme defaults if theme is set' do
36
+ Gchart.line(:theme=>:test).include?('chco=6886B4,FDD84E').should be_true
37
+ Gchart.line(:theme=>:test).include?(Gchart.jstize('chf=c,s,FFFFFF|bg,s,FFFFFF')).should be_true
38
+ end
39
+
40
+ it "should use the simple encoding by default with auto max value" do
41
+ # 9 is the max value in simple encoding, 26 being our max value the 2nd encoded value should be 9
42
+ Gchart.line(:data => [0, 26]).include?('chd=s:A9').should be_true
43
+ Gchart.line(:data => [0, 26], :max_value => 26).should == Gchart.line(:data => [0, 26])
44
+ end
45
+
46
+ it "should support simple encoding with and without max_value" do
47
+ Gchart.line(:data => [0, 26], :max_value => 26).include?('chd=s:A9').should be_true
48
+ Gchart.line(:data => [0, 26], :max_value => false).include?('chd=s:Aa').should be_true
49
+ end
50
+
51
+ it "should support the extended encoding and encode properly" do
52
+ Gchart.line(:data => [0, 10], :encoding => 'extended', :max_value => false).include?('chd=e:AA').should be_true
53
+ Gchart.line(:encoding => 'extended',
54
+ :max_value => false,
55
+ :data => [[0,25,26,51,52,61,62,63], [64,89,90,115,4084]]
56
+ ).include?('chd=e:AAAZAaAzA0A9A-A.,BABZBaBz.0').should be_true
57
+ end
58
+
59
+ it "should auto set the max value for extended encoding" do
60
+ Gchart.line(:data => [0, 25], :encoding => 'extended', :max_value => false).include?('chd=e:AAAZ').should be_true
61
+ # Extended encoding max value is '..'
62
+ Gchart.line(:data => [0, 25], :encoding => 'extended').include?('chd=e:AA..').should be_true
63
+ end
64
+
65
+ it "should be able to have data with text encoding" do
66
+ Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').include?('chd=t:10,5.2,4,45,78').should be_true
67
+ end
68
+
69
+ it "should handle max and min values with text encoding" do
70
+ Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').include?('chds=0,78').should be_true
71
+ end
72
+
73
+ it "should automatically handle negative values with proper max/min limits when using text encoding" do
74
+ Gchart.line(:data => [-10, 5.2, 4, 45, 78], :encoding => 'text').include?('chds=-10,78').should be_true
75
+ end
76
+
77
+ it "should handle negative values with manual max/min limits when using text encoding" do
78
+ Gchart.line(:data => [-10, 5.2, 4, 45, 78], :encoding => 'text', :min_value => -20, :max_value => 100).include?('chds=-20,100').should be_true
79
+ end
80
+
81
+ it "should set the proper axis values when using text encoding and negative values" do
82
+ Gchart.bar( :data => [[-10], [100]],
83
+ :encoding => 'text',
84
+ :horizontal => true,
85
+ :min_value => -20,
86
+ :max_value => 100,
87
+ :axis_with_labels => 'x',
88
+ :bar_colors => ['FD9A3B', '4BC7DC']).should include("chxr=0,-20,100")
89
+ end
90
+
91
+ it "should be able to have muliple set of data with text encoding" do
92
+ Gchart.line(:data => [[10, 5.2, 4, 45, 78], [20, 40, 70, 15, 99]], :encoding => 'text').include?(Gchart.jstize('chd=t:10,5.2,4,45,78|20,40,70,15,99')).should be_true
93
+ end
94
+
95
+ it "should be able to receive a custom param" do
96
+ Gchart.line(:custom => 'ceci_est_une_pipe').include?('ceci_est_une_pipe').should be_true
97
+ end
98
+
99
+ it "should be able to set label axis" do
100
+ Gchart.line(:axis_with_labels => 'x,y,r').include?('chxt=x,y,r').should be_true
101
+ Gchart.line(:axis_with_labels => ['x','y','r']).include?('chxt=x,y,r').should be_true
102
+ end
103
+
104
+ it "should be able to have axis labels" do
105
+ Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true
106
+ Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true
107
+ Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true
108
+ Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan'], ['0','100'], ['A','B','C'], ['2005','2006','2007']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true
109
+ end
110
+
111
+
112
+ end
113
+
114
+ describe "generating different type of charts" do
115
+
116
+ it "should be able to generate a line chart" do
117
+ Gchart.line.should be_an_instance_of(String)
118
+ Gchart.line.include?('cht=lc').should be_true
119
+ end
120
+
121
+ it "should be able to generate a sparkline chart" do
122
+ Gchart.sparkline.should be_an_instance_of(String)
123
+ Gchart.sparkline.include?('cht=ls').should be_true
124
+ end
125
+
126
+ it "should be able to generate a line xy chart" do
127
+ Gchart.line_xy.should be_an_instance_of(String)
128
+ Gchart.line_xy.include?('cht=lxy').should be_true
129
+ end
130
+
131
+ it "should be able to generate a scatter chart" do
132
+ Gchart.scatter.should be_an_instance_of(String)
133
+ Gchart.scatter.include?('cht=s').should be_true
134
+ end
135
+
136
+ it "should be able to generate a bar chart" do
137
+ Gchart.bar.should be_an_instance_of(String)
138
+ Gchart.bar.include?('cht=bvs').should be_true
139
+ end
140
+
141
+ it "should be able to generate a Venn diagram" do
142
+ Gchart.venn.should be_an_instance_of(String)
143
+ Gchart.venn.include?('cht=v').should be_true
144
+ end
145
+
146
+ it "should be able to generate a Pie Chart" do
147
+ Gchart.pie.should be_an_instance_of(String)
148
+ Gchart.pie.include?('cht=p').should be_true
149
+ end
150
+
151
+ it "should be able to generate a Google-O-Meter" do
152
+ Gchart.meter.should be_an_instance_of(String)
153
+ Gchart.meter.include?('cht=gom').should be_true
154
+ end
155
+
156
+ it "should be able to generate a map chart" do
157
+ Gchart.map.should be_an_instance_of(String)
158
+ Gchart.map.include?('cht=t').should be_true
159
+ end
160
+
161
+ it "should not support other types" do
162
+ Gchart.sexy.should == "sexy is not a supported chart format, please use one of the following: #{Gchart.supported_types}."
163
+ end
164
+
165
+ end
166
+
167
+
168
+ describe "range markers" do
169
+
170
+ it "should be able to generate given a hash of range-marker options" do
171
+ Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'}).include?('chm=r,ff0000,0,0.59,0.61').should be_true
172
+ end
173
+
174
+ it "should be able to generate given an array of range-marker hash options" do
175
+ Gchart.line(:range_markers => [
176
+ {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'},
177
+ {:start_position => 0, :stop_position => 0.6, :color => '666666'},
178
+ {:color => 'cccccc', :start_position => 0.6, :stop_position => 1}
179
+ ]).include?(Gchart.jstize('r,ff0000,0,0.59,0.61|r,666666,0,0,0.6|r,cccccc,0,0.6,1')).should be_true
180
+ end
181
+
182
+ it "should allow a :overlaid? to be set" do
183
+ Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ffffff', :overlaid? => true}).include?('chm=r,ffffff,0,0.59,0.61,1').should be_true
184
+ Gchart.line(:range_markers => {:start_position => 0.59, :stop_position => 0.61, :color => 'ffffff', :overlaid? => false}).include?('chm=r,ffffff,0,0.59,0.61').should be_true
185
+ end
186
+
187
+ describe "when setting the orientation option" do
188
+ before(:each) do
189
+ options = {:start_position => 0.59, :stop_position => 0.61, :color => 'ff0000'}
190
+ end
191
+
192
+ it "to vertical (R) if given a valid option" do
193
+ Gchart.line(:range_markers => options.merge(:orientation => 'v')).include?('chm=R').should be_true
194
+ Gchart.line(:range_markers => options.merge(:orientation => 'V')).include?('chm=R').should be_true
195
+ Gchart.line(:range_markers => options.merge(:orientation => 'R')).include?('chm=R').should be_true
196
+ Gchart.line(:range_markers => options.merge(:orientation => 'vertical')).include?('chm=R').should be_true
197
+ Gchart.line(:range_markers => options.merge(:orientation => 'Vertical')).include?('chm=R').should be_true
198
+ end
199
+
200
+ it "to horizontal (r) if given a valid option (actually anything other than the vertical options)" do
201
+ Gchart.line(:range_markers => options.merge(:orientation => 'horizontal')).include?('chm=r').should be_true
202
+ Gchart.line(:range_markers => options.merge(:orientation => 'h')).include?('chm=r').should be_true
203
+ Gchart.line(:range_markers => options.merge(:orientation => 'etc')).include?('chm=r').should be_true
204
+ end
205
+
206
+ it "if left blank defaults to horizontal (r)" do
207
+ Gchart.line(:range_markers => options).include?('chm=r').should be_true
208
+ end
209
+ end
210
+
211
+ end
212
+
213
+
214
+ describe "a bar graph" do
215
+
216
+ it "should have a default vertical orientation" do
217
+ Gchart.bar.include?('cht=bvs').should be_true
218
+ end
219
+
220
+ it "should be able to have a different orientation" do
221
+ Gchart.bar(:orientation => 'vertical').include?('cht=bvs').should be_true
222
+ Gchart.bar(:orientation => 'v').include?('cht=bvs').should be_true
223
+ Gchart.bar(:orientation => 'h').include?('cht=bhs').should be_true
224
+ Gchart.bar(:orientation => 'horizontal').include?('cht=bhs').should be_true
225
+ Gchart.bar(:horizontal => false).include?('cht=bvs').should be_true
226
+ end
227
+
228
+ it "should be set to be stacked by default" do
229
+ Gchart.bar.include?('cht=bvs').should be_true
230
+ end
231
+
232
+ it "should be able to stacked or grouped" do
233
+ Gchart.bar(:stacked => true).include?('cht=bvs').should be_true
234
+ Gchart.bar(:stacked => false).include?('cht=bvg').should be_true
235
+ Gchart.bar(:grouped => true).include?('cht=bvg').should be_true
236
+ Gchart.bar(:grouped => false).include?('cht=bvs').should be_true
237
+ end
238
+
239
+ it "should be able to have different bar colors" do
240
+ Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=').should be_true
241
+ Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=efefef,00ffff').should be_true
242
+ # alias
243
+ Gchart.bar(:bar_color => 'efefef').include?('chco=efefef').should be_true
244
+ end
245
+
246
+ it "should be able to have different bar colors when using an array of colors" do
247
+ Gchart.bar(:bar_colors => ['efefef','00ffff']).include?('chco=efefef,00ffff').should be_true
248
+ end
249
+
250
+ it 'should be able to accept a string of width and spacing options' do
251
+ Gchart.bar(:bar_width_and_spacing => '25,6').include?('chbh=25,6').should be_true
252
+ end
253
+
254
+ it 'should be able to accept a single fixnum width and spacing option to set the bar width' do
255
+ Gchart.bar(:bar_width_and_spacing => 25).include?('chbh=25').should be_true
256
+ end
257
+
258
+ it 'should be able to accept an array of width and spacing options' do
259
+ Gchart.bar(:bar_width_and_spacing => [25,6,12]).include?('chbh=25,6,12').should be_true
260
+ Gchart.bar(:bar_width_and_spacing => [25,6]).include?('chbh=25,6').should be_true
261
+ Gchart.bar(:bar_width_and_spacing => [25]).include?('chbh=25').should be_true
262
+ end
263
+
264
+ describe "with a hash of width and spacing options" do
265
+
266
+ before(:each) do
267
+ @default_width = 23
268
+ @default_spacing = 4
269
+ @default_group_spacing = 8
270
+ end
271
+
272
+ it 'should be able to have a custom bar width' do
273
+ Gchart.bar(:bar_width_and_spacing => {:width => 19}).include?("chbh=19,#{@default_spacing},#{@default_group_spacing}").should be_true
274
+ end
275
+
276
+ it 'should be able to have custom spacing' do
277
+ Gchart.bar(:bar_width_and_spacing => {:spacing => 19}).include?("chbh=#{@default_width},19,#{@default_group_spacing}").should be_true
278
+ end
279
+
280
+ it 'should be able to have custom group spacing' do
281
+ Gchart.bar(:bar_width_and_spacing => {:group_spacing => 19}).include?("chbh=#{@default_width},#{@default_spacing},19").should be_true
282
+ end
283
+
284
+ end
285
+
286
+ end
287
+
288
+ describe "a line chart" do
289
+
290
+ before(:each) do
291
+ @title = 'Chart Title'
292
+ @legend = ['first data set label', 'n data set label']
293
+ @chart = Gchart.line(:title => @title, :legend => @legend)
294
+ end
295
+
296
+ it 'should be able have a chart title' do
297
+ @chart.include?("chtt=Chart+Title").should be_true
298
+ end
299
+
300
+ it "should be able to a custom color and size title" do
301
+ Gchart.line(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true
302
+ Gchart.line(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true
303
+ end
304
+
305
+ it "should be able to have multiple legends" do
306
+ @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true
307
+ end
308
+
309
+ it "should escape text values in url" do
310
+ title = 'Chart & Title'
311
+ legend = ['first data & set label', 'n data set label']
312
+ chart = Gchart.line(:title => title, :legend => legend)
313
+ chart.include?(Gchart.jstize("chdl=first+data+%26+set+label|n+data+set+label")).should be_true
314
+ end
315
+
316
+ it "should be able to have one legend" do
317
+ chart = Gchart.line(:legend => 'legend label')
318
+ chart.include?("chdl=legend+label").should be_true
319
+ end
320
+
321
+ it "should be able to set the background fill" do
322
+ Gchart.line(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true
323
+ Gchart.line(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true
324
+
325
+ Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true
326
+ Gchart.line(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true
327
+ Gchart.line(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=bg,lg,90,efefef,0,ffffff,1").should be_true
328
+
329
+ Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'}).include?("chf=bg,ls,90,efefef,0.2,ffffff,0.2").should be_true
330
+ end
331
+
332
+ it "should be able to set a graph fill" do
333
+ Gchart.line(:graph_bg => 'efefef').include?("chf=c,s,efefef").should be_true
334
+ Gchart.line(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true
335
+ Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true
336
+ Gchart.line(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true
337
+ Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true
338
+ end
339
+
340
+ it "should be able to set both a graph and a background fill" do
341
+ Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true
342
+ Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true
343
+ Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true
344
+ end
345
+
346
+ it "should be able to have different line colors" do
347
+ Gchart.line(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true
348
+ Gchart.line(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true
349
+ end
350
+
351
+ it "should be able to render a graph where all the data values are 0" do
352
+ Gchart.line(:data => [0, 0, 0]).include?("chd=s:AAA").should be_true
353
+ end
354
+
355
+ end
356
+
357
+ describe "a sparkline chart" do
358
+
359
+ before(:each) do
360
+ @title = 'Chart Title'
361
+ @legend = ['first data set label', 'n data set label']
362
+ @jstized_legend = Gchart.jstize(@legend.join('|'))
363
+ @data = [27,25,25,25,25,27,100,31,25,36,25,25,39,25,31,25,25,25,26,26,25,25,28,25,25,100,28,27,31,25,27,27,29,25,27,26,26,25,26,26,35,33,34,25,26,25,36,25,26,37,33,33,37,37,39,25,25,25,25]
364
+ @chart = Gchart.sparkline(:title => @title, :data => @data, :legend => @legend)
365
+ end
366
+
367
+ it "should create a sparkline" do
368
+ @chart.include?('cht=ls').should be_true
369
+ end
370
+
371
+ it 'should be able have a chart title' do
372
+ @chart.include?("chtt=Chart+Title").should be_true
373
+ end
374
+
375
+ it "should be able to a custom color and size title" do
376
+ Gchart.sparkline(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true
377
+ Gchart.sparkline(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true
378
+ end
379
+
380
+ it "should be able to have multiple legends" do
381
+ @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true
382
+ end
383
+
384
+ it "should be able to have one legend" do
385
+ chart = Gchart.sparkline(:legend => 'legend label')
386
+ chart.include?("chdl=legend+label").should be_true
387
+ end
388
+
389
+ it "should be able to set the background fill" do
390
+ Gchart.sparkline(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true
391
+ Gchart.sparkline(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true
392
+
393
+ Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true
394
+ Gchart.sparkline(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true
395
+ Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=bg,lg,90,efefef,0,ffffff,1").should be_true
396
+
397
+ Gchart.sparkline(:bg => {:color => 'efefef', :type => 'stripes'}).include?("chf=bg,ls,90,efefef,0.2,ffffff,0.2").should be_true
398
+ end
399
+
400
+ it "should be able to set a graph fill" do
401
+ Gchart.sparkline(:graph_bg => 'efefef').include?("chf=c,s,efefef").should be_true
402
+ Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true
403
+ Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true
404
+ Gchart.sparkline(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true
405
+ Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true
406
+ end
407
+
408
+ it "should be able to set both a graph and a background fill" do
409
+ Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true
410
+ Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true
411
+ Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true
412
+ end
413
+
414
+ it "should be able to have different line colors" do
415
+ Gchart.sparkline(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true
416
+ Gchart.sparkline(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true
417
+ end
418
+
419
+ end
420
+
421
+ describe "a 3d pie chart" do
422
+
423
+ before(:each) do
424
+ @title = 'Chart Title'
425
+ @legend = ['first data set label', 'n data set label']
426
+ @jstized_legend = Gchart.jstize(@legend.join('|'))
427
+ @data = [12,8,40,15,5]
428
+ @chart = Gchart.pie(:title => @title, :legend => @legend, :data => @data)
429
+ end
430
+
431
+ it "should create a pie" do
432
+ @chart.include?('cht=p').should be_true
433
+ end
434
+
435
+ it "should be able to be in 3d" do
436
+ Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).include?('cht=p3').should be_true
437
+ end
438
+
439
+ it "should be able to set labels by using the legend or labesl accessor" do
440
+ Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).include?("chl=#{@jstized_legend}").should be_true
441
+ Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).include?("chl=#{@jstized_legend}").should be_true
442
+ Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should == Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data)
443
+ end
444
+
445
+ end
446
+
447
+ describe "a google-o-meter" do
448
+
449
+ before(:each) do
450
+ @data = [70]
451
+ @legend = ['arrow points here']
452
+ @jstized_legend = Gchart.jstize(@legend.join('|'))
453
+ @chart = Gchart.meter(:data => @data)
454
+ end
455
+
456
+ it "should create a meter" do
457
+ @chart.include?('cht=gom').should be_true
458
+ end
459
+
460
+ it "should be able to set a solid background fill" do
461
+ Gchart.meter(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true
462
+ Gchart.meter(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true
463
+ end
464
+
465
+ end
466
+
467
+ describe "a map chart" do
468
+
469
+ before(:each) do
470
+ @data = [0,100,50,32]
471
+ @geographical_area = 'usa'
472
+ @map_colors = ['FFFFFF', 'FF0000', 'FFFF00', '00FF00']
473
+ @country_codes = ['MT', 'WY', "ID", 'SD']
474
+ @chart = Gchart.map(:data => @data, :encoding => 'text', :size => '400x300',
475
+ :geographical_area => @geographical_area, :map_colors => @map_colors,
476
+ :country_codes => @country_codes)
477
+ end
478
+
479
+ it "should create a map" do
480
+ @chart.include?('cht=t').should be_true
481
+ end
482
+
483
+ it "should set the geographical area" do
484
+ @chart.include?('chtm=usa').should be_true
485
+ end
486
+
487
+ it "should set the map colors" do
488
+ @chart.include?('chco=FFFFFF,FF0000,FFFF00,00FF00').should be_true
489
+ end
490
+
491
+ it "should set the country/state codes" do
492
+ @chart.include?('chld=MTWYIDSD').should be_true
493
+ end
494
+
495
+ it "should set the chart data" do
496
+ @chart.include?('chd=t:0,100,50,32').should be_true
497
+ end
498
+
499
+ end
500
+
501
+ describe 'exporting a chart' do
502
+
503
+ it "should be available in the url format by default" do
504
+ Gchart.line(:data => [0, 26], :format => 'url').should == Gchart.line(:data => [0, 26])
505
+ end
506
+
507
+ it "should be available as an image tag" do
508
+ Gchart.line(:data => [0, 26], :format => 'image_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/)
509
+ end
510
+
511
+ it "should be available as an image tag using img_tag alias" do
512
+ Gchart.line(:data => [0, 26], :format => 'img_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/)
513
+ end
514
+
515
+ it "should be available as an image tag using custom dimensions" do
516
+ Gchart.line(:data => [0, 26], :format => 'image_tag', :size => '400x400').should match(/<img src=(.*) width="400" height="400" alt="Google Chart" \/>/)
517
+ end
518
+
519
+ it "should be available as an image tag using custom alt text" do
520
+ Gchart.line(:data => [0, 26], :format => 'image_tag', :alt => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Sexy chart" \/>/)
521
+ end
522
+
523
+ it "should be available as an image tag using custom title text" do
524
+ Gchart.line(:data => [0, 26], :format => 'image_tag', :title => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" title="Sexy chart" \/>/)
525
+ end
526
+
527
+ it "should be available as an image tag using custom css id selector" do
528
+ Gchart.line(:data => [0, 26], :format => 'image_tag', :id => 'chart').should match(/<img id="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/)
529
+ end
530
+
531
+ it "should be available as an image tag using custom css class selector" do
532
+ Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should match(/<img class="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/)
533
+ end
534
+
535
+ it "should use ampersands to separate key/value pairs in URLs by default" do
536
+ Gchart.line(:data => [0, 26]).should satisfy {|chart| chart.include? "&" }
537
+ Gchart.line(:data => [0, 26]).should_not satisfy {|chart| chart.include? "&amp;" }
538
+ end
539
+
540
+ it "should escape ampersands in URLs when used as an image tag" do
541
+ Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should satisfy {|chart| chart.include? "&amp;" }
542
+ end
543
+
544
+ it "should be available as a file" do
545
+ File.delete('chart.png') if File.exist?('chart.png')
546
+ Gchart.line(:data => [0, 26], :format => 'file')
547
+ File.exist?('chart.png').should be_true
548
+ File.delete('chart.png') if File.exist?('chart.png')
549
+ end
550
+
551
+ it "should be available as a file using a custom file name" do
552
+ File.delete('custom_file_name.png') if File.exist?('custom_file_name.png')
553
+ Gchart.line(:data => [0, 26], :format => 'file', :filename => 'custom_file_name.png')
554
+ File.exist?('custom_file_name.png').should be_true
555
+ File.delete('custom_file_name.png') if File.exist?('custom_file_name.png')
556
+ end
557
+
558
+ it "should work even with multiple attrs" do
559
+ File.delete('foo.png') if File.exist?('foo.png')
560
+ Gchart.line(:size => '400x200',
561
+ :data => [1,2,3,4,5],
562
+ :axis_labels => [[1,2,3,4, 5], %w[foo bar]],
563
+ :axis_with_labels => 'x,r',
564
+ :format => "file",
565
+ :filename => "foo.png"
566
+ )
567
+ File.exist?('foo.png').should be_true
568
+ File.delete('foo.png') if File.exist?('foo.png')
569
+ end
570
+
571
+ end