ruby-googlechart 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/CHANGELOG +30 -0
- data/LICENSE +20 -0
- data/README.rdoc +59 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/array.rb +7 -0
- data/lib/google_chart.rb +30 -0
- data/lib/google_chart/abstract_chart.rb +48 -0
- data/lib/google_chart/axis.rb +40 -0
- data/lib/google_chart/bar_chart.rb +57 -0
- data/lib/google_chart/bar_style.rb +19 -0
- data/lib/google_chart/color.rb +16 -0
- data/lib/google_chart/data.rb +99 -0
- data/lib/google_chart/grid_line.rb +21 -0
- data/lib/google_chart/legend.rb +16 -0
- data/lib/google_chart/line_chart.rb +24 -0
- data/lib/google_chart/line_style.rb +36 -0
- data/lib/google_chart/range_marker.rb +26 -0
- data/lib/google_chart/title.rb +16 -0
- data/ruby-googlechart.gemspec +90 -0
- data/test/google_chart/test_abstract_chart.rb +29 -0
- data/test/google_chart/test_axis.rb +74 -0
- data/test/google_chart/test_bar_chart.rb +126 -0
- data/test/google_chart/test_bar_style.rb +23 -0
- data/test/google_chart/test_color.rb +21 -0
- data/test/google_chart/test_data.rb +142 -0
- data/test/google_chart/test_grid_line.rb +35 -0
- data/test/google_chart/test_legend.rb +27 -0
- data/test/google_chart/test_line_chart.rb +51 -0
- data/test/google_chart/test_line_style.rb +47 -0
- data/test/google_chart/test_range_marker.rb +27 -0
- data/test/google_chart/test_title.rb +15 -0
- data/test/test_google_chart.rb +103 -0
- data/test/test_helper.rb +10 -0
- metadata +112 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class TestBarStyle < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@klass = Class.new(MockChart).class_eval { include GoogleChart::BarStyle }
|
6
|
+
end
|
7
|
+
|
8
|
+
should 'not display bar style parameter by default' do
|
9
|
+
assert_no_match(/\bchbh=/, @klass.new.to_url)
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'display with custom bar width' do
|
13
|
+
assert_match(/\bchbh=10\b/, @klass.new(:width => 10).to_url)
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'display with custom bar width and spacing' do
|
17
|
+
assert_match(/\bchbh=8,6\b/, @klass.new(:width => 8, :spacing => 6).to_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'display with custom bar width, spacing and group spacing' do
|
21
|
+
assert_match(/\bchbh=10,4,12\b/, @klass.new(:width => 10, :spacing => [4,12]).to_url)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class TestColor < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@klass = Class.new(MockChart).class_eval { include GoogleChart::Color }
|
6
|
+
end
|
7
|
+
|
8
|
+
should 'not display color parameter by default' do
|
9
|
+
assert_no_match(/\bchco=/, @klass.new.to_url)
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'display single color parameter' do
|
13
|
+
assert_match(/\bchco=ff0000\b/, @klass.new(:color => 'ff0000').to_url)
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'display multiple color parameters' do
|
17
|
+
assert_match(/\bchco=ff0000,00ff00,0000ff\b/, @klass.new(:color => %w[ff0000 00ff00 0000ff]).to_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'convert 3-digit colors to 6-digit colors'
|
21
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class TestData < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@klass = Class.new(MockChart).class_eval { include GoogleChart::Data }
|
6
|
+
end
|
7
|
+
|
8
|
+
should 'use simple encoding by default' do
|
9
|
+
assert_match(/\bchd=s:AB89\b/, @klass.new(:data => [0, 1, 60, 61]).to_url)
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'raise an ArgumentError if data set is empty' do
|
13
|
+
assert_raise(ArgumentError, /1 non-nil value/) { @klass.new(:data => []) }
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'raise an ArgumentError if data set contains only nils' do
|
17
|
+
assert_raise(ArgumentError, /1 non-nil value/) { @klass.new(:data => [nil, nil]) }
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'not raise an ArgumentError if only one of many data sets contains only nils' do
|
21
|
+
assert_nothing_raised(ArgumentError) { @klass.new(:data => [[nil, nil], [nil, 1]]) }
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'auto-scale between 0 and maximum value among all data sets' do
|
25
|
+
assert_match(/\bchd=s:67,89\b/, @klass.new(:data => [[58, 59], [60, 61]]).to_url)
|
26
|
+
end
|
27
|
+
|
28
|
+
should 'be able to auto-scale data sets with nils' do
|
29
|
+
assert_match(/\bchd=s:A_9\b/, @klass.new(:data => [0, nil, 100]).to_url)
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'be able to auto-scale data sets with one empty set' do
|
33
|
+
assert_match(/\bchd=s:__,A9\b/, @klass.new(:data => [[nil, nil], [0, 100]]).to_url)
|
34
|
+
end
|
35
|
+
|
36
|
+
should 'encode data with high-pass filter when auto-scaling' do
|
37
|
+
assert_match(/\bchd=s:AAB89\b/, @klass.new(:data => [-1, 0, 1, 60, 61]).to_url)
|
38
|
+
end
|
39
|
+
|
40
|
+
should 'encode data with band-pass filter when manual-scaling' do
|
41
|
+
assert_match(/\bchd=s:AB899\b/, @klass.new(:data => [-5, -1, 99, 100, 102], :scale => -3..100).to_url)
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'simple encoding' do
|
45
|
+
setup { @chart = @klass.new(:encoding => :simple) }
|
46
|
+
|
47
|
+
should 'encode dataset with auto-scaling' do
|
48
|
+
@chart.data = [0, 15, 10]
|
49
|
+
assert_match(/\bchd=s:A9o\b/, @chart.to_url)
|
50
|
+
end
|
51
|
+
|
52
|
+
should 'encode dataset with manual scaling' do
|
53
|
+
@chart.data = [0, 15, 10]
|
54
|
+
@chart.scale = 0..20
|
55
|
+
assert_match(/\bchd=s:Ate\b/, @chart.to_url)
|
56
|
+
end
|
57
|
+
|
58
|
+
should 'encode multiple datasets' do
|
59
|
+
@chart.data = [[9, 15], [24, 7]]
|
60
|
+
@chart.scale = 0..61
|
61
|
+
assert_match(/\bchd=s:JP,YH\b/, @chart.to_url)
|
62
|
+
end
|
63
|
+
|
64
|
+
should 'encode floating point data' do
|
65
|
+
@chart.data = [50.5, 33.4]
|
66
|
+
@chart.scale = 0..61
|
67
|
+
assert_match(/\bchd=s:yh\b/, @chart.to_url)
|
68
|
+
end
|
69
|
+
|
70
|
+
should 'encode missing data' do
|
71
|
+
@chart.data = [50, nil, 33]
|
72
|
+
@chart.scale = 0..61
|
73
|
+
assert_match(/\bchd=s:y_h\b/, @chart.to_url)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'extended encoding' do
|
78
|
+
setup { @chart = @klass.new(:encoding => :extended) }
|
79
|
+
|
80
|
+
should 'encode dataset with auto-scaling' do
|
81
|
+
@chart.data = [0, 15, 10]
|
82
|
+
assert_match(/\bchd=e:AA\.\.qq\b/, @chart.to_url)
|
83
|
+
end
|
84
|
+
|
85
|
+
should 'encode dataset with manual scaling' do
|
86
|
+
@chart.data = [15, 10, 0]
|
87
|
+
@chart.scale = 0..20
|
88
|
+
assert_match(/\bchd=e:v\.f\.AA\b/, @chart.to_url)
|
89
|
+
end
|
90
|
+
|
91
|
+
should 'encode multiple datasets' do
|
92
|
+
@chart.data = [[2281, 3233], [591, 1543]]
|
93
|
+
@chart.scale = 0..4095
|
94
|
+
assert_match(/\bchd=e:jpyh,JPYH\b/, @chart.to_url)
|
95
|
+
end
|
96
|
+
|
97
|
+
should 'encode floating point data' do
|
98
|
+
@chart.data = [2281.49, 3233.50]
|
99
|
+
@chart.scale = 0..4095
|
100
|
+
assert_match(/\bchd=e:jpyh\b/, @chart.to_url)
|
101
|
+
end
|
102
|
+
|
103
|
+
should 'encode missing data' do
|
104
|
+
@chart.data = [2281, nil, 3233]
|
105
|
+
@chart.scale = 0..4095
|
106
|
+
assert_match(/\bchd=e:jp__yh\b/, @chart.to_url)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'text encoding' do
|
111
|
+
setup { @chart = @klass.new(:encoding => :text) }
|
112
|
+
|
113
|
+
should 'encode dataset with auto-scaling' do
|
114
|
+
@chart.data = [0, 15, 10]
|
115
|
+
assert_match(/\bchd=t:0,100,66.7\b/, @chart.to_url)
|
116
|
+
end
|
117
|
+
|
118
|
+
should 'encode dataset with manual scaling' do
|
119
|
+
@chart.data = [0, 15, 10]
|
120
|
+
@chart.scale = 0..20
|
121
|
+
assert_match(/\bchd=t:0,75,50\b/, @chart.to_url)
|
122
|
+
end
|
123
|
+
|
124
|
+
should 'encode multiple datasets' do
|
125
|
+
@chart.data = [[6, 14], [5, 23]]
|
126
|
+
@chart.scale = 0..100
|
127
|
+
assert_match(/\bchd=t:6,14\|5,23\b/, @chart.to_url)
|
128
|
+
end
|
129
|
+
|
130
|
+
should 'rounds floating point data to the nearest tenth' do
|
131
|
+
@chart.data = [5.95, 14.01, 5.23]
|
132
|
+
@chart.scale = 0..100
|
133
|
+
assert_match(/\bchd=t:6,14,5.2\b/, @chart.to_url)
|
134
|
+
end
|
135
|
+
|
136
|
+
should 'encode missing data' do
|
137
|
+
@chart.data = [6, nil, 14]
|
138
|
+
@chart.scale = 0..100
|
139
|
+
assert_match(/\bchd=t:6,-1,14\b/, @chart.to_url)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class TestGridLine < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@klass = Class.new(MockChart).class_eval { include GoogleChart::GridLine }
|
6
|
+
end
|
7
|
+
|
8
|
+
should 'not display grid lines by default' do
|
9
|
+
assert_no_match(/\bchg=/, @klass.new.to_url)
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'display vertical grid lines' do
|
13
|
+
assert_match(/\bchg=5,0\b/, @klass.new(:grid => {:x => 5}).to_url)
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'display horizontal grid lines' do
|
17
|
+
assert_match(/\bchg=0,5\b/, @klass.new(:grid => {:y => 5}).to_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'display horizontal and vertical grid lines' do
|
21
|
+
assert_match(/\bchg=6,14\b/, @klass.new(:grid => {:x => 6, :y => 14}).to_url)
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'display solid grid lines' do
|
25
|
+
assert_match(/\bchg=8,16,1,0\b/, @klass.new(:grid => {:x => 8, :y => 16, :style => :solid}).to_url)
|
26
|
+
end
|
27
|
+
|
28
|
+
should 'display dashed grid lines' do
|
29
|
+
assert_match(/\bchg=8,16,3,2\b/, @klass.new(:grid => {:x => 8, :y => 16, :style => :dash}).to_url)
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'display dotted grid lines' do
|
33
|
+
assert_match(/\bchg=8,16,1,2\b/, @klass.new(:grid => {:x => 8, :y => 16, :style => :dot}).to_url)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class TestLegend < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@klass = Class.new(MockChart).class_eval { include GoogleChart::Legend }
|
6
|
+
end
|
7
|
+
|
8
|
+
should 'not display legend by default' do
|
9
|
+
assert_no_match(/\bchdl=/, @klass.new.to_url)
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'display legend for single dataset' do
|
13
|
+
assert_match(/\bchdl=Foo\b/, @klass.new(:legend => 'Foo').to_url)
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'display legend for multiple datasets' do
|
17
|
+
assert_match(/\bchdl=Foo\|Bar\|Baz\b/, @klass.new(:legend => %w[Foo Bar Baz]).to_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'escape legend text for url' do
|
21
|
+
assert_match(/\bchdl=Foo\+Bar%7CBaz\b/, @klass.new(:legend => 'Foo Bar|Baz').to_url)
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'convert non-String legend keys to Strings' do
|
25
|
+
assert_match(/\bchdl=foo\|\|1\b/, @klass.new(:legend => ['foo', nil, 1]).to_url)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class TestLineChart < Test::Unit::TestCase
|
4
|
+
should 'have a default chart type' do
|
5
|
+
assert_match(/\bcht=lc\b/, GoogleChart::LineChart.new.to_url)
|
6
|
+
end
|
7
|
+
|
8
|
+
should 'support xy chart type' do
|
9
|
+
assert_match(/\bcht=lxy\b/, GoogleChart::LineChart.new(:type => :xy).to_url)
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'support sparkline chart type' do
|
13
|
+
assert_match(/\bcht=ls\b/, GoogleChart::LineChart.new(:type => :sparkline).to_url)
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'support line as chart type' do
|
17
|
+
assert_match(/\bcht=lc\b/, GoogleChart::LineChart.new(:type => :line).to_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'include Axis module' do
|
21
|
+
assert GoogleChart::Axis === GoogleChart::LineChart.new
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'include Color module' do
|
25
|
+
assert GoogleChart::Color === GoogleChart::LineChart.new
|
26
|
+
end
|
27
|
+
|
28
|
+
should 'include Data module' do
|
29
|
+
assert GoogleChart::Data === GoogleChart::LineChart.new
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'include GridLine module' do
|
33
|
+
assert GoogleChart::GridLine === GoogleChart::LineChart.new
|
34
|
+
end
|
35
|
+
|
36
|
+
should 'include Legend module' do
|
37
|
+
assert GoogleChart::Legend === GoogleChart::LineChart.new
|
38
|
+
end
|
39
|
+
|
40
|
+
should 'include LineStyle module' do
|
41
|
+
assert GoogleChart::LineStyle === GoogleChart::LineChart.new
|
42
|
+
end
|
43
|
+
|
44
|
+
should 'include RangeMarker module' do
|
45
|
+
assert GoogleChart::RangeMarker === GoogleChart::LineChart.new
|
46
|
+
end
|
47
|
+
|
48
|
+
should 'include Title module' do
|
49
|
+
assert GoogleChart::Title === GoogleChart::LineChart.new
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class TestLineStyle < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@klass = Class.new(MockChart).class_eval { include GoogleChart::LineStyle }
|
6
|
+
end
|
7
|
+
|
8
|
+
should 'not include line styles by default' do
|
9
|
+
assert_no_match(/\bchls=/, @klass.new.to_url)
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'support solid lines' do
|
13
|
+
assert_match(/\bchls=1,1,0\b/, @klass.new(:style => :solid).to_url)
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'support dashed lines' do
|
17
|
+
assert_match(/\bchls=1,3,2\b/, @klass.new(:style => :dash).to_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'support dotted lines' do
|
21
|
+
assert_match(/\bchls=1,1,2\b/, @klass.new(:style => :dot).to_url)
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'support multiple line styles' do
|
25
|
+
assert_match(/\bchls=1,3,2\|1,1,2\|1,1,0\b/, @klass.new(:style => [:dash, :dot, :solid]).to_url)
|
26
|
+
end
|
27
|
+
|
28
|
+
should 'support custom line width' do
|
29
|
+
assert_match(/\bchls=2,2,0\b/, @klass.new(:width => 2).to_url)
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'support named line style with custom width' do
|
33
|
+
assert_match(/\bchls=2,6,4\b/, @klass.new(:style => :dash, :width => 2).to_url)
|
34
|
+
end
|
35
|
+
|
36
|
+
should 'support multiple line styles and multiple custom widths' do
|
37
|
+
assert_match(/\bchls=2,2,4\|3,9,6\b/, @klass.new(:style => [:dot, :dash], :width => [2, 3]).to_url)
|
38
|
+
end
|
39
|
+
|
40
|
+
should 'use default line width if there are more styles than widths' do
|
41
|
+
assert_match(/\bchls=2,2,4\|1,3,2\|1,1,0\b/, @klass.new(:style => [:dot, :dash, :solid], :width => 2).to_url)
|
42
|
+
end
|
43
|
+
|
44
|
+
should 'use default line style if there are more widths than styles' do
|
45
|
+
assert_match(/\bchls=2,2,4\|3,3,0\|2,2,0\b/, @klass.new(:style => :dot, :width => [2, 3, 2]).to_url)
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class TestRangeMarker < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@klass = Class.new(MockChart).class_eval { include GoogleChart::RangeMarker }
|
6
|
+
end
|
7
|
+
|
8
|
+
should 'not have range markers by default' do
|
9
|
+
assert_no_match(/\bchm=/, @klass.new.to_url)
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'display horizontal range markers' do
|
13
|
+
assert_match(/\bchm=r,000000cc,x,0.45,0.55\b/, @klass.new(:ranges => [:h, 0.45, 0.55]).to_url)
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'display vertical range markers' do
|
17
|
+
assert_match(/\bchm=R,000000cc,x,0.45,0.55\b/, @klass.new(:ranges => [:v, 0.45, 0.55]).to_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'display multiple range markers' do
|
21
|
+
assert_match(/\bchm=r,000000cc,x,0.1,0.2\|R,000000cc,x,0.3,0.4\b/, @klass.new(:ranges => [[:h, 0.1, 0.2], [:v, 0.3, 0.4]]).to_url)
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'display range markers with custom colors' do
|
25
|
+
assert_match(/\bchm=r,abcdef,x,0.4,0.6\b/, @klass.new(:ranges => [:h, 'abcdef', 0.4, 0.6]).to_url)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class TestTitle < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@klass = Class.new(MockChart).class_eval { include GoogleChart::Title }
|
6
|
+
end
|
7
|
+
|
8
|
+
should 'not have a title by default' do
|
9
|
+
assert_no_match(/\bchtt=/, @klass.new.to_url)
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'url-encode title' do
|
13
|
+
assert_match(/\bchtt=foo\+bar\b/, @klass.new(:title => 'foo bar').to_url)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestGoogleChart < Test::Unit::TestCase
|
4
|
+
context '#Line' do
|
5
|
+
context 'with hash parameters' do
|
6
|
+
setup do
|
7
|
+
@url = GoogleChart.Line(:size => '1000x300', :data => [[35, 41], [50, 33]], :scale => 0..61)
|
8
|
+
end
|
9
|
+
|
10
|
+
should 'return Google Chart URL' do
|
11
|
+
assert_match(%r{\Ahttp://chart\.apis\.google\.com/chart\?}, @url)
|
12
|
+
end
|
13
|
+
|
14
|
+
should 'include chart type parameter' do
|
15
|
+
assert_match(/\bcht=lc\b/, @url)
|
16
|
+
end
|
17
|
+
|
18
|
+
should 'include chart size parameter' do
|
19
|
+
assert_match(/\bchs=1000x300\b/, @url)
|
20
|
+
end
|
21
|
+
|
22
|
+
should 'include chart data parameter' do
|
23
|
+
assert_match(/\bchd=s:jp,yh\b/, @url)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with block parameters' do
|
28
|
+
setup do
|
29
|
+
@url = GoogleChart.Line do |c|
|
30
|
+
c.size = '800x375'
|
31
|
+
c.data = [[35, 41], [50, 33]]
|
32
|
+
c.scale = 0..61
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
should 'return Google Chart URL' do
|
37
|
+
assert_match(%r{\Ahttp://chart\.apis\.google\.com/chart\?}, @url)
|
38
|
+
end
|
39
|
+
|
40
|
+
should 'include chart type parameter' do
|
41
|
+
assert_match(/\bcht=lc\b/, @url)
|
42
|
+
end
|
43
|
+
|
44
|
+
should 'include chart size parameter' do
|
45
|
+
assert_match(/\bchs=800x375\b/, @url)
|
46
|
+
end
|
47
|
+
|
48
|
+
should 'include chart data parameter' do
|
49
|
+
assert_match(/\bchd=s:jp,yh\b/, @url)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context '#Bar' do
|
55
|
+
context 'with hash parameters' do
|
56
|
+
setup do
|
57
|
+
@url = GoogleChart.Bar(:size => '1000x300', :data => [[35, 41], [50, 33]], :scale => 0..61)
|
58
|
+
end
|
59
|
+
|
60
|
+
should 'return Google Chart URL' do
|
61
|
+
assert_match(%r{\Ahttp://chart\.apis\.google\.com/chart\?}, @url)
|
62
|
+
end
|
63
|
+
|
64
|
+
should 'include chart type parameter' do
|
65
|
+
assert_match(/\bcht=bvg\b/, @url)
|
66
|
+
end
|
67
|
+
|
68
|
+
should 'include chart size parameter' do
|
69
|
+
assert_match(/\bchs=1000x300\b/, @url)
|
70
|
+
end
|
71
|
+
|
72
|
+
should 'include chart data parameter' do
|
73
|
+
assert_match(/\bchd=s:jp,yh\b/, @url)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'with block parameters' do
|
78
|
+
setup do
|
79
|
+
@url = GoogleChart.Bar do |c|
|
80
|
+
c.size = '800x375'
|
81
|
+
c.data = [[35, 41], [50, 33]]
|
82
|
+
c.scale = 0..61
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
should 'return Google Chart URL' do
|
87
|
+
assert_match(%r{\Ahttp://chart\.apis\.google\.com/chart\?}, @url)
|
88
|
+
end
|
89
|
+
|
90
|
+
should 'include chart type parameter' do
|
91
|
+
assert_match(/\bcht=bvg\b/, @url)
|
92
|
+
end
|
93
|
+
|
94
|
+
should 'include chart size parameter' do
|
95
|
+
assert_match(/\bchs=800x375\b/, @url)
|
96
|
+
end
|
97
|
+
|
98
|
+
should 'include chart data parameter' do
|
99
|
+
assert_match(/\bchd=s:jp,yh\b/, @url)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|