jparker-ruby-googlechart 0.6.2 → 0.6.3
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.
- data/CHANGELOG +8 -0
- data/Rakefile +1 -1
- data/lib/array.rb +7 -0
- data/lib/google_chart.rb +2 -0
- data/lib/google_chart/axis.rb +1 -1
- data/lib/google_chart/bar_chart.rb +32 -6
- data/lib/google_chart/data.rb +17 -8
- data/lib/google_chart/legend.rb +1 -1
- data/ruby-googlechart.gemspec +4 -4
- data/test/google_chart/test_axis.rb +2 -2
- data/test/google_chart/test_bar_chart.rb +81 -6
- data/test/google_chart/test_data.rb +38 -54
- data/test/google_chart/test_legend.rb +4 -0
- data/test/test_google_chart.rb +2 -2
- metadata +4 -2
data/CHANGELOG
CHANGED
@@ -20,3 +20,11 @@
|
|
20
20
|
== 0.6.2 2008-11-20
|
21
21
|
|
22
22
|
* Fixed axis label encoding to handle +nil+
|
23
|
+
|
24
|
+
== 0.6.3 2008-11-23
|
25
|
+
|
26
|
+
* Increased speed of Data#normalize
|
27
|
+
* Fixed axis label and legend encoding to handle non-Strings
|
28
|
+
* Raise ArgumentError if all data sets are empty
|
29
|
+
* Fixed auto-scaling of data containing +nil+
|
30
|
+
* Redesigned bar grouping (now supports overlapping) [BACKWARDS INCOMPATIBLE]
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('ruby-googlechart', '0.6.
|
5
|
+
Echoe.new('ruby-googlechart', '0.6.3') do |p|
|
6
6
|
p.description = 'Ruby wrapper around the Google Charts API'
|
7
7
|
p.url = 'http://github.com/jparker/ruby-googlechart'
|
8
8
|
p.author = 'John Parker'
|
data/lib/array.rb
ADDED
data/lib/google_chart.rb
CHANGED
data/lib/google_chart/axis.rb
CHANGED
@@ -13,7 +13,7 @@ module GoogleChart
|
|
13
13
|
[:x, :y, :r, :t].each do |axis|
|
14
14
|
case axes[axis]
|
15
15
|
when Array
|
16
|
-
@axis_labels << ("#{idx}:|" + axes[axis].map {|l| CGI::escape(l)
|
16
|
+
@axis_labels << ("#{idx}:|" + axes[axis].map {|l| CGI::escape(l.to_s) }.join('|'))
|
17
17
|
@axes << axis
|
18
18
|
idx += 1
|
19
19
|
when Range
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'matrix'
|
2
|
+
|
1
3
|
module GoogleChart
|
2
4
|
class BarChart < AbstractChart
|
3
5
|
include Axis
|
@@ -10,7 +12,7 @@ module GoogleChart
|
|
10
12
|
include Title
|
11
13
|
|
12
14
|
@@orientations = {:horizontal => 'h', :vertical => 'v'}
|
13
|
-
@@groupings = {:
|
15
|
+
@@groupings = {:group => 'g', :stack => 's', :overlap => 's'}
|
14
16
|
|
15
17
|
attr_writer :orientation, :grouping
|
16
18
|
|
@@ -18,14 +20,38 @@ module GoogleChart
|
|
18
20
|
self.orientation = arg ? :horizontal : :vertical
|
19
21
|
end
|
20
22
|
|
21
|
-
def grouped=(arg)
|
22
|
-
self.grouping = arg ? :grouped : :stacked
|
23
|
-
end
|
24
|
-
|
25
23
|
def chart_type
|
26
|
-
@grouping ||= :
|
24
|
+
@grouping ||= :group
|
27
25
|
@orientation ||= :vertical
|
28
26
|
"cht=b#{@@orientations[@orientation]}#{@@groupings[@grouping]}"
|
29
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def reduce(data)
|
31
|
+
if @grouping == :overlap
|
32
|
+
# FIXME: This is really ugly!
|
33
|
+
(data.size - 1).downto(1) do |i|
|
34
|
+
data[i].size.times do |j|
|
35
|
+
data[i][j] -= data[0...i].map {|set|
|
36
|
+
set[j].nil? || set[j] < 0 ? 0 : set[j]
|
37
|
+
}.sum
|
38
|
+
end
|
39
|
+
end
|
40
|
+
data
|
41
|
+
else
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def set_scale
|
47
|
+
if @grouping == :stack
|
48
|
+
if @scale.nil? && !@data.nil?
|
49
|
+
min = [0, @data.map {|set| set.compact.min }.compact.min].max
|
50
|
+
max = Matrix[*@data].column_vectors.map {|v| v.to_a.compact.sum }.max
|
51
|
+
@scale = min..max
|
52
|
+
end
|
53
|
+
end
|
54
|
+
super
|
55
|
+
end
|
30
56
|
end
|
31
57
|
end
|
data/lib/google_chart/data.rb
CHANGED
@@ -13,10 +13,14 @@ module GoogleChart
|
|
13
13
|
|
14
14
|
def data=(data)
|
15
15
|
@data = data.any? {|e| Array === e } ? data : [data]
|
16
|
+
if @data.all? {|set| set.compact.empty? }
|
17
|
+
raise ArgumentError, 'data must contain at least 1 non-nil value'
|
18
|
+
end
|
16
19
|
end
|
17
20
|
|
18
21
|
def data
|
19
|
-
|
22
|
+
set_scale
|
23
|
+
'chd=' + send(:"#{encoding}_encode", reduce(@data)) if @data
|
20
24
|
end
|
21
25
|
|
22
26
|
private
|
@@ -24,17 +28,22 @@ module GoogleChart
|
|
24
28
|
@encoding ||= :simple
|
25
29
|
end
|
26
30
|
|
27
|
-
def
|
28
|
-
if @scale.nil?
|
29
|
-
min =
|
30
|
-
|
31
|
+
def set_scale
|
32
|
+
if @scale.nil? && !@data.nil?
|
33
|
+
min = @data.map {|set| set.compact.min }.compact.min
|
34
|
+
min = 0 if min > 0
|
35
|
+
max = @data.map {|set| set.compact.max }.compact.max
|
31
36
|
@scale = min..max
|
32
37
|
end
|
33
38
|
@scale
|
34
39
|
end
|
35
40
|
|
41
|
+
def reduce(data)
|
42
|
+
data
|
43
|
+
end
|
44
|
+
|
36
45
|
def normalize(set, encoding_max)
|
37
|
-
min, max = scale.
|
46
|
+
min, max = @scale.first, @scale.last
|
38
47
|
if min != max
|
39
48
|
set.map {|e| (e.to_f - min) / (max - min) * encoding_max if e }
|
40
49
|
else
|
@@ -49,7 +58,7 @@ module GoogleChart
|
|
49
58
|
when e.nil? then '_'
|
50
59
|
when e <= 0 then @@simple[0]
|
51
60
|
when e >= @@simple.size then @@simple[-1]
|
52
|
-
else @@simple[e.
|
61
|
+
else @@simple[e.floor]
|
53
62
|
end
|
54
63
|
}.join
|
55
64
|
}.join(',')
|
@@ -62,7 +71,7 @@ module GoogleChart
|
|
62
71
|
when e.nil? then '__'
|
63
72
|
when e <= 0 then @@extended[0]
|
64
73
|
when e >= @@extended.size then @@extended[-1]
|
65
|
-
else @@extended[e.
|
74
|
+
else @@extended[e.floor]
|
66
75
|
end
|
67
76
|
}.join
|
68
77
|
}.join(',')
|
data/lib/google_chart/legend.rb
CHANGED
data/ruby-googlechart.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{ruby-googlechart}
|
5
|
-
s.version = "0.6.
|
5
|
+
s.version = "0.6.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["John Parker"]
|
9
|
-
s.date = %q{2008-11-
|
9
|
+
s.date = %q{2008-11-23}
|
10
10
|
s.description = %q{Ruby wrapper around the Google Charts API}
|
11
11
|
s.email = %q{jparker@urgetopunt.com}
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG", "lib/google_chart/abstract_chart.rb", "lib/google_chart/axis.rb", "lib/google_chart/bar_chart.rb", "lib/google_chart/bar_style.rb", "lib/google_chart/color.rb", "lib/google_chart/data.rb", "lib/google_chart/grid_line.rb", "lib/google_chart/legend.rb", "lib/google_chart/line_chart.rb", "lib/google_chart/line_style.rb", "lib/google_chart/range_marker.rb", "lib/google_chart/title.rb", "lib/google_chart.rb", "README.rdoc"]
|
13
|
-
s.files = ["CHANGELOG", "lib/google_chart/abstract_chart.rb", "lib/google_chart/axis.rb", "lib/google_chart/bar_chart.rb", "lib/google_chart/bar_style.rb", "lib/google_chart/color.rb", "lib/google_chart/data.rb", "lib/google_chart/grid_line.rb", "lib/google_chart/legend.rb", "lib/google_chart/line_chart.rb", "lib/google_chart/line_style.rb", "lib/google_chart/range_marker.rb", "lib/google_chart/title.rb", "lib/google_chart.rb", "Manifest", "Rakefile", "README.rdoc", "ruby-googlechart.gemspec", "test/google_chart/test_abstract_chart.rb", "test/google_chart/test_axis.rb", "test/google_chart/test_bar_chart.rb", "test/google_chart/test_bar_style.rb", "test/google_chart/test_color.rb", "test/google_chart/test_data.rb", "test/google_chart/test_grid_line.rb", "test/google_chart/test_legend.rb", "test/google_chart/test_line_chart.rb", "test/google_chart/test_line_style.rb", "test/google_chart/test_range_marker.rb", "test/google_chart/test_title.rb", "test/test_google_chart.rb", "test/test_helper.rb"]
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/array.rb", "lib/google_chart/abstract_chart.rb", "lib/google_chart/axis.rb", "lib/google_chart/bar_chart.rb", "lib/google_chart/bar_style.rb", "lib/google_chart/color.rb", "lib/google_chart/data.rb", "lib/google_chart/grid_line.rb", "lib/google_chart/legend.rb", "lib/google_chart/line_chart.rb", "lib/google_chart/line_style.rb", "lib/google_chart/range_marker.rb", "lib/google_chart/title.rb", "lib/google_chart.rb", "README.rdoc"]
|
13
|
+
s.files = ["CHANGELOG", "lib/array.rb", "lib/google_chart/abstract_chart.rb", "lib/google_chart/axis.rb", "lib/google_chart/bar_chart.rb", "lib/google_chart/bar_style.rb", "lib/google_chart/color.rb", "lib/google_chart/data.rb", "lib/google_chart/grid_line.rb", "lib/google_chart/legend.rb", "lib/google_chart/line_chart.rb", "lib/google_chart/line_style.rb", "lib/google_chart/range_marker.rb", "lib/google_chart/title.rb", "lib/google_chart.rb", "Manifest", "Rakefile", "README.rdoc", "ruby-googlechart.gemspec", "test/google_chart/test_abstract_chart.rb", "test/google_chart/test_axis.rb", "test/google_chart/test_bar_chart.rb", "test/google_chart/test_bar_style.rb", "test/google_chart/test_color.rb", "test/google_chart/test_data.rb", "test/google_chart/test_grid_line.rb", "test/google_chart/test_legend.rb", "test/google_chart/test_line_chart.rb", "test/google_chart/test_line_style.rb", "test/google_chart/test_range_marker.rb", "test/google_chart/test_title.rb", "test/test_google_chart.rb", "test/test_helper.rb"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://github.com/jparker/ruby-googlechart}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ruby-googlechart", "--main", "README.rdoc"]
|
@@ -49,8 +49,8 @@ class TestAxis < Test::Unit::TestCase
|
|
49
49
|
assert_match(/\bchxl=0:\|foo\+bar\|baz%7Cfroz\b/, @klass.new(:axes => {:x => ['foo bar', 'baz|froz']}).to_url)
|
50
50
|
end
|
51
51
|
|
52
|
-
should 'convert
|
53
|
-
assert_match(/\bchxl=0:\|foo\|\|
|
52
|
+
should 'convert non-String labels to Strings' do
|
53
|
+
assert_match(/\bchxl=0:\|foo\|\|1\b/, @klass.new(:axes => {:x => ['foo', nil, 1]}).to_url)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -2,19 +2,94 @@ require File.dirname(__FILE__) + '/../test_helper'
|
|
2
2
|
|
3
3
|
class TestBarChart < Test::Unit::TestCase
|
4
4
|
should 'have a default chart type' do
|
5
|
-
assert_match(/\bcht=
|
5
|
+
assert_match(/\bcht=bvg\b/, GoogleChart::BarChart.new.to_url)
|
6
6
|
end
|
7
7
|
|
8
8
|
should 'support horizontal orientation' do
|
9
|
-
assert_match(/\bcht=
|
9
|
+
assert_match(/\bcht=bhg\b/, GoogleChart::BarChart.new(:horizontal => true).to_url)
|
10
10
|
end
|
11
11
|
|
12
|
-
should 'support
|
13
|
-
assert_match(/\bcht=bvg\b/, GoogleChart::BarChart.new(:
|
12
|
+
should 'support grouping' do
|
13
|
+
assert_match(/\bcht=bvg\b/, GoogleChart::BarChart.new(:grouping => :group).to_url)
|
14
14
|
end
|
15
15
|
|
16
|
-
should 'support
|
17
|
-
assert_match(/\bcht=
|
16
|
+
should 'support stacking' do
|
17
|
+
assert_match(/\bcht=bvs\b/, GoogleChart::BarChart.new(:grouping => :stack).to_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'support overlapping as alias for stacking' do
|
21
|
+
assert_match(/\bcht=bvs\b/, GoogleChart::BarChart.new(:grouping => :overlap).to_url)
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'support horizontal orientation with grouping' do
|
25
|
+
assert_match(/\bcht=bhg\b/, GoogleChart::BarChart.new(:horizontal => true, :grouping => :group).to_url)
|
26
|
+
end
|
27
|
+
|
28
|
+
should 'support horizontal orientation with stacking' do
|
29
|
+
assert_match(/\bcht=bhs\b/, GoogleChart::BarChart.new(:horizontal => true, :grouping => :stack).to_url)
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'support horizontal orientation with overlapping' do
|
33
|
+
assert_match(/\bcht=bhs\b/, GoogleChart::BarChart.new(:horizontal => true, :grouping => :overlap).to_url)
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'data reduction and scaling' do
|
37
|
+
context 'with one data set' do
|
38
|
+
setup { @chart = GoogleChart::BarChart.new(:data => [0,2,3]) }
|
39
|
+
|
40
|
+
should 'scale normally for grouping' do
|
41
|
+
@chart.grouping = :group
|
42
|
+
assert_match(/\bchd=s:Ao9\b/, @chart.to_url)
|
43
|
+
end
|
44
|
+
|
45
|
+
should 'scale normally for stacking' do
|
46
|
+
@chart.grouping = :stack
|
47
|
+
assert_match(/\bchd=s:Ao9\b/, @chart.to_url)
|
48
|
+
end
|
49
|
+
|
50
|
+
should 'scale normally for overlapping' do
|
51
|
+
@chart.grouping = :overlap
|
52
|
+
assert_match(/\bchd=s:Ao9\b/, @chart.to_url)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'with two data sets' do
|
57
|
+
setup { @chart = GoogleChart::BarChart.new(:data => [[0,2,3], [0,4,6]]) }
|
58
|
+
|
59
|
+
should 'scale normally for grouping' do
|
60
|
+
@chart.grouping = :group
|
61
|
+
assert_match(/\bchd=s:AUe,Ao9\b/, @chart.to_url)
|
62
|
+
end
|
63
|
+
|
64
|
+
should 'scale based on column sums for stacking' do
|
65
|
+
@chart.grouping = :stack
|
66
|
+
assert_match(/\bchd=s:ANU,Abo\b/, @chart.to_url)
|
67
|
+
end
|
68
|
+
|
69
|
+
should 'scale based on reduced data for overlapping' do
|
70
|
+
@chart.grouping = :overlap
|
71
|
+
assert_match(/\bchd=s:AUe,AUe\b/, @chart.to_url)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'with three data sets' do
|
76
|
+
setup { @chart = GoogleChart::BarChart.new(:data => [[0,2,3], [0,4,6], [0,6,9]]) }
|
77
|
+
|
78
|
+
should 'scale normally for grouping' do
|
79
|
+
@chart.grouping = :group
|
80
|
+
assert_match(/\bchd=s:ANU,Abo,Ao9\b/, @chart.to_url)
|
81
|
+
end
|
82
|
+
|
83
|
+
should 'scale based on column sums for stacking' do
|
84
|
+
@chart.grouping = :stack
|
85
|
+
assert_match(/\bchd=s:AGK,ANU,AUe\b/, @chart.to_url)
|
86
|
+
end
|
87
|
+
|
88
|
+
should 'scale based on reduced data for overlapping' do
|
89
|
+
@chart.grouping = :overlap
|
90
|
+
assert_match(/\bchd=s:ANU,ANU,AAA\b/, @chart.to_url)
|
91
|
+
end
|
92
|
+
end
|
18
93
|
end
|
19
94
|
|
20
95
|
should 'include Axis module' do
|
@@ -9,18 +9,50 @@ class TestData < Test::Unit::TestCase
|
|
9
9
|
assert_match(/\bchd=s:AB89\b/, @klass.new(:data => [0, 1, 60, 61]).to_url)
|
10
10
|
end
|
11
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
|
+
|
12
44
|
context 'simple encoding' do
|
13
45
|
setup { @chart = @klass.new(:encoding => :simple) }
|
14
46
|
|
15
47
|
should 'encode dataset with auto-scaling' do
|
16
48
|
@chart.data = [0, 15, 10]
|
17
|
-
assert_match(/\bchd=s:
|
49
|
+
assert_match(/\bchd=s:A9o\b/, @chart.to_url)
|
18
50
|
end
|
19
51
|
|
20
52
|
should 'encode dataset with manual scaling' do
|
21
53
|
@chart.data = [0, 15, 10]
|
22
54
|
@chart.scale = 0..20
|
23
|
-
assert_match(/\bchd=s:
|
55
|
+
assert_match(/\bchd=s:Ate\b/, @chart.to_url)
|
24
56
|
end
|
25
57
|
|
26
58
|
should 'encode multiple datasets' do
|
@@ -30,27 +62,11 @@ class TestData < Test::Unit::TestCase
|
|
30
62
|
end
|
31
63
|
|
32
64
|
should 'encode floating point data' do
|
33
|
-
@chart.data = [
|
65
|
+
@chart.data = [50.5, 33.4]
|
34
66
|
@chart.scale = 0..61
|
35
67
|
assert_match(/\bchd=s:yh\b/, @chart.to_url)
|
36
68
|
end
|
37
69
|
|
38
|
-
should 'encode all zeros with "A"' do
|
39
|
-
@chart.data = [0, 0, 0]
|
40
|
-
assert_match(/\bchd=s:AAA\b/, @chart.to_url)
|
41
|
-
end
|
42
|
-
|
43
|
-
should 'encode unchanging non-zero data with "9"' do
|
44
|
-
@chart.data = [1, 1, 1]
|
45
|
-
assert_match(/\bchd=s:999\b/, @chart.to_url)
|
46
|
-
end
|
47
|
-
|
48
|
-
should 'encode out-of-bounds data' do
|
49
|
-
@chart.data = [62, 61, 60, 1, 0, -1]
|
50
|
-
@chart.scale = 0..61
|
51
|
-
assert_match(/\bchd=s:998BAA/, @chart.to_url)
|
52
|
-
end
|
53
|
-
|
54
70
|
should 'encode missing data' do
|
55
71
|
@chart.data = [50, nil, 33]
|
56
72
|
@chart.scale = 0..61
|
@@ -67,9 +83,9 @@ class TestData < Test::Unit::TestCase
|
|
67
83
|
end
|
68
84
|
|
69
85
|
should 'encode dataset with manual scaling' do
|
70
|
-
@chart.data = [
|
86
|
+
@chart.data = [15, 10, 0]
|
71
87
|
@chart.scale = 0..20
|
72
|
-
assert_match(/\bchd=e:
|
88
|
+
assert_match(/\bchd=e:v\.f\.AA\b/, @chart.to_url)
|
73
89
|
end
|
74
90
|
|
75
91
|
should 'encode multiple datasets' do
|
@@ -79,27 +95,11 @@ class TestData < Test::Unit::TestCase
|
|
79
95
|
end
|
80
96
|
|
81
97
|
should 'encode floating point data' do
|
82
|
-
@chart.data = [2281.49,
|
98
|
+
@chart.data = [2281.49, 3233.50]
|
83
99
|
@chart.scale = 0..4095
|
84
100
|
assert_match(/\bchd=e:jpyh\b/, @chart.to_url)
|
85
101
|
end
|
86
102
|
|
87
|
-
should 'encode all zeros with "AA"' do
|
88
|
-
@chart.data = [0, 0, 0]
|
89
|
-
assert_match(/\bchd=e:AAAAAA\b/, @chart.to_url)
|
90
|
-
end
|
91
|
-
|
92
|
-
should 'encode unchanging non-zero data with ".."' do
|
93
|
-
@chart.data = [1, 1, 1]
|
94
|
-
assert_match(/\bchd=e:\.{6}/, @chart.to_url)
|
95
|
-
end
|
96
|
-
|
97
|
-
should 'encode out-of-bounds data' do
|
98
|
-
@chart.data = [4096, 4095, 4094, 1, 0, -1]
|
99
|
-
@chart.scale = 0..4095
|
100
|
-
assert_match(/\bchd=e:\.\.\.\.\.-ABAAAA\b/, @chart.to_url)
|
101
|
-
end
|
102
|
-
|
103
103
|
should 'encode missing data' do
|
104
104
|
@chart.data = [2281, nil, 3233]
|
105
105
|
@chart.scale = 0..4095
|
@@ -133,22 +133,6 @@ class TestData < Test::Unit::TestCase
|
|
133
133
|
assert_match(/\bchd=t:6,14,5.2\b/, @chart.to_url)
|
134
134
|
end
|
135
135
|
|
136
|
-
should 'encode all zeros with "0"' do
|
137
|
-
@chart.data = [0, 0, 0]
|
138
|
-
assert_match(/\bchd=t:0,0,0\b/, @chart.to_url)
|
139
|
-
end
|
140
|
-
|
141
|
-
should 'encode unchanging non-zero data with "100"' do
|
142
|
-
@chart.data = [1, 1, 1]
|
143
|
-
assert_match(/\bchd=t:100,100,100\b/, @chart.to_url)
|
144
|
-
end
|
145
|
-
|
146
|
-
should 'encode out-of-bounds data' do
|
147
|
-
@chart.data = [101, 100, 99, 1, 0, -1]
|
148
|
-
@chart.scale = 0..100
|
149
|
-
assert_match(/\bchd=t:100,100,99,1,0,0\b/, @chart.to_url)
|
150
|
-
end
|
151
|
-
|
152
136
|
should 'encode missing data' do
|
153
137
|
@chart.data = [6, nil, 14]
|
154
138
|
@chart.scale = 0..100
|
@@ -20,4 +20,8 @@ class TestLegend < Test::Unit::TestCase
|
|
20
20
|
should 'escape legend text for url' do
|
21
21
|
assert_match(/\bchdl=Foo\+Bar%7CBaz\b/, @klass.new(:legend => 'Foo Bar|Baz').to_url)
|
22
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
|
23
27
|
end
|
data/test/test_google_chart.rb
CHANGED
@@ -62,7 +62,7 @@ class TestGoogleChart < Test::Unit::TestCase
|
|
62
62
|
end
|
63
63
|
|
64
64
|
should 'include chart type parameter' do
|
65
|
-
assert_match(/\bcht=
|
65
|
+
assert_match(/\bcht=bvg\b/, @url)
|
66
66
|
end
|
67
67
|
|
68
68
|
should 'include chart size parameter' do
|
@@ -88,7 +88,7 @@ class TestGoogleChart < Test::Unit::TestCase
|
|
88
88
|
end
|
89
89
|
|
90
90
|
should 'include chart type parameter' do
|
91
|
-
assert_match(/\bcht=
|
91
|
+
assert_match(/\bcht=bvg\b/, @url)
|
92
92
|
end
|
93
93
|
|
94
94
|
should 'include chart size parameter' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jparker-ruby-googlechart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Parker
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-11-
|
12
|
+
date: 2008-11-23 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -29,6 +29,7 @@ extensions: []
|
|
29
29
|
|
30
30
|
extra_rdoc_files:
|
31
31
|
- CHANGELOG
|
32
|
+
- lib/array.rb
|
32
33
|
- lib/google_chart/abstract_chart.rb
|
33
34
|
- lib/google_chart/axis.rb
|
34
35
|
- lib/google_chart/bar_chart.rb
|
@@ -45,6 +46,7 @@ extra_rdoc_files:
|
|
45
46
|
- README.rdoc
|
46
47
|
files:
|
47
48
|
- CHANGELOG
|
49
|
+
- lib/array.rb
|
48
50
|
- lib/google_chart/abstract_chart.rb
|
49
51
|
- lib/google_chart/axis.rb
|
50
52
|
- lib/google_chart/bar_chart.rb
|