ghazel-ghazel-googlecharts 1.4.0.4

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