matta-googlecharts 1.1.0

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,277 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ require File.dirname(__FILE__) + '/../lib/gchart'
3
+
4
+ # Time to add your specs!
5
+ # http://rspec.rubyforge.org/
6
+ describe "generating a default Gchart" do
7
+
8
+ before(:each) do
9
+ @chart = Gchart.line
10
+ end
11
+
12
+ it "should include the Google URL" do
13
+ @chart.include?("http://chart.apis.google.com/chart?").should be_true
14
+ end
15
+
16
+ it "should have a default size" do
17
+ @chart.include?('chs=300x200').should be_true
18
+ end
19
+
20
+ it "should be able to have a custom size" do
21
+ Gchart.line(:size => '400x600').include?('chs=400x600').should be_true
22
+ Gchart.line(:width => 400, :height => 600).include?('chs=400x600').should be_true
23
+ end
24
+
25
+ it "should have a type" do
26
+ @chart.include?('cht=lc').should be_true
27
+ end
28
+
29
+ it "should use the simple encoding by default with auto max value" do
30
+ # 9 is the max value in simple encoding, 26 being our max value the 2nd encoded value should be 9
31
+ Gchart.line(:data => [0, 26]).include?('chd=s:A9').should be_true
32
+ Gchart.line(:data => [0, 26], :max_value => 26).should == Gchart.line(:data => [0, 26])
33
+ end
34
+
35
+ it "should support simple encoding with and without max_value" do
36
+ Gchart.line(:data => [0, 26], :max_value => 26).include?('chd=s:A9').should be_true
37
+ Gchart.line(:data => [0, 26], :max_value => false).include?('chd=s:Aa').should be_true
38
+ end
39
+
40
+ it "should support the extended encoding and encode properly" do
41
+ Gchart.line(:data => [0, 10], :encoding => 'extended', :max_value => false).include?('chd=e:AA').should be_true
42
+ Gchart.line(:encoding => 'extended',
43
+ :max_value => false,
44
+ :data => [[0,25,26,51,52,61,62,63], [64,89,90,115,4084]]
45
+ ).include?('chd=e:AAAZAaAzA0A9A-A.,BABZBaBz.0').should be_true
46
+ end
47
+
48
+ it "should auto set the max value for extended encoding" do
49
+ Gchart.line(:data => [0, 25], :encoding => 'extended', :max_value => false).include?('chd=e:AAAZ').should be_true
50
+ # Extended encoding max value is '..'
51
+ Gchart.line(:data => [0, 25], :encoding => 'extended').include?('chd=e:AA..').should be_true
52
+ end
53
+
54
+ it "should be able to have data with text encoding" do
55
+ Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').include?('chd=t:10,5.2,4,45,78').should be_true
56
+ end
57
+
58
+ it "should be able to have muliple set of data with text encoding" do
59
+ 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
60
+ end
61
+
62
+ it "should be able to receive a custom param" do
63
+ Gchart.line(:custom => 'ceci_est_une_pipe').include?('ceci_est_une_pipe').should be_true
64
+ end
65
+
66
+ it "should be able to set label axis" do
67
+ Gchart.line(:axis_with_labels => 'x,y,r').include?('chxt=x,y,r').should be_true
68
+ Gchart.line(:axis_with_labels => ['x','y','r']).include?('chxt=x,y,r').should be_true
69
+ end
70
+
71
+ it "should be able to have axis labels" do
72
+ 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
73
+ Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true
74
+ Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true
75
+ 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
76
+ end
77
+
78
+ end
79
+
80
+ describe "generating different type of charts" do
81
+
82
+ it "should be able to generate a line chart" do
83
+ Gchart.line.should be_an_instance_of(String)
84
+ Gchart.line.include?('cht=lc').should be_true
85
+ end
86
+
87
+ it "should be able to generate a line xy chart" do
88
+ Gchart.line_xy.should be_an_instance_of(String)
89
+ Gchart.line_xy.include?('cht=lxy').should be_true
90
+ end
91
+
92
+ it "should be able to generate a scatter chart" do
93
+ Gchart.scatter.should be_an_instance_of(String)
94
+ Gchart.scatter.include?('cht=s').should be_true
95
+ end
96
+
97
+ it "should be able to generate a bar chart" do
98
+ Gchart.bar.should be_an_instance_of(String)
99
+ Gchart.bar.include?('cht=bvs').should be_true
100
+ end
101
+
102
+ it "should be able to generate a Venn diagram" do
103
+ Gchart.venn.should be_an_instance_of(String)
104
+ Gchart.venn.include?('cht=v').should be_true
105
+ end
106
+
107
+ it "should be able to generate a Pie Chart" do
108
+ Gchart.pie.should be_an_instance_of(String)
109
+ Gchart.pie.include?('cht=p').should be_true
110
+ end
111
+
112
+ it "should not support other types" do
113
+ Gchart.sexy.should == "sexy is not a supported chart format, please use one of the following: #{Gchart.supported_types}."
114
+ end
115
+
116
+ end
117
+
118
+ describe "a bar graph" do
119
+
120
+ it "should have a default vertical orientation" do
121
+ Gchart.bar.include?('cht=bvs').should be_true
122
+ end
123
+
124
+ it "should be able to have a different orientation" do
125
+ Gchart.bar(:orientation => 'vertical').include?('cht=bvs').should be_true
126
+ Gchart.bar(:orientation => 'v').include?('cht=bvs').should be_true
127
+ Gchart.bar(:orientation => 'h').include?('cht=bhs').should be_true
128
+ Gchart.bar(:orientation => 'horizontal').include?('cht=bhs').should be_true
129
+ Gchart.bar(:horizontal => false).include?('cht=bvs').should be_true
130
+ end
131
+
132
+ it "should be set to be stacked by default" do
133
+ Gchart.bar.include?('cht=bvs').should be_true
134
+ end
135
+
136
+ it "should be able to stacked or grouped" do
137
+ Gchart.bar(:stacked => true).include?('cht=bvs').should be_true
138
+ Gchart.bar(:stacked => false).include?('cht=bvg').should be_true
139
+ Gchart.bar(:grouped => true).include?('cht=bvg').should be_true
140
+ Gchart.bar(:grouped => false).include?('cht=bvs').should be_true
141
+ end
142
+
143
+ it "should be able to have different bar colors" do
144
+ Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=').should be_true
145
+ Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=efefef,00ffff').should be_true
146
+ # alias
147
+ Gchart.bar(:bar_color => 'efefef').include?('chco=efefef').should be_true
148
+ end
149
+
150
+ it "should be able to have different bar colors when using an array of colors" do
151
+ Gchart.bar(:bar_colors => ['efefef','00ffff']).include?('chco=efefef,00ffff').should be_true
152
+ end
153
+
154
+ end
155
+
156
+ describe "a line chart" do
157
+
158
+ before(:each) do
159
+ @title = 'Chart Title'
160
+ @legend = ['first data set label', 'n data set label']
161
+ @chart = Gchart.line(:title => @title, :legend => @legend)
162
+ end
163
+
164
+ it 'should be able have a chart title' do
165
+ @chart.include?("chtt=Chart+Title").should be_true
166
+ end
167
+
168
+ it "should be able to a custom color and size title" do
169
+ Gchart.line(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true
170
+ Gchart.line(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true
171
+ end
172
+
173
+ it "should be able to have multiple legends" do
174
+ @chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true
175
+ end
176
+
177
+ it "should be able to have one legend" do
178
+ chart = Gchart.line(:legend => 'legend label')
179
+ chart.include?("chdl=legend+label").should be_true
180
+ end
181
+
182
+ it "should be able to set the background fill" do
183
+ Gchart.line(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true
184
+ Gchart.line(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true
185
+
186
+ Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true
187
+ Gchart.line(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true
188
+ Gchart.line(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=bg,lg,90,efefef,0,ffffff,1").should be_true
189
+
190
+ Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'}).include?("chf=bg,ls,90,efefef,0.2,ffffff,0.2").should be_true
191
+ end
192
+
193
+ it "should be able to set a graph fill" do
194
+ Gchart.line(:graph_bg => 'efefef').include?("chf=c,s,efefef").should be_true
195
+ Gchart.line(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true
196
+ Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true
197
+ Gchart.line(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true
198
+ Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true
199
+ end
200
+
201
+ it "should be able to set both a graph and a background fill" do
202
+ Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true
203
+ Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true
204
+ Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true
205
+ end
206
+
207
+ it "should be able to have different line colors" do
208
+ Gchart.line(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true
209
+ Gchart.line(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true
210
+ end
211
+
212
+ end
213
+
214
+ describe "a pie chart" do
215
+
216
+ before(:each) do
217
+ @title = 'Chart Title'
218
+ @legend = ['first data set label', 'n data set label']
219
+ @jstized_legend = Gchart.jstize(@legend.join('|'))
220
+ @data = [12,8,40,15,5]
221
+ @chart = Gchart.pie(:title => @title, :legend => @legend, :data => @data)
222
+ end
223
+
224
+ it "should create a pie" do
225
+ @chart.include?('cht=p').should be_true
226
+ end
227
+
228
+ it "should be able to be in 3d" do
229
+ Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).include?('cht=p3').should be_true
230
+ end
231
+
232
+ it "should be able to set labels by using the legend or labesl accessor" do
233
+ Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).include?("chl=#{@jstized_legend}").should be_true
234
+ Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).include?("chl=#{@jstized_legend}").should be_true
235
+ Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should == Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data)
236
+ end
237
+
238
+ end
239
+
240
+ describe 'exporting a chart' do
241
+
242
+ it "should be available in the url format by default" do
243
+ Gchart.line(:data => [0, 26], :format => 'url').should == Gchart.line(:data => [0, 26])
244
+ end
245
+
246
+ it "should be available as the img tag" do
247
+ Gchart.line(:data => [0, 26], :format => 'img_tag').should match(/<img src=(.*)\/>/)
248
+ end
249
+
250
+ it "should be available as a file" do
251
+ File.delete('chart.png') if File.exist?('chart.png')
252
+ Gchart.line(:data => [0, 26], :format => 'file')
253
+ File.exist?('chart.png').should be_true
254
+ File.delete('chart.png') if File.exist?('chart.png')
255
+ end
256
+
257
+ it "should be available as a file using a custom file name" do
258
+ File.delete('custom_file_name.png') if File.exist?('custom_file_name.png')
259
+ Gchart.line(:data => [0, 26], :format => 'file', :filename => 'custom_file_name.png')
260
+ File.exist?('custom_file_name.png').should be_true
261
+ File.delete('custom_file_name.png') if File.exist?('custom_file_name.png')
262
+ end
263
+
264
+ it "should work even with multiple attrs" do
265
+ File.delete('foo.png') if File.exist?('foo.png')
266
+ Gchart.line(:size => '400x200',
267
+ :data => [1,2,3,4,5],
268
+ :axis_labels => [[1,2,3,4, 5], %w[foo bar]],
269
+ :axis_with_labels => 'x,r',
270
+ :format => "file",
271
+ :filename => "foo.png"
272
+ )
273
+ File.exist?('foo.png').should be_true
274
+ File.delete('foo.png') if File.exist?('foo.png')
275
+ end
276
+
277
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,7 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
@@ -0,0 +1,34 @@
1
+ desc 'Release the website and new gem version'
2
+ task :deploy => [:check_version, :website, :release] do
3
+ puts "Remember to create SVN tag:"
4
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
6
+ puts "Suggested comment:"
7
+ puts "Tagging release #{CHANGES}"
8
+ end
9
+
10
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
11
+ task :local_deploy => [:website_generate, :install_gem]
12
+
13
+ task :check_version do
14
+ unless ENV['VERSION']
15
+ puts 'Must pass a VERSION=x.y.z release version'
16
+ exit
17
+ end
18
+ unless ENV['VERSION'] == VERS
19
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
20
+ exit
21
+ end
22
+ end
23
+
24
+ desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
25
+ task :install_gem_no_doc => [:clean, :package] do
26
+ sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
27
+ end
28
+
29
+ namespace :manifest do
30
+ desc 'Recreate Manifest.txt to include ALL files'
31
+ task :refresh do
32
+ `rake check_manifest | patch -p0 > Manifest.txt`
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ task :ruby_env do
2
+ RUBY_APP = if RUBY_PLATFORM =~ /java/
3
+ "jruby"
4
+ else
5
+ "ruby"
6
+ end unless defined? RUBY_APP
7
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/*_spec.rb']
21
+ end
@@ -0,0 +1,17 @@
1
+ desc 'Generate website files'
2
+ task :website_generate => :ruby_env do
3
+ (Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
4
+ sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
5
+ end
6
+ end
7
+
8
+ desc 'Upload website files to rubyforge'
9
+ task :website_upload do
10
+ host = "#{rubyforge_username}@rubyforge.org"
11
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
12
+ local_dir = 'website'
13
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
14
+ end
15
+
16
+ desc 'Generate and upload website files'
17
+ task :website => [:website_generate, :website_upload, :publish_docs]