googlecharts 1.3.6 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/README +0 -0
- data/README.markdown +290 -0
- data/Rakefile +18 -30
- data/VERSION +1 -0
- data/lib/gchart.rb +100 -23
- data/lib/gchart/version.rb +2 -2
- data/lib/themes.yml +45 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/spec/fixtures/another_test_theme.yml +8 -0
- data/spec/fixtures/test_theme.yml +8 -0
- data/spec/gchart_spec.rb +210 -90
- data/spec/spec.opts +4 -1
- data/tasks/deployment.rake +34 -0
- data/tasks/website.rake +17 -0
- data/website/index.html +732 -0
- data/website/index.txt +570 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +139 -0
- data/website/template.rhtml +53 -0
- metadata +38 -49
- data.tar.gz.sig +0 -2
- metadata.gz.sig +0 -3
data/lib/gchart/version.rb
CHANGED
data/lib/themes.yml
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#Default themes ganked from Gruff: http://github.com/topfunky/gruff/tree/master
|
2
|
+
:keynote:
|
3
|
+
:colors:
|
4
|
+
- &blue 6886B4
|
5
|
+
- &yellow FDD84E
|
6
|
+
- &green 72AE6E
|
7
|
+
- &red D1695E
|
8
|
+
- &purple 8A6EAF
|
9
|
+
- &orange EFAA43
|
10
|
+
- &white FFFFFF
|
11
|
+
- &black !str 000000
|
12
|
+
:bar_colors: [ *blue, *yellow, *green, *red, *purple, *orange ]
|
13
|
+
:background: *black
|
14
|
+
:chart_background: *white
|
15
|
+
:thirty7signals:
|
16
|
+
:colors:
|
17
|
+
- &green 339933
|
18
|
+
- &purple cc99cc
|
19
|
+
- &blue 336699
|
20
|
+
- &yellow FFF804
|
21
|
+
- &red ff0000
|
22
|
+
- &orange cf5910
|
23
|
+
:bar_colors: [ *yellow, *blue, *green, *red, *purple, *orange ]
|
24
|
+
:background: *white
|
25
|
+
:pastel:
|
26
|
+
:colors:
|
27
|
+
- &blue a9dada
|
28
|
+
- &green aedaa9
|
29
|
+
- &peach daaea9
|
30
|
+
- &yellow dadaa9
|
31
|
+
- &dk_purple a9a9da
|
32
|
+
- &purple daaeda
|
33
|
+
- &grey dadada
|
34
|
+
:bar_colors: [ *blue, *green, *peach, *yellow, *dk_purple ]
|
35
|
+
:background_color: *white
|
36
|
+
:greyscale:
|
37
|
+
:bar_colors: [
|
38
|
+
282828,
|
39
|
+
383838,
|
40
|
+
686868,
|
41
|
+
989898,
|
42
|
+
c8c8c8,
|
43
|
+
e8e8e8
|
44
|
+
]
|
45
|
+
:background_color: *white
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/script/txt2html
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
begin
|
5
|
+
require 'newgem'
|
6
|
+
rescue LoadError
|
7
|
+
puts "\n\nGenerating the website requires the newgem RubyGem"
|
8
|
+
puts "Install: gem install newgem\n\n"
|
9
|
+
exit(1)
|
10
|
+
end
|
11
|
+
require 'redcloth'
|
12
|
+
require 'syntax/convertors/html'
|
13
|
+
require 'erb'
|
14
|
+
require File.dirname(__FILE__) + '/../lib/gchart'
|
15
|
+
|
16
|
+
version = Gchart.version
|
17
|
+
download = 'http://rubyforge.org/projects/googlecharts'
|
18
|
+
|
19
|
+
class Fixnum
|
20
|
+
def ordinal
|
21
|
+
# teens
|
22
|
+
return 'th' if (10..19).include?(self % 100)
|
23
|
+
# others
|
24
|
+
case self % 10
|
25
|
+
when 1: return 'st'
|
26
|
+
when 2: return 'nd'
|
27
|
+
when 3: return 'rd'
|
28
|
+
else return 'th'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Time
|
34
|
+
def pretty
|
35
|
+
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def convert_syntax(syntax, source)
|
40
|
+
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
41
|
+
end
|
42
|
+
|
43
|
+
if ARGV.length >= 1
|
44
|
+
src, template = ARGV
|
45
|
+
template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
|
46
|
+
|
47
|
+
else
|
48
|
+
puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
|
49
|
+
exit!
|
50
|
+
end
|
51
|
+
|
52
|
+
template = ERB.new(File.open(template).read)
|
53
|
+
|
54
|
+
title = nil
|
55
|
+
body = nil
|
56
|
+
File.open(src) do |fsrc|
|
57
|
+
title_text = fsrc.readline
|
58
|
+
body_text = fsrc.read
|
59
|
+
syntax_items = []
|
60
|
+
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
61
|
+
ident = syntax_items.length
|
62
|
+
element, syntax, source = $1, $2, $3
|
63
|
+
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
64
|
+
"syntax-temp-#{ident}"
|
65
|
+
}
|
66
|
+
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
67
|
+
body = RedCloth.new(body_text).to_html
|
68
|
+
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
69
|
+
end
|
70
|
+
stat = File.stat(src)
|
71
|
+
created = stat.ctime
|
72
|
+
modified = stat.mtime
|
73
|
+
|
74
|
+
$stdout << template.result(binding)
|
data/spec/gchart_spec.rb
CHANGED
@@ -6,62 +6,88 @@ Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/test_theme.yml")
|
|
6
6
|
# Time to add your specs!
|
7
7
|
# http://rspec.rubyforge.org/
|
8
8
|
describe "generating a default Gchart" do
|
9
|
-
|
9
|
+
|
10
10
|
before(:each) do
|
11
11
|
@chart = Gchart.line
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it "should include the Google URL" do
|
15
15
|
@chart.include?("http://chart.apis.google.com/chart?").should be_true
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it "should have a default size" do
|
19
19
|
@chart.include?('chs=300x200').should be_true
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
it "should be able to have a custom size" do
|
23
23
|
Gchart.line(:size => '400x600').include?('chs=400x600').should be_true
|
24
24
|
Gchart.line(:width => 400, :height => 600).include?('chs=400x600').should be_true
|
25
25
|
end
|
26
|
-
|
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
|
+
|
27
31
|
it "should have a type" do
|
28
32
|
@chart.include?('cht=lc').should be_true
|
29
33
|
end
|
30
|
-
|
34
|
+
|
31
35
|
it 'should use theme defaults if theme is set' do
|
32
36
|
Gchart.line(:theme=>:test).include?('chco=6886B4,FDD84E').should be_true
|
33
37
|
Gchart.line(:theme=>:test).include?(Gchart.jstize('chf=c,s,FFFFFF|bg,s,FFFFFF')).should be_true
|
34
38
|
end
|
35
|
-
|
39
|
+
|
36
40
|
it "should use the simple encoding by default with auto max value" do
|
37
41
|
# 9 is the max value in simple encoding, 26 being our max value the 2nd encoded value should be 9
|
38
42
|
Gchart.line(:data => [0, 26]).include?('chd=s:A9').should be_true
|
39
43
|
Gchart.line(:data => [0, 26], :max_value => 26).should == Gchart.line(:data => [0, 26])
|
40
44
|
end
|
41
|
-
|
45
|
+
|
42
46
|
it "should support simple encoding with and without max_value" do
|
43
47
|
Gchart.line(:data => [0, 26], :max_value => 26).include?('chd=s:A9').should be_true
|
44
48
|
Gchart.line(:data => [0, 26], :max_value => false).include?('chd=s:Aa').should be_true
|
45
49
|
end
|
46
|
-
|
50
|
+
|
47
51
|
it "should support the extended encoding and encode properly" do
|
48
52
|
Gchart.line(:data => [0, 10], :encoding => 'extended', :max_value => false).include?('chd=e:AA').should be_true
|
49
|
-
Gchart.line(:encoding => 'extended',
|
53
|
+
Gchart.line(:encoding => 'extended',
|
50
54
|
:max_value => false,
|
51
55
|
:data => [[0,25,26,51,52,61,62,63], [64,89,90,115,4084]]
|
52
56
|
).include?('chd=e:AAAZAaAzA0A9A-A.,BABZBaBz.0').should be_true
|
53
57
|
end
|
54
|
-
|
58
|
+
|
55
59
|
it "should auto set the max value for extended encoding" do
|
56
60
|
Gchart.line(:data => [0, 25], :encoding => 'extended', :max_value => false).include?('chd=e:AAAZ').should be_true
|
57
61
|
# Extended encoding max value is '..'
|
58
62
|
Gchart.line(:data => [0, 25], :encoding => 'extended').include?('chd=e:AA..').should be_true
|
59
63
|
end
|
60
|
-
|
64
|
+
|
61
65
|
it "should be able to have data with text encoding" do
|
62
66
|
Gchart.line(:data => [10, 5.2, 4, 45, 78], :encoding => 'text').include?('chd=t:10,5.2,4,45,78').should be_true
|
63
67
|
end
|
64
|
-
|
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
|
+
|
65
91
|
it "should be able to have muliple set of data with text encoding" do
|
66
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
|
67
93
|
end
|
@@ -69,75 +95,128 @@ describe "generating a default Gchart" do
|
|
69
95
|
it "should be able to receive a custom param" do
|
70
96
|
Gchart.line(:custom => 'ceci_est_une_pipe').include?('ceci_est_une_pipe').should be_true
|
71
97
|
end
|
72
|
-
|
98
|
+
|
73
99
|
it "should be able to set label axis" do
|
74
100
|
Gchart.line(:axis_with_labels => 'x,y,r').include?('chxt=x,y,r').should be_true
|
75
101
|
Gchart.line(:axis_with_labels => ['x','y','r']).include?('chxt=x,y,r').should be_true
|
76
102
|
end
|
77
|
-
|
103
|
+
|
78
104
|
it "should be able to have axis labels" do
|
79
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
|
80
106
|
Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan']).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true
|
81
107
|
Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true
|
82
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
|
83
109
|
end
|
84
|
-
|
110
|
+
|
111
|
+
|
85
112
|
end
|
86
113
|
|
87
114
|
describe "generating different type of charts" do
|
88
|
-
|
115
|
+
|
89
116
|
it "should be able to generate a line chart" do
|
90
117
|
Gchart.line.should be_an_instance_of(String)
|
91
118
|
Gchart.line.include?('cht=lc').should be_true
|
92
119
|
end
|
93
|
-
|
120
|
+
|
94
121
|
it "should be able to generate a sparkline chart" do
|
95
122
|
Gchart.sparkline.should be_an_instance_of(String)
|
96
123
|
Gchart.sparkline.include?('cht=ls').should be_true
|
97
124
|
end
|
98
|
-
|
125
|
+
|
99
126
|
it "should be able to generate a line xy chart" do
|
100
127
|
Gchart.line_xy.should be_an_instance_of(String)
|
101
128
|
Gchart.line_xy.include?('cht=lxy').should be_true
|
102
129
|
end
|
103
|
-
|
130
|
+
|
104
131
|
it "should be able to generate a scatter chart" do
|
105
132
|
Gchart.scatter.should be_an_instance_of(String)
|
106
133
|
Gchart.scatter.include?('cht=s').should be_true
|
107
134
|
end
|
108
|
-
|
135
|
+
|
109
136
|
it "should be able to generate a bar chart" do
|
110
137
|
Gchart.bar.should be_an_instance_of(String)
|
111
138
|
Gchart.bar.include?('cht=bvs').should be_true
|
112
139
|
end
|
113
|
-
|
140
|
+
|
114
141
|
it "should be able to generate a Venn diagram" do
|
115
142
|
Gchart.venn.should be_an_instance_of(String)
|
116
143
|
Gchart.venn.include?('cht=v').should be_true
|
117
144
|
end
|
118
|
-
|
145
|
+
|
119
146
|
it "should be able to generate a Pie Chart" do
|
120
147
|
Gchart.pie.should be_an_instance_of(String)
|
121
148
|
Gchart.pie.include?('cht=p').should be_true
|
122
149
|
end
|
123
|
-
|
150
|
+
|
124
151
|
it "should be able to generate a Google-O-Meter" do
|
125
152
|
Gchart.meter.should be_an_instance_of(String)
|
126
153
|
Gchart.meter.include?('cht=gom').should be_true
|
127
154
|
end
|
128
|
-
|
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
|
+
|
129
161
|
it "should not support other types" do
|
130
162
|
Gchart.sexy.should == "sexy is not a supported chart format, please use one of the following: #{Gchart.supported_types}."
|
131
163
|
end
|
132
|
-
|
164
|
+
|
133
165
|
end
|
134
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
|
+
|
135
214
|
describe "a bar graph" do
|
136
|
-
|
215
|
+
|
137
216
|
it "should have a default vertical orientation" do
|
138
217
|
Gchart.bar.include?('cht=bvs').should be_true
|
139
218
|
end
|
140
|
-
|
219
|
+
|
141
220
|
it "should be able to have a different orientation" do
|
142
221
|
Gchart.bar(:orientation => 'vertical').include?('cht=bvs').should be_true
|
143
222
|
Gchart.bar(:orientation => 'v').include?('cht=bvs').should be_true
|
@@ -145,104 +224,111 @@ describe "a bar graph" do
|
|
145
224
|
Gchart.bar(:orientation => 'horizontal').include?('cht=bhs').should be_true
|
146
225
|
Gchart.bar(:horizontal => false).include?('cht=bvs').should be_true
|
147
226
|
end
|
148
|
-
|
227
|
+
|
149
228
|
it "should be set to be stacked by default" do
|
150
229
|
Gchart.bar.include?('cht=bvs').should be_true
|
151
230
|
end
|
152
|
-
|
231
|
+
|
153
232
|
it "should be able to stacked or grouped" do
|
154
233
|
Gchart.bar(:stacked => true).include?('cht=bvs').should be_true
|
155
234
|
Gchart.bar(:stacked => false).include?('cht=bvg').should be_true
|
156
235
|
Gchart.bar(:grouped => true).include?('cht=bvg').should be_true
|
157
236
|
Gchart.bar(:grouped => false).include?('cht=bvs').should be_true
|
158
237
|
end
|
159
|
-
|
238
|
+
|
160
239
|
it "should be able to have different bar colors" do
|
161
240
|
Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=').should be_true
|
162
241
|
Gchart.bar(:bar_colors => 'efefef,00ffff').include?('chco=efefef,00ffff').should be_true
|
163
242
|
# alias
|
164
243
|
Gchart.bar(:bar_color => 'efefef').include?('chco=efefef').should be_true
|
165
244
|
end
|
166
|
-
|
245
|
+
|
167
246
|
it "should be able to have different bar colors when using an array of colors" do
|
168
247
|
Gchart.bar(:bar_colors => ['efefef','00ffff']).include?('chco=efefef,00ffff').should be_true
|
169
248
|
end
|
170
|
-
|
249
|
+
|
171
250
|
it 'should be able to accept a string of width and spacing options' do
|
172
251
|
Gchart.bar(:bar_width_and_spacing => '25,6').include?('chbh=25,6').should be_true
|
173
252
|
end
|
174
|
-
|
253
|
+
|
175
254
|
it 'should be able to accept a single fixnum width and spacing option to set the bar width' do
|
176
255
|
Gchart.bar(:bar_width_and_spacing => 25).include?('chbh=25').should be_true
|
177
256
|
end
|
178
|
-
|
257
|
+
|
179
258
|
it 'should be able to accept an array of width and spacing options' do
|
180
259
|
Gchart.bar(:bar_width_and_spacing => [25,6,12]).include?('chbh=25,6,12').should be_true
|
181
260
|
Gchart.bar(:bar_width_and_spacing => [25,6]).include?('chbh=25,6').should be_true
|
182
261
|
Gchart.bar(:bar_width_and_spacing => [25]).include?('chbh=25').should be_true
|
183
262
|
end
|
184
|
-
|
263
|
+
|
185
264
|
describe "with a hash of width and spacing options" do
|
186
|
-
|
265
|
+
|
187
266
|
before(:each) do
|
188
267
|
@default_width = 23
|
189
268
|
@default_spacing = 4
|
190
269
|
@default_group_spacing = 8
|
191
270
|
end
|
192
|
-
|
271
|
+
|
193
272
|
it 'should be able to have a custom bar width' do
|
194
273
|
Gchart.bar(:bar_width_and_spacing => {:width => 19}).include?("chbh=19,#{@default_spacing},#{@default_group_spacing}").should be_true
|
195
274
|
end
|
196
|
-
|
275
|
+
|
197
276
|
it 'should be able to have custom spacing' do
|
198
277
|
Gchart.bar(:bar_width_and_spacing => {:spacing => 19}).include?("chbh=#{@default_width},19,#{@default_group_spacing}").should be_true
|
199
278
|
end
|
200
|
-
|
279
|
+
|
201
280
|
it 'should be able to have custom group spacing' do
|
202
281
|
Gchart.bar(:bar_width_and_spacing => {:group_spacing => 19}).include?("chbh=#{@default_width},#{@default_spacing},19").should be_true
|
203
282
|
end
|
204
|
-
|
283
|
+
|
205
284
|
end
|
206
|
-
|
285
|
+
|
207
286
|
end
|
208
287
|
|
209
288
|
describe "a line chart" do
|
210
|
-
|
289
|
+
|
211
290
|
before(:each) do
|
212
291
|
@title = 'Chart Title'
|
213
292
|
@legend = ['first data set label', 'n data set label']
|
214
293
|
@chart = Gchart.line(:title => @title, :legend => @legend)
|
215
294
|
end
|
216
|
-
|
295
|
+
|
217
296
|
it 'should be able have a chart title' do
|
218
297
|
@chart.include?("chtt=Chart+Title").should be_true
|
219
298
|
end
|
220
|
-
|
299
|
+
|
221
300
|
it "should be able to a custom color and size title" do
|
222
301
|
Gchart.line(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true
|
223
302
|
Gchart.line(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true
|
224
303
|
end
|
225
|
-
|
304
|
+
|
226
305
|
it "should be able to have multiple legends" do
|
227
306
|
@chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true
|
228
307
|
end
|
229
|
-
|
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
|
+
|
230
316
|
it "should be able to have one legend" do
|
231
317
|
chart = Gchart.line(:legend => 'legend label')
|
232
318
|
chart.include?("chdl=legend+label").should be_true
|
233
319
|
end
|
234
|
-
|
320
|
+
|
235
321
|
it "should be able to set the background fill" do
|
236
322
|
Gchart.line(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true
|
237
323
|
Gchart.line(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true
|
238
|
-
|
324
|
+
|
239
325
|
Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true
|
240
326
|
Gchart.line(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true
|
241
327
|
Gchart.line(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=bg,lg,90,efefef,0,ffffff,1").should be_true
|
242
|
-
|
328
|
+
|
243
329
|
Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'}).include?("chf=bg,ls,90,efefef,0.2,ffffff,0.2").should be_true
|
244
330
|
end
|
245
|
-
|
331
|
+
|
246
332
|
it "should be able to set a graph fill" do
|
247
333
|
Gchart.line(:graph_bg => 'efefef').include?("chf=c,s,efefef").should be_true
|
248
334
|
Gchart.line(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true
|
@@ -250,26 +336,26 @@ describe "a line chart" do
|
|
250
336
|
Gchart.line(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true
|
251
337
|
Gchart.line(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true
|
252
338
|
end
|
253
|
-
|
339
|
+
|
254
340
|
it "should be able to set both a graph and a background fill" do
|
255
341
|
Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true
|
256
342
|
Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true
|
257
343
|
Gchart.line(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true
|
258
344
|
end
|
259
|
-
|
345
|
+
|
260
346
|
it "should be able to have different line colors" do
|
261
347
|
Gchart.line(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true
|
262
348
|
Gchart.line(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true
|
263
349
|
end
|
264
|
-
|
350
|
+
|
265
351
|
it "should be able to render a graph where all the data values are 0" do
|
266
352
|
Gchart.line(:data => [0, 0, 0]).include?("chd=s:AAA").should be_true
|
267
353
|
end
|
268
|
-
|
354
|
+
|
269
355
|
end
|
270
356
|
|
271
357
|
describe "a sparkline chart" do
|
272
|
-
|
358
|
+
|
273
359
|
before(:each) do
|
274
360
|
@title = 'Chart Title'
|
275
361
|
@legend = ['first data set label', 'n data set label']
|
@@ -277,40 +363,40 @@ describe "a sparkline chart" do
|
|
277
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]
|
278
364
|
@chart = Gchart.sparkline(:title => @title, :data => @data, :legend => @legend)
|
279
365
|
end
|
280
|
-
|
366
|
+
|
281
367
|
it "should create a sparkline" do
|
282
368
|
@chart.include?('cht=ls').should be_true
|
283
369
|
end
|
284
|
-
|
370
|
+
|
285
371
|
it 'should be able have a chart title' do
|
286
372
|
@chart.include?("chtt=Chart+Title").should be_true
|
287
373
|
end
|
288
|
-
|
374
|
+
|
289
375
|
it "should be able to a custom color and size title" do
|
290
376
|
Gchart.sparkline(:title => @title, :title_color => 'FF0000').include?('chts=FF0000').should be_true
|
291
377
|
Gchart.sparkline(:title => @title, :title_size => '20').include?('chts=454545,20').should be_true
|
292
378
|
end
|
293
|
-
|
379
|
+
|
294
380
|
it "should be able to have multiple legends" do
|
295
381
|
@chart.include?(Gchart.jstize("chdl=first+data+set+label|n+data+set+label")).should be_true
|
296
382
|
end
|
297
|
-
|
383
|
+
|
298
384
|
it "should be able to have one legend" do
|
299
385
|
chart = Gchart.sparkline(:legend => 'legend label')
|
300
386
|
chart.include?("chdl=legend+label").should be_true
|
301
387
|
end
|
302
|
-
|
388
|
+
|
303
389
|
it "should be able to set the background fill" do
|
304
390
|
Gchart.sparkline(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true
|
305
391
|
Gchart.sparkline(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true
|
306
|
-
|
392
|
+
|
307
393
|
Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true
|
308
394
|
Gchart.sparkline(:bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=bg,lg,0,efefef,0,ffffff,1").should be_true
|
309
395
|
Gchart.sparkline(:bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=bg,lg,90,efefef,0,ffffff,1").should be_true
|
310
|
-
|
396
|
+
|
311
397
|
Gchart.sparkline(:bg => {:color => 'efefef', :type => 'stripes'}).include?("chf=bg,ls,90,efefef,0.2,ffffff,0.2").should be_true
|
312
398
|
end
|
313
|
-
|
399
|
+
|
314
400
|
it "should be able to set a graph fill" do
|
315
401
|
Gchart.sparkline(:graph_bg => 'efefef').include?("chf=c,s,efefef").should be_true
|
316
402
|
Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'solid'}).include?("chf=c,s,efefef").should be_true
|
@@ -318,22 +404,22 @@ describe "a sparkline chart" do
|
|
318
404
|
Gchart.sparkline(:graph_bg => {:color => 'efefef,0,ffffff,1', :type => 'gradient'}).include?("chf=c,lg,0,efefef,0,ffffff,1").should be_true
|
319
405
|
Gchart.sparkline(:graph_bg => {:color => 'efefef', :type => 'gradient', :angle => 90}).include?("chf=c,lg,90,efefef,0,ffffff,1").should be_true
|
320
406
|
end
|
321
|
-
|
407
|
+
|
322
408
|
it "should be able to set both a graph and a background fill" do
|
323
409
|
Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("bg,s,efefef").should be_true
|
324
410
|
Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?("c,s,76A4FB").should be_true
|
325
411
|
Gchart.sparkline(:bg => 'efefef', :graph_bg => '76A4FB').include?(Gchart.jstize("chf=c,s,76A4FB|bg,s,efefef")).should be_true
|
326
412
|
end
|
327
|
-
|
413
|
+
|
328
414
|
it "should be able to have different line colors" do
|
329
415
|
Gchart.sparkline(:line_colors => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true
|
330
416
|
Gchart.sparkline(:line_color => 'efefef|00ffff').include?(Gchart.jstize('chco=efefef|00ffff')).should be_true
|
331
417
|
end
|
332
|
-
|
418
|
+
|
333
419
|
end
|
334
420
|
|
335
421
|
describe "a 3d pie chart" do
|
336
|
-
|
422
|
+
|
337
423
|
before(:each) do
|
338
424
|
@title = 'Chart Title'
|
339
425
|
@legend = ['first data set label', 'n data set label']
|
@@ -341,21 +427,21 @@ describe "a 3d pie chart" do
|
|
341
427
|
@data = [12,8,40,15,5]
|
342
428
|
@chart = Gchart.pie(:title => @title, :legend => @legend, :data => @data)
|
343
429
|
end
|
344
|
-
|
430
|
+
|
345
431
|
it "should create a pie" do
|
346
432
|
@chart.include?('cht=p').should be_true
|
347
433
|
end
|
348
|
-
|
434
|
+
|
349
435
|
it "should be able to be in 3d" do
|
350
436
|
Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).include?('cht=p3').should be_true
|
351
437
|
end
|
352
|
-
|
438
|
+
|
353
439
|
it "should be able to set labels by using the legend or labesl accessor" do
|
354
440
|
Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data).include?("chl=#{@jstized_legend}").should be_true
|
355
441
|
Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).include?("chl=#{@jstized_legend}").should be_true
|
356
442
|
Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data).should == Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data)
|
357
443
|
end
|
358
|
-
|
444
|
+
|
359
445
|
end
|
360
446
|
|
361
447
|
describe "a google-o-meter" do
|
@@ -366,48 +452,82 @@ describe "a google-o-meter" do
|
|
366
452
|
@jstized_legend = Gchart.jstize(@legend.join('|'))
|
367
453
|
@chart = Gchart.meter(:data => @data)
|
368
454
|
end
|
369
|
-
|
455
|
+
|
370
456
|
it "should create a meter" do
|
371
457
|
@chart.include?('cht=gom').should be_true
|
372
458
|
end
|
373
|
-
|
459
|
+
|
374
460
|
it "should be able to set a solid background fill" do
|
375
461
|
Gchart.meter(:bg => 'efefef').include?("chf=bg,s,efefef").should be_true
|
376
462
|
Gchart.meter(:bg => {:color => 'efefef', :type => 'solid'}).include?("chf=bg,s,efefef").should be_true
|
377
463
|
end
|
378
|
-
|
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
|
+
|
379
499
|
end
|
380
500
|
|
381
501
|
describe 'exporting a chart' do
|
382
|
-
|
502
|
+
|
383
503
|
it "should be available in the url format by default" do
|
384
504
|
Gchart.line(:data => [0, 26], :format => 'url').should == Gchart.line(:data => [0, 26])
|
385
505
|
end
|
386
|
-
|
506
|
+
|
387
507
|
it "should be available as an image tag" do
|
388
508
|
Gchart.line(:data => [0, 26], :format => 'image_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/)
|
389
509
|
end
|
390
|
-
|
510
|
+
|
391
511
|
it "should be available as an image tag using img_tag alias" do
|
392
512
|
Gchart.line(:data => [0, 26], :format => 'img_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/)
|
393
513
|
end
|
394
|
-
|
514
|
+
|
395
515
|
it "should be available as an image tag using custom dimensions" do
|
396
516
|
Gchart.line(:data => [0, 26], :format => 'image_tag', :size => '400x400').should match(/<img src=(.*) width="400" height="400" alt="Google Chart" \/>/)
|
397
517
|
end
|
398
|
-
|
518
|
+
|
399
519
|
it "should be available as an image tag using custom alt text" do
|
400
520
|
Gchart.line(:data => [0, 26], :format => 'image_tag', :alt => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Sexy chart" \/>/)
|
401
521
|
end
|
402
|
-
|
522
|
+
|
403
523
|
it "should be available as an image tag using custom title text" do
|
404
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" \/>/)
|
405
525
|
end
|
406
|
-
|
526
|
+
|
407
527
|
it "should be available as an image tag using custom css id selector" do
|
408
528
|
Gchart.line(:data => [0, 26], :format => 'image_tag', :id => 'chart').should match(/<img id="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/)
|
409
529
|
end
|
410
|
-
|
530
|
+
|
411
531
|
it "should be available as an image tag using custom css class selector" do
|
412
532
|
Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should match(/<img class="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/)
|
413
533
|
end
|
@@ -416,25 +536,25 @@ describe 'exporting a chart' do
|
|
416
536
|
Gchart.line(:data => [0, 26]).should satisfy {|chart| chart.include? "&" }
|
417
537
|
Gchart.line(:data => [0, 26]).should_not satisfy {|chart| chart.include? "&" }
|
418
538
|
end
|
419
|
-
|
539
|
+
|
420
540
|
it "should escape ampersands in URLs when used as an image tag" do
|
421
541
|
Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should satisfy {|chart| chart.include? "&" }
|
422
542
|
end
|
423
|
-
|
543
|
+
|
424
544
|
it "should be available as a file" do
|
425
545
|
File.delete('chart.png') if File.exist?('chart.png')
|
426
546
|
Gchart.line(:data => [0, 26], :format => 'file')
|
427
547
|
File.exist?('chart.png').should be_true
|
428
548
|
File.delete('chart.png') if File.exist?('chart.png')
|
429
549
|
end
|
430
|
-
|
550
|
+
|
431
551
|
it "should be available as a file using a custom file name" do
|
432
552
|
File.delete('custom_file_name.png') if File.exist?('custom_file_name.png')
|
433
553
|
Gchart.line(:data => [0, 26], :format => 'file', :filename => 'custom_file_name.png')
|
434
554
|
File.exist?('custom_file_name.png').should be_true
|
435
555
|
File.delete('custom_file_name.png') if File.exist?('custom_file_name.png')
|
436
556
|
end
|
437
|
-
|
557
|
+
|
438
558
|
it "should work even with multiple attrs" do
|
439
559
|
File.delete('foo.png') if File.exist?('foo.png')
|
440
560
|
Gchart.line(:size => '400x200',
|
@@ -447,5 +567,5 @@ describe 'exporting a chart' do
|
|
447
567
|
File.exist?('foo.png').should be_true
|
448
568
|
File.delete('foo.png') if File.exist?('foo.png')
|
449
569
|
end
|
450
|
-
|
451
|
-
end
|
570
|
+
|
571
|
+
end
|