jparker-ruby-googlechart 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/google_chart/{base.rb → abstract_chart.rb} +15 -9
- data/lib/google_chart/{axes.rb → axis.rb} +11 -11
- data/lib/google_chart/bar_chart.rb +31 -0
- data/lib/google_chart/bar_style.rb +19 -0
- data/lib/google_chart/{colors.rb → color.rb} +5 -3
- data/lib/google_chart/data.rb +36 -41
- data/lib/google_chart/{grid_lines.rb → grid_line.rb} +5 -5
- data/lib/google_chart/{legends.rb → legend.rb} +5 -3
- data/lib/google_chart/{line.rb → line_chart.rb} +10 -10
- data/lib/google_chart/{line_styles.rb → line_style.rb} +17 -16
- data/lib/google_chart/{range_markers.rb → range_marker.rb} +5 -5
- data/lib/google_chart/{titles.rb → title.rb} +5 -5
- data/lib/google_chart.rb +16 -15
- data/test/google_chart/{test_base.rb → test_abstract_chart.rb} +12 -4
- data/test/google_chart/{test_axes.rb → test_axis.rb} +2 -2
- data/test/google_chart/test_bar_chart.rb +51 -0
- data/test/google_chart/{test_bar_styles.rb → test_bar_style.rb} +2 -2
- data/test/google_chart/{test_colors.rb → test_color.rb} +2 -2
- data/test/google_chart/test_data.rb +78 -31
- data/test/google_chart/{test_grid_lines.rb → test_grid_line.rb} +2 -2
- data/test/google_chart/{test_legends.rb → test_legend.rb} +2 -2
- data/test/google_chart/test_line_chart.rb +51 -0
- data/test/google_chart/{test_line_styles.rb → test_line_style.rb} +2 -2
- data/test/google_chart/{test_range_markers.rb → test_range_marker.rb} +2 -2
- data/test/google_chart/{test_titles.rb → test_title.rb} +2 -2
- data/test/test_google_chart.rb +8 -2
- data/test/test_helper.rb +1 -1
- metadata +23 -25
- data/lib/google_chart/bar.rb +0 -27
- data/lib/google_chart/bar_styles.rb +0 -25
- data/lib/google_chart/sizes.rb +0 -16
- data/test/google_chart/test_bar.rb +0 -55
- data/test/google_chart/test_line.rb +0 -55
- data/test/google_chart/test_sizes.rb +0 -15
@@ -1,16 +1,28 @@
|
|
1
1
|
module GoogleChart
|
2
|
-
class
|
3
|
-
@@base_url
|
2
|
+
class AbstractChart
|
3
|
+
@@base_url = 'http://chart.apis.google.com/chart'
|
4
|
+
@@default_size = '600x500'
|
4
5
|
|
5
6
|
def initialize(options = {})
|
6
7
|
options.each {|key, value| send("#{key}=", value) }
|
7
8
|
yield self if block_given?
|
8
9
|
end
|
9
10
|
|
11
|
+
def to_url
|
12
|
+
"#{@@base_url}?#{query_string}"
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_writer :size
|
16
|
+
|
17
|
+
def size
|
18
|
+
@size ||= @@default_size
|
19
|
+
"chs=#{@size}"
|
20
|
+
end
|
21
|
+
|
10
22
|
def self.inherited(klass)
|
11
23
|
klass.class_eval do
|
12
24
|
class_variable_set(:@@parameters, [])
|
13
|
-
register!(:chart_type)
|
25
|
+
register!(:chart_type, :size)
|
14
26
|
end
|
15
27
|
end
|
16
28
|
|
@@ -28,12 +40,6 @@ module GoogleChart
|
|
28
40
|
class_variable_get :@@parameters
|
29
41
|
end
|
30
42
|
|
31
|
-
# Collect all of the registered chart parameters and join them together
|
32
|
-
# to form the URL for the chart to be generated.
|
33
|
-
def to_url
|
34
|
-
"#{@@base_url}?#{query_string}"
|
35
|
-
end
|
36
|
-
|
37
43
|
private
|
38
44
|
def query_string
|
39
45
|
self.class.registry.map {|m| send(m) }.compact.join('&')
|
@@ -1,22 +1,12 @@
|
|
1
1
|
# <URL:http://code.google.com/apis/chart/#multiple_axes_labels>
|
2
2
|
module GoogleChart
|
3
|
-
module
|
3
|
+
module Axis
|
4
4
|
def self.included(klass)
|
5
5
|
klass.register!(:axes)
|
6
6
|
end
|
7
7
|
|
8
8
|
# TODO: Add support for axis label positions/styles, support for multiple label sets per axis
|
9
9
|
|
10
|
-
def axes
|
11
|
-
unless @axes.nil? || @axes.empty?
|
12
|
-
[
|
13
|
-
'chxt=' + @axes.join(','),
|
14
|
-
@axis_labels.empty? ? nil : 'chxl=' + @axis_labels.join('|'),
|
15
|
-
@axis_ranges.empty? ? nil : 'chxr=' + @axis_ranges.join('|')
|
16
|
-
].compact.join('&')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
10
|
def axes=(axes)
|
21
11
|
idx = 0
|
22
12
|
@axes, @axis_labels, @axis_ranges = [], [], []
|
@@ -36,5 +26,15 @@ module GoogleChart
|
|
36
26
|
end
|
37
27
|
end
|
38
28
|
end
|
29
|
+
|
30
|
+
def axes
|
31
|
+
unless @axes.nil? || @axes.empty?
|
32
|
+
[
|
33
|
+
'chxt=' + @axes.join(','),
|
34
|
+
@axis_labels.empty? ? nil : 'chxl=' + @axis_labels.join('|'),
|
35
|
+
@axis_ranges.empty? ? nil : 'chxr=' + @axis_ranges.join('|')
|
36
|
+
].compact.join('&')
|
37
|
+
end
|
38
|
+
end
|
39
39
|
end
|
40
40
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module GoogleChart
|
2
|
+
class BarChart < AbstractChart
|
3
|
+
include Axis
|
4
|
+
include BarStyle
|
5
|
+
include Color
|
6
|
+
include Data
|
7
|
+
include GridLine
|
8
|
+
include Legend
|
9
|
+
include RangeMarker
|
10
|
+
include Title
|
11
|
+
|
12
|
+
@@orientations = {:horizontal => 'h', :vertical => 'v'}
|
13
|
+
@@groupings = {:grouped => 'g', :stacked => 's'}
|
14
|
+
|
15
|
+
attr_writer :orientation, :grouping
|
16
|
+
|
17
|
+
def horizontal=(arg)
|
18
|
+
self.orientation = arg ? :horizontal : :vertical
|
19
|
+
end
|
20
|
+
|
21
|
+
def grouped=(arg)
|
22
|
+
self.grouping = arg ? :grouped : :stacked
|
23
|
+
end
|
24
|
+
|
25
|
+
def chart_type
|
26
|
+
@grouping ||= :stacked
|
27
|
+
@orientation ||= :vertical
|
28
|
+
"cht=b#{@@orientations[@orientation]}#{@@groupings[@grouping]}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# <URL:http://code.google.com/apis/chart/#bar_width>
|
2
|
+
module GoogleChart
|
3
|
+
module BarStyle
|
4
|
+
def self.included(klass)
|
5
|
+
klass.register!(:style)
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_writer :width
|
9
|
+
|
10
|
+
# TODO: raise error if bar spacing > group spacing?
|
11
|
+
def spacing=(spacing)
|
12
|
+
@spacing = [spacing].flatten
|
13
|
+
end
|
14
|
+
|
15
|
+
def style
|
16
|
+
"chbh=#{[@width, *@spacing].compact.join(',')}" if @width
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
# <URL:http://code.google.com/apis/chart/#line_bar_pie_colors>
|
2
2
|
module GoogleChart
|
3
|
-
module
|
3
|
+
module Color
|
4
4
|
def self.included(klass)
|
5
5
|
klass.register!(:color)
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
def color=(color)
|
9
|
+
@color = [color].flatten
|
10
|
+
end
|
9
11
|
|
10
12
|
def color
|
11
|
-
|
13
|
+
"chco=#{@color.join(',')}" if @color
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
data/lib/google_chart/data.rb
CHANGED
@@ -7,82 +7,77 @@ module GoogleChart
|
|
7
7
|
|
8
8
|
attr_writer :encoding, :scale
|
9
9
|
|
10
|
-
@@
|
11
|
-
|
12
|
-
@@
|
13
|
-
@@extended_alphabet.collect {|b| a + b }
|
14
|
-
}.flatten
|
10
|
+
@@simple = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
|
11
|
+
alphabet = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a + %w[- .]
|
12
|
+
@@extended = alphabet.map {|a| alphabet.map {|b| a + b }}.flatten
|
15
13
|
|
16
|
-
def data
|
17
|
-
|
14
|
+
def data=(data)
|
15
|
+
@data = data.any? {|e| Array === e } ? data : [data]
|
18
16
|
end
|
19
17
|
|
20
|
-
def data
|
21
|
-
|
18
|
+
def data
|
19
|
+
'chd=' + send(:"#{encoding}_encode", @data) if @data
|
22
20
|
end
|
23
21
|
|
24
22
|
private
|
25
23
|
def encoding
|
26
|
-
@encoding
|
24
|
+
@encoding ||= :simple
|
27
25
|
end
|
28
26
|
|
29
|
-
def scale
|
27
|
+
def scale
|
28
|
+
if @scale.nil?
|
29
|
+
min = [0, @data.map {|set| set.min }.min].min
|
30
|
+
max = @data.map {|set| set.max }.max
|
31
|
+
@scale = min..max
|
32
|
+
end
|
30
33
|
@scale
|
31
34
|
end
|
32
35
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
if min < 0
|
37
|
-
set.collect! {|n| n - min }
|
38
|
-
max -= min
|
39
|
-
end
|
40
|
-
set.collect {|n| (n * range).to_f / max if n }
|
41
|
-
else
|
42
|
-
set
|
43
|
-
end
|
36
|
+
def normalize(set, encoding_max)
|
37
|
+
min, max = scale.min, scale.max
|
38
|
+
set.map {|e| (e.to_f - min) / (max - min) * encoding_max if e }
|
44
39
|
end
|
45
40
|
|
46
41
|
def simple_encode(data)
|
47
|
-
's:' + data.
|
48
|
-
|
42
|
+
's:' + data.map {|set|
|
43
|
+
normalize(set, @@simple.size - 1).map {|e|
|
49
44
|
case
|
50
|
-
when
|
51
|
-
when
|
52
|
-
when
|
53
|
-
else @@
|
45
|
+
when e.nil? then '_'
|
46
|
+
when e <= 0 then @@simple[0]
|
47
|
+
when e >= @@simple.size then @@simple[-1]
|
48
|
+
else @@simple[e.round]
|
54
49
|
end
|
55
50
|
}.join
|
56
51
|
}.join(',')
|
57
52
|
end
|
58
53
|
|
59
54
|
def extended_encode(data)
|
60
|
-
'e:' + data.
|
61
|
-
|
55
|
+
'e:' + data.map {|set|
|
56
|
+
normalize(set, @@extended.size - 1).collect {|e|
|
62
57
|
case
|
63
|
-
when
|
64
|
-
when
|
65
|
-
when
|
66
|
-
else @@
|
58
|
+
when e.nil? then '__'
|
59
|
+
when e <= 0 then @@extended[0]
|
60
|
+
when e >= @@extended.size then @@extended[-1]
|
61
|
+
else @@extended[e.round]
|
67
62
|
end
|
68
63
|
}.join
|
69
64
|
}.join(',')
|
70
65
|
end
|
71
66
|
|
72
67
|
def text_encode(data)
|
73
|
-
't:' + data.
|
74
|
-
|
68
|
+
't:' + data.map {|set|
|
69
|
+
normalize(set, 100).map {|e|
|
75
70
|
case
|
76
|
-
when
|
77
|
-
when
|
78
|
-
when
|
71
|
+
when e.nil? then -1
|
72
|
+
when e < 0 then 0
|
73
|
+
when e > 100 then 100
|
79
74
|
else
|
80
75
|
# More than one decimal place yields negligible resolution at the
|
81
76
|
# potentially great cost of one extra character in the URL. Avoid
|
82
77
|
# this by rounding to the nearest tenth. Further round down to an
|
83
78
|
# integer when possible to save the extra two characters (".0").
|
84
|
-
|
85
|
-
|
79
|
+
n = (e * 10).round
|
80
|
+
n / (n % 10 == 0 ? 10 : 10.0)
|
86
81
|
end
|
87
82
|
}.join(',')
|
88
83
|
}.join('|')
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# <URL:http://code.google.com/apis/chart/#grid>
|
2
2
|
module GoogleChart
|
3
|
-
module
|
3
|
+
module GridLine
|
4
4
|
def self.included(klass)
|
5
5
|
klass.register!(:grid)
|
6
6
|
end
|
@@ -8,14 +8,14 @@ module GoogleChart
|
|
8
8
|
@@grid_line_styles = { :solid => [1,0], :dash => [3,2], :dot => [1,2] }
|
9
9
|
@@default_grid_step = 0
|
10
10
|
|
11
|
-
def grid
|
12
|
-
'chg=' + @grid if @grid
|
13
|
-
end
|
14
|
-
|
15
11
|
def grid=(grid)
|
16
12
|
grid[:x] ||= @@default_grid_step
|
17
13
|
grid[:y] ||= @@default_grid_step
|
18
14
|
@grid = [grid[:x], grid[:y], *@@grid_line_styles[grid[:style]]].compact.join(',')
|
19
15
|
end
|
16
|
+
|
17
|
+
def grid
|
18
|
+
"chg=#{@grid}" if @grid
|
19
|
+
end
|
20
20
|
end
|
21
21
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
# <URL:http://code.google.com/apis/chart/#chdl>
|
2
2
|
module GoogleChart
|
3
|
-
module
|
3
|
+
module Legend
|
4
4
|
def self.included(klass)
|
5
5
|
klass.register!(:legend)
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
def legend=(legend)
|
9
|
+
@legend = [legend].flatten.map {|l| CGI::escape(l) }
|
10
|
+
end
|
9
11
|
|
10
12
|
def legend
|
11
|
-
|
13
|
+
"chdl=#{@legend.join('|')}" if @legend
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -1,24 +1,24 @@
|
|
1
1
|
module GoogleChart
|
2
|
-
class
|
2
|
+
class LineChart < AbstractChart
|
3
3
|
@@chart_types = { :line => 'lc', :xy => 'lxy', :sparkline => 'ls' }
|
4
4
|
|
5
|
-
include
|
6
|
-
include
|
5
|
+
include Axis
|
6
|
+
include Color
|
7
7
|
include Data
|
8
|
-
include
|
9
|
-
include
|
10
|
-
include
|
11
|
-
include
|
12
|
-
include
|
13
|
-
include Titles
|
8
|
+
include GridLine
|
9
|
+
include Legend
|
10
|
+
include LineStyle
|
11
|
+
include RangeMarker
|
12
|
+
include Title
|
14
13
|
|
15
14
|
def chart_type
|
16
15
|
@chart_type ||= @@chart_types[:line]
|
17
16
|
'cht=' + @chart_type if @chart_type
|
18
17
|
end
|
19
18
|
|
20
|
-
def
|
19
|
+
def chart_type=(chart_type)
|
21
20
|
@chart_type = @@chart_types[chart_type]
|
22
21
|
end
|
22
|
+
alias_method :type=, :chart_type=
|
23
23
|
end
|
24
24
|
end
|
@@ -1,35 +1,36 @@
|
|
1
1
|
# <URL:http://code.google.com/apis/chart/#line_styles>
|
2
2
|
module GoogleChart
|
3
|
-
module
|
3
|
+
module LineStyle
|
4
4
|
def self.included(klass)
|
5
5
|
klass.register!(:style)
|
6
6
|
end
|
7
7
|
|
8
|
-
@@
|
9
|
-
|
10
|
-
@@
|
8
|
+
@@styles = { :solid => [1,1,0], :dash => [1,3,2], :dot => [1,1,2] }
|
9
|
+
|
10
|
+
@@default_style = :solid
|
11
|
+
@@default_width = 1
|
12
|
+
|
13
|
+
def style=(style)
|
14
|
+
@style = [style].flatten
|
15
|
+
end
|
16
|
+
|
17
|
+
def width=(width)
|
18
|
+
@width = [width].flatten
|
19
|
+
end
|
11
20
|
|
12
21
|
def style
|
13
22
|
@style ||= []
|
14
23
|
@width ||= []
|
15
24
|
|
16
25
|
# Pad @style and @width with defaults until they are equal in length
|
17
|
-
(@style.size - @width.size).times { @width << @@
|
18
|
-
(@width.size - @style.size).times { @style << @@
|
26
|
+
(@style.size - @width.size).times { @width << @@default_width }
|
27
|
+
(@width.size - @style.size).times { @style << @@default_style }
|
19
28
|
|
20
29
|
unless @style.empty?
|
21
|
-
'chls=' + (0...@style.size).
|
22
|
-
@@
|
30
|
+
'chls=' + (0...@style.size).map {|i|
|
31
|
+
@@styles[@style[i]].map {|n| n * @width[i] }.join(',')
|
23
32
|
}.join('|')
|
24
33
|
end
|
25
34
|
end
|
26
|
-
|
27
|
-
def style=(style)
|
28
|
-
@style = [style].flatten
|
29
|
-
end
|
30
|
-
|
31
|
-
def width=(width)
|
32
|
-
@width = [width].flatten
|
33
|
-
end
|
34
35
|
end
|
35
36
|
end
|
@@ -1,12 +1,16 @@
|
|
1
1
|
# <URL:http://code.google.com/apis/chart/#hor_line_marker>
|
2
2
|
module GoogleChart
|
3
|
-
module
|
3
|
+
module RangeMarker
|
4
4
|
def self.included(klass)
|
5
5
|
klass.register!(:ranges)
|
6
6
|
end
|
7
7
|
|
8
8
|
@@range_marker_orientations = { :h => 'r', :v => 'R' }
|
9
9
|
|
10
|
+
def ranges=(ranges)
|
11
|
+
@ranges = ranges.any? {|e| e.is_a?(Array) } ? ranges : [ranges]
|
12
|
+
end
|
13
|
+
|
10
14
|
def ranges
|
11
15
|
unless @ranges.nil? || @ranges.empty?
|
12
16
|
'chm=' + @ranges.collect {|r|
|
@@ -18,9 +22,5 @@ module GoogleChart
|
|
18
22
|
}.join('|')
|
19
23
|
end
|
20
24
|
end
|
21
|
-
|
22
|
-
def ranges=(ranges)
|
23
|
-
@ranges = ranges.any? {|e| e.is_a?(Array) } ? ranges : [ranges]
|
24
|
-
end
|
25
25
|
end
|
26
26
|
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require 'cgi'
|
2
|
-
|
3
1
|
# <URL:http://code.google.com/apis/chart/#chtt>
|
4
2
|
module GoogleChart
|
5
|
-
module
|
3
|
+
module Title
|
6
4
|
def self.included(klass)
|
7
5
|
klass.register!(:title)
|
8
6
|
end
|
9
7
|
|
10
|
-
|
8
|
+
def title=(title)
|
9
|
+
@title = CGI::escape(title)
|
10
|
+
end
|
11
11
|
|
12
12
|
def title
|
13
|
-
|
13
|
+
"chtt=#{@title}" if @title
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/google_chart.rb
CHANGED
@@ -1,29 +1,30 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
|
-
require '
|
5
|
-
|
6
|
-
require 'google_chart/
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
require 'google_chart/axis'
|
7
|
+
require 'google_chart/bar_style'
|
8
|
+
require 'google_chart/color'
|
7
9
|
require 'google_chart/data'
|
8
|
-
require 'google_chart/
|
9
|
-
require 'google_chart/
|
10
|
-
require 'google_chart/
|
11
|
-
require 'google_chart/
|
12
|
-
require 'google_chart/
|
13
|
-
require 'google_chart/titles'
|
10
|
+
require 'google_chart/grid_line'
|
11
|
+
require 'google_chart/legend'
|
12
|
+
require 'google_chart/line_style'
|
13
|
+
require 'google_chart/range_marker'
|
14
|
+
require 'google_chart/title'
|
14
15
|
|
15
|
-
require 'google_chart/
|
16
|
-
require 'google_chart/
|
17
|
-
require 'google_chart/
|
16
|
+
require 'google_chart/abstract_chart'
|
17
|
+
require 'google_chart/bar_chart'
|
18
|
+
require 'google_chart/line_chart'
|
18
19
|
|
19
20
|
module GoogleChart
|
20
|
-
VERSION = '0.
|
21
|
+
VERSION = '0.6.0'
|
21
22
|
|
22
23
|
def self.Line(options = {}, &block)
|
23
|
-
GoogleChart::
|
24
|
+
GoogleChart::LineChart.new(options, &block).to_url
|
24
25
|
end
|
25
26
|
|
26
27
|
def self.Bar(options = {}, &block)
|
27
|
-
GoogleChart::
|
28
|
+
GoogleChart::BarChart.new(options, &block).to_url
|
28
29
|
end
|
29
30
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestAbstractChart < Test::Unit::TestCase
|
4
4
|
should 'require descendent classes to define #chart_type method' do
|
5
|
-
klass = Class.new(GoogleChart::
|
5
|
+
klass = Class.new(GoogleChart::AbstractChart)
|
6
6
|
assert_raise(NoMethodError, /chart_type/) { klass.new.to_url }
|
7
7
|
|
8
8
|
klass.class_eval { def chart_type() end }
|
@@ -10,12 +10,20 @@ class TestBase < Test::Unit::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
should 'allow descendent classes to maintain distinct parameter registries' do
|
13
|
-
klass = Class.new(GoogleChart::
|
14
|
-
another_klass = Class.new(GoogleChart::
|
13
|
+
klass = Class.new(GoogleChart::AbstractChart)
|
14
|
+
another_klass = Class.new(GoogleChart::AbstractChart)
|
15
15
|
assert_not_same(another_klass.registry, klass.registry)
|
16
16
|
end
|
17
17
|
|
18
18
|
should 'begin URLs with Google Charts base URL' do
|
19
19
|
assert_match(%r{\Ahttp://chart\.apis\.google\.com/chart\?}, Class.new(MockChart).new.to_url)
|
20
20
|
end
|
21
|
+
|
22
|
+
should 'have a default chart size' do
|
23
|
+
assert_match(/\bchs=600x500\b/, Class.new(MockChart).new.to_url)
|
24
|
+
end
|
25
|
+
|
26
|
+
should 'accept custom chart sizes' do
|
27
|
+
assert_match(/\bchs=800x375\b/, Class.new(MockChart).new(:size => '800x375').to_url)
|
28
|
+
end
|
21
29
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestAxis < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
@klass = Class.new(MockChart).class_eval { include GoogleChart::
|
5
|
+
@klass = Class.new(MockChart).class_eval { include GoogleChart::Axis }
|
6
6
|
end
|
7
7
|
|
8
8
|
should 'not display axis parameter by default' do
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class TestBarChart < Test::Unit::TestCase
|
4
|
+
should 'have a default chart type' do
|
5
|
+
assert_match(/\bcht=bvs\b/, GoogleChart::BarChart.new.to_url)
|
6
|
+
end
|
7
|
+
|
8
|
+
should 'support horizontal orientation' do
|
9
|
+
assert_match(/\bcht=bhs\b/, GoogleChart::BarChart.new(:horizontal => true).to_url)
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'support grouped grouping' do
|
13
|
+
assert_match(/\bcht=bvg\b/, GoogleChart::BarChart.new(:grouped => true).to_url)
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'support horizontal orientation and grouped grouping' do
|
17
|
+
assert_match(/\bcht=bhg\b/, GoogleChart::BarChart.new(:horizontal => true, :grouped => true).to_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'include Axis module' do
|
21
|
+
assert GoogleChart::Axis === GoogleChart::BarChart.new
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'include BarStyle module' do
|
25
|
+
assert GoogleChart::BarStyle === GoogleChart::BarChart.new
|
26
|
+
end
|
27
|
+
|
28
|
+
should 'include Color module' do
|
29
|
+
assert GoogleChart::Color === GoogleChart::BarChart.new
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'include Data module' do
|
33
|
+
assert GoogleChart::Data === GoogleChart::BarChart.new
|
34
|
+
end
|
35
|
+
|
36
|
+
should 'include GridLine module' do
|
37
|
+
assert GoogleChart::GridLine === GoogleChart::BarChart.new
|
38
|
+
end
|
39
|
+
|
40
|
+
should 'include Legend module' do
|
41
|
+
assert GoogleChart::Legend === GoogleChart::BarChart.new
|
42
|
+
end
|
43
|
+
|
44
|
+
should 'include RangeMarker module' do
|
45
|
+
assert GoogleChart::RangeMarker === GoogleChart::BarChart.new
|
46
|
+
end
|
47
|
+
|
48
|
+
should 'include Title module' do
|
49
|
+
assert GoogleChart::Title === GoogleChart::BarChart.new
|
50
|
+
end
|
51
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestBarStyle < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
@klass = Class.new(MockChart).class_eval { include GoogleChart::
|
5
|
+
@klass = Class.new(MockChart).class_eval { include GoogleChart::BarStyle }
|
6
6
|
end
|
7
7
|
|
8
8
|
should 'not display bar style parameter by default' do
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestColor < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
@klass = Class.new(MockChart).class_eval { include GoogleChart::
|
5
|
+
@klass = Class.new(MockChart).class_eval { include GoogleChart::Color }
|
6
6
|
end
|
7
7
|
|
8
8
|
should 'not display color parameter by default' do
|
@@ -6,76 +6,123 @@ class TestData < Test::Unit::TestCase
|
|
6
6
|
end
|
7
7
|
|
8
8
|
should 'use simple encoding by default' do
|
9
|
-
assert_match(/\bchd=s:AB89\b/, @klass.new(:data => [0,1,60,61]).to_url)
|
9
|
+
assert_match(/\bchd=s:AB89\b/, @klass.new(:data => [0, 1, 60, 61]).to_url)
|
10
10
|
end
|
11
11
|
|
12
12
|
context 'simple encoding' do
|
13
|
-
|
14
|
-
|
13
|
+
setup { @chart = @klass.new(:encoding => :simple) }
|
14
|
+
|
15
|
+
should 'encode dataset with auto-scaling' do
|
16
|
+
@chart.data = [0, 15, 10]
|
17
|
+
assert_match(/\bchd=s:A9p\b/, @chart.to_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'encode dataset with manual scaling' do
|
21
|
+
@chart.data = [0, 15, 10]
|
22
|
+
@chart.scale = 0..20
|
23
|
+
assert_match(/\bchd=s:Auf\b/, @chart.to_url)
|
15
24
|
end
|
16
25
|
|
17
26
|
should 'encode multiple datasets' do
|
18
|
-
|
27
|
+
@chart.data = [[9, 15], [24, 7]]
|
28
|
+
@chart.scale = 0..61
|
29
|
+
assert_match(/\bchd=s:JP,YH\b/, @chart.to_url)
|
19
30
|
end
|
20
31
|
|
21
32
|
should 'encode missing data' do
|
22
|
-
|
33
|
+
@chart.data = [50, nil, 33]
|
34
|
+
@chart.scale = 0..61
|
35
|
+
assert_match(/\bchd=s:y_h\b/, @chart.to_url)
|
23
36
|
end
|
24
37
|
|
25
|
-
should 'encode
|
26
|
-
|
38
|
+
should 'encode out-of-bounds data' do
|
39
|
+
@chart.data = [62, 61, 60, 1, 0, -1]
|
40
|
+
@chart.scale = 0..61
|
41
|
+
assert_match(/\bchd=s:998BAA/, @chart.to_url)
|
27
42
|
end
|
28
43
|
|
29
|
-
should '
|
30
|
-
|
31
|
-
|
44
|
+
should 'encode floating point data' do
|
45
|
+
@chart.data = [49.5, 33.4]
|
46
|
+
@chart.scale = 0..61
|
47
|
+
assert_match(/\bchd=s:yh\b/, @chart.to_url)
|
48
|
+
end
|
32
49
|
end
|
33
50
|
|
34
51
|
context 'extended encoding' do
|
35
|
-
|
36
|
-
|
52
|
+
setup { @chart = @klass.new(:encoding => :extended) }
|
53
|
+
|
54
|
+
should 'encode dataset with auto-scaling' do
|
55
|
+
@chart.data = [0, 15, 10]
|
56
|
+
assert_match(/\bchd=e:AA\.\.qq\b/, @chart.to_url)
|
57
|
+
end
|
58
|
+
|
59
|
+
should 'encode dataset with manual scaling' do
|
60
|
+
@chart.data = [0, 15, 10]
|
61
|
+
@chart.scale = 0..20
|
62
|
+
assert_match(/\bchd=e:AAv\.gA\b/, @chart.to_url)
|
37
63
|
end
|
38
64
|
|
39
65
|
should 'encode multiple datasets' do
|
40
|
-
|
66
|
+
@chart.data = [[2281, 3233], [591, 1543]]
|
67
|
+
@chart.scale = 0..4095
|
68
|
+
assert_match(/\bchd=e:jpyh,JPYH\b/, @chart.to_url)
|
41
69
|
end
|
42
70
|
|
43
71
|
should 'encode missing data' do
|
44
|
-
|
72
|
+
@chart.data = [2281, nil, 3233]
|
73
|
+
@chart.scale = 0..4095
|
74
|
+
assert_match(/\bchd=e:jp__yh\b/, @chart.to_url)
|
45
75
|
end
|
46
76
|
|
47
|
-
should 'encode
|
48
|
-
|
77
|
+
should 'encode out-of-bounds data' do
|
78
|
+
@chart.data = [4096, 4095, 4094, 1, 0, -1]
|
79
|
+
@chart.scale = 0..4095
|
80
|
+
assert_match(/\bchd=e:\.\.\.\.\.-ABAAAA\b/, @chart.to_url)
|
49
81
|
end
|
50
82
|
|
51
|
-
should '
|
52
|
-
|
53
|
-
|
83
|
+
should 'encode floating point data' do
|
84
|
+
@chart.data = [2281.49, 3232.50]
|
85
|
+
@chart.scale = 0..4095
|
86
|
+
assert_match(/\bchd=e:jpyh\b/, @chart.to_url)
|
87
|
+
end
|
54
88
|
end
|
55
89
|
|
56
90
|
context 'text encoding' do
|
57
|
-
|
58
|
-
|
91
|
+
setup { @chart = @klass.new(:encoding => :text) }
|
92
|
+
|
93
|
+
should 'encode dataset with auto-scaling' do
|
94
|
+
@chart.data = [0, 15, 10]
|
95
|
+
assert_match(/\bchd=t:0,100,66.7\b/, @chart.to_url)
|
96
|
+
end
|
97
|
+
|
98
|
+
should 'encode dataset with manual scaling' do
|
99
|
+
@chart.data = [0, 15, 10]
|
100
|
+
@chart.scale = 0..20
|
101
|
+
assert_match(/\bchd=t:0,75,50\b/, @chart.to_url)
|
59
102
|
end
|
60
103
|
|
61
104
|
should 'encode multiple datasets' do
|
62
|
-
|
105
|
+
@chart.data = [[6, 14], [5, 23]]
|
106
|
+
@chart.scale = 0..100
|
107
|
+
assert_match(/\bchd=t:6,14\|5,23\b/, @chart.to_url)
|
63
108
|
end
|
64
109
|
|
65
110
|
should 'encode missing data' do
|
66
|
-
|
111
|
+
@chart.data = [6, nil, 14]
|
112
|
+
@chart.scale = 0..100
|
113
|
+
assert_match(/\bchd=t:6,-1,14\b/, @chart.to_url)
|
67
114
|
end
|
68
115
|
|
69
|
-
should '
|
70
|
-
|
116
|
+
should 'encode out-of-bounds data' do
|
117
|
+
@chart.data = [101, 100, 99, 1, 0, -1]
|
118
|
+
@chart.scale = 0..100
|
119
|
+
assert_match(/\bchd=t:100,100,99,1,0,0\b/, @chart.to_url)
|
71
120
|
end
|
72
121
|
|
73
|
-
should '
|
74
|
-
|
122
|
+
should 'rounds floating point data to the nearest tenth' do
|
123
|
+
@chart.data = [5.95, 14.01, 5.23]
|
124
|
+
@chart.scale = 0..100
|
125
|
+
assert_match(/\bchd=t:6,14,5.2\b/, @chart.to_url)
|
75
126
|
end
|
76
|
-
|
77
|
-
should 'scale data based on maximum value by default'
|
78
|
-
|
79
|
-
should 'scale data using custom scale'
|
80
127
|
end
|
81
128
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestGridLine < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
@klass = Class.new(MockChart).class_eval { include GoogleChart::
|
5
|
+
@klass = Class.new(MockChart).class_eval { include GoogleChart::GridLine }
|
6
6
|
end
|
7
7
|
|
8
8
|
should 'not display grid lines by default' do
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestLegend < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
@klass = Class.new(MockChart).class_eval { include GoogleChart::
|
5
|
+
@klass = Class.new(MockChart).class_eval { include GoogleChart::Legend }
|
6
6
|
end
|
7
7
|
|
8
8
|
should 'not display legend by default' do
|
@@ -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
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestLineStyle < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
@klass = Class.new(MockChart).class_eval { include GoogleChart::
|
5
|
+
@klass = Class.new(MockChart).class_eval { include GoogleChart::LineStyle }
|
6
6
|
end
|
7
7
|
|
8
8
|
should 'not include line styles by default' do
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestRangeMarker < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
@klass = Class.new(MockChart).class_eval { include GoogleChart::
|
5
|
+
@klass = Class.new(MockChart).class_eval { include GoogleChart::RangeMarker }
|
6
6
|
end
|
7
7
|
|
8
8
|
should 'not have range markers by default' do
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestTitle < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
@klass = Class.new(MockChart).class_eval { include GoogleChart::
|
5
|
+
@klass = Class.new(MockChart).class_eval { include GoogleChart::Title }
|
6
6
|
end
|
7
7
|
|
8
8
|
should 'not have a title by default' do
|
data/test/test_google_chart.rb
CHANGED
@@ -4,7 +4,7 @@ class TestGoogleChart < Test::Unit::TestCase
|
|
4
4
|
context '#Line' do
|
5
5
|
context 'with hash parameters' do
|
6
6
|
setup do
|
7
|
-
@url = GoogleChart.Line(:size => '1000x300', :data => [[35, 41], [50, 33]])
|
7
|
+
@url = GoogleChart.Line(:size => '1000x300', :data => [[35, 41], [50, 33]], :scale => 0..61)
|
8
8
|
end
|
9
9
|
|
10
10
|
should 'return Google Chart URL' do
|
@@ -29,6 +29,7 @@ class TestGoogleChart < Test::Unit::TestCase
|
|
29
29
|
@url = GoogleChart.Line do |c|
|
30
30
|
c.size = '800x375'
|
31
31
|
c.data = [[35, 41], [50, 33]]
|
32
|
+
c.scale = 0..61
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
@@ -53,7 +54,7 @@ class TestGoogleChart < Test::Unit::TestCase
|
|
53
54
|
context '#Bar' do
|
54
55
|
context 'with hash parameters' do
|
55
56
|
setup do
|
56
|
-
@url = GoogleChart.Bar(:size => '1000x300', :data => [[35, 41], [50, 33]])
|
57
|
+
@url = GoogleChart.Bar(:size => '1000x300', :data => [[35, 41], [50, 33]], :scale => 0..61)
|
57
58
|
end
|
58
59
|
|
59
60
|
should 'return Google Chart URL' do
|
@@ -67,6 +68,10 @@ class TestGoogleChart < Test::Unit::TestCase
|
|
67
68
|
should 'include chart size parameter' do
|
68
69
|
assert_match(/\bchs=1000x300\b/, @url)
|
69
70
|
end
|
71
|
+
|
72
|
+
should 'include chart data parameter' do
|
73
|
+
assert_match(/\bchd=s:jp,yh\b/, @url)
|
74
|
+
end
|
70
75
|
end
|
71
76
|
|
72
77
|
context 'with block parameters' do
|
@@ -74,6 +79,7 @@ class TestGoogleChart < Test::Unit::TestCase
|
|
74
79
|
@url = GoogleChart.Bar do |c|
|
75
80
|
c.size = '800x375'
|
76
81
|
c.data = [[35, 41], [50, 33]]
|
82
|
+
c.scale = 0..61
|
77
83
|
end
|
78
84
|
end
|
79
85
|
|
data/test/test_helper.rb
CHANGED
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.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Parker
|
@@ -55,19 +55,18 @@ files:
|
|
55
55
|
- Rakefile
|
56
56
|
- README.txt
|
57
57
|
- lib/google_chart.rb
|
58
|
-
- lib/google_chart/
|
59
|
-
- lib/google_chart/
|
60
|
-
- lib/google_chart/
|
61
|
-
- lib/google_chart/
|
62
|
-
- lib/google_chart/
|
58
|
+
- lib/google_chart/abstract_chart.rb
|
59
|
+
- lib/google_chart/axis.rb
|
60
|
+
- lib/google_chart/bar_chart.rb
|
61
|
+
- lib/google_chart/bar_style.rb
|
62
|
+
- lib/google_chart/color.rb
|
63
63
|
- lib/google_chart/data.rb
|
64
|
-
- lib/google_chart/
|
65
|
-
- lib/google_chart/
|
66
|
-
- lib/google_chart/
|
67
|
-
- lib/google_chart/
|
68
|
-
- lib/google_chart/
|
69
|
-
- lib/google_chart/
|
70
|
-
- lib/google_chart/titles.rb
|
64
|
+
- lib/google_chart/grid_line.rb
|
65
|
+
- lib/google_chart/legend.rb
|
66
|
+
- lib/google_chart/line_chart.rb
|
67
|
+
- lib/google_chart/line_style.rb
|
68
|
+
- lib/google_chart/range_marker.rb
|
69
|
+
- lib/google_chart/title.rb
|
71
70
|
has_rdoc: false
|
72
71
|
homepage: http://github.com/jparker/ruby-googlechart
|
73
72
|
post_install_message:
|
@@ -98,16 +97,15 @@ summary: Ruby wrapper for the Google Charts API
|
|
98
97
|
test_files:
|
99
98
|
- test/test_helper.rb
|
100
99
|
- test/test_google_chart.rb
|
101
|
-
- test/google_chart/
|
102
|
-
- test/google_chart/
|
103
|
-
- test/google_chart/
|
104
|
-
- test/google_chart/
|
105
|
-
- test/google_chart/
|
100
|
+
- test/google_chart/test_abstract_chart.rb
|
101
|
+
- test/google_chart/test_axis.rb
|
102
|
+
- test/google_chart/test_bar_chart.rb
|
103
|
+
- test/google_chart/test_bar_style.rb
|
104
|
+
- test/google_chart/test_color.rb
|
106
105
|
- test/google_chart/test_data.rb
|
107
|
-
- test/google_chart/
|
108
|
-
- test/google_chart/
|
109
|
-
- test/google_chart/
|
110
|
-
- test/google_chart/
|
111
|
-
- test/google_chart/
|
112
|
-
- test/google_chart/
|
113
|
-
- test/google_chart/test_titles.rb
|
106
|
+
- test/google_chart/test_grid_line.rb
|
107
|
+
- test/google_chart/test_legend.rb
|
108
|
+
- test/google_chart/test_line_chart.rb
|
109
|
+
- test/google_chart/test_line_style.rb
|
110
|
+
- test/google_chart/test_range_marker.rb
|
111
|
+
- test/google_chart/test_title.rb
|
data/lib/google_chart/bar.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module GoogleChart
|
2
|
-
class Bar < Base
|
3
|
-
include Axes
|
4
|
-
include BarStyles
|
5
|
-
include Colors
|
6
|
-
include Data
|
7
|
-
include GridLines
|
8
|
-
include Legends
|
9
|
-
include RangeMarkers
|
10
|
-
include Sizes
|
11
|
-
include Titles
|
12
|
-
|
13
|
-
attr_writer :horizontal, :grouped
|
14
|
-
|
15
|
-
def chart_type
|
16
|
-
'cht=b' + (horizontal? ? 'h' : 'v') + (grouped? ? 'g' : 's')
|
17
|
-
end
|
18
|
-
|
19
|
-
def horizontal?
|
20
|
-
@horizontal
|
21
|
-
end
|
22
|
-
|
23
|
-
def grouped?
|
24
|
-
@grouped
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# <URL:http://code.google.com/apis/chart/#bar_width>
|
2
|
-
module GoogleChart
|
3
|
-
module BarStyles
|
4
|
-
def self.included(klass)
|
5
|
-
klass.register!(:style)
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_writer :width
|
9
|
-
|
10
|
-
def style
|
11
|
-
"chbh=#{[@width, *@spacing].compact.join(',')}" if @width
|
12
|
-
end
|
13
|
-
|
14
|
-
# Spacing can be given as a single number for space between bars within a
|
15
|
-
# group or as an array of numbers with the first element as the space
|
16
|
-
# between bars within a group and the second element as the space between
|
17
|
-
# groups. If not provided, the default spacing between groups is 8 pixels.
|
18
|
-
#
|
19
|
-
# TODO: Should we raise an error if bar spacing is greater than group
|
20
|
-
# spacing? This would visually group bars from different groups.
|
21
|
-
def spacing=(spacing)
|
22
|
-
@spacing = [spacing].flatten
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/lib/google_chart/sizes.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# <URL:http://code.google.com/apis/chart/#chart_size>
|
2
|
-
module GoogleChart
|
3
|
-
module Sizes
|
4
|
-
def self.included(klass)
|
5
|
-
klass.register!(:size)
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_writer :size
|
9
|
-
|
10
|
-
@@default_size = '600x500'
|
11
|
-
|
12
|
-
def size
|
13
|
-
'chs=' + (@size ? @size : @@default_size)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
-
|
3
|
-
class TestBar < Test::Unit::TestCase
|
4
|
-
should 'have a default chart type' do
|
5
|
-
assert_match(/\bcht=bvs\b/, GoogleChart::Bar.new.to_url)
|
6
|
-
end
|
7
|
-
|
8
|
-
should 'support horizontal orientation' do
|
9
|
-
assert_match(/\bcht=bhs\b/, GoogleChart::Bar.new(:horizontal => true).to_url)
|
10
|
-
end
|
11
|
-
|
12
|
-
should 'support grouped grouping' do
|
13
|
-
assert_match(/\bcht=bvg\b/, GoogleChart::Bar.new(:grouped => true).to_url)
|
14
|
-
end
|
15
|
-
|
16
|
-
should 'support horizontal orientation and grouped grouping' do
|
17
|
-
assert_match(/\bcht=bhg\b/, GoogleChart::Bar.new(:horizontal => true, :grouped => true).to_url)
|
18
|
-
end
|
19
|
-
|
20
|
-
should 'include Axes module' do
|
21
|
-
assert GoogleChart::Axes === GoogleChart::Bar.new
|
22
|
-
end
|
23
|
-
|
24
|
-
should 'include BarStyles module' do
|
25
|
-
assert GoogleChart::BarStyles === GoogleChart::Bar.new
|
26
|
-
end
|
27
|
-
|
28
|
-
should 'include Colors module' do
|
29
|
-
assert GoogleChart::Colors === GoogleChart::Bar.new
|
30
|
-
end
|
31
|
-
|
32
|
-
should 'include Data module' do
|
33
|
-
assert GoogleChart::Data === GoogleChart::Bar.new
|
34
|
-
end
|
35
|
-
|
36
|
-
should 'include GridLines module' do
|
37
|
-
assert GoogleChart::GridLines === GoogleChart::Bar.new
|
38
|
-
end
|
39
|
-
|
40
|
-
should 'include Legends module' do
|
41
|
-
assert GoogleChart::Legends === GoogleChart::Bar.new
|
42
|
-
end
|
43
|
-
|
44
|
-
should 'include RangeMarkers module' do
|
45
|
-
assert GoogleChart::RangeMarkers === GoogleChart::Bar.new
|
46
|
-
end
|
47
|
-
|
48
|
-
should 'include Sizes module' do
|
49
|
-
assert GoogleChart::Sizes === GoogleChart::Bar.new
|
50
|
-
end
|
51
|
-
|
52
|
-
should 'include Titles module' do
|
53
|
-
assert GoogleChart::Titles === GoogleChart::Bar.new
|
54
|
-
end
|
55
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
-
|
3
|
-
class TestLine < Test::Unit::TestCase
|
4
|
-
should 'have a default chart type' do
|
5
|
-
assert_match(/\bcht=lc\b/, GoogleChart::Line.new.to_url)
|
6
|
-
end
|
7
|
-
|
8
|
-
should 'support xy chart type' do
|
9
|
-
assert_match(/\bcht=lxy\b/, GoogleChart::Line.new(:type => :xy).to_url)
|
10
|
-
end
|
11
|
-
|
12
|
-
should 'support sparkline chart type' do
|
13
|
-
assert_match(/\bcht=ls\b/, GoogleChart::Line.new(:type => :sparkline).to_url)
|
14
|
-
end
|
15
|
-
|
16
|
-
should 'support line as chart type' do
|
17
|
-
assert_match(/\bcht=lc\b/, GoogleChart::Line.new(:type => :line).to_url)
|
18
|
-
end
|
19
|
-
|
20
|
-
should 'include Axes module' do
|
21
|
-
assert GoogleChart::Axes === GoogleChart::Line.new
|
22
|
-
end
|
23
|
-
|
24
|
-
should 'include Colors module' do
|
25
|
-
assert GoogleChart::Colors === GoogleChart::Line.new
|
26
|
-
end
|
27
|
-
|
28
|
-
should 'include Data module' do
|
29
|
-
assert GoogleChart::Data === GoogleChart::Line.new
|
30
|
-
end
|
31
|
-
|
32
|
-
should 'include GridLines module' do
|
33
|
-
assert GoogleChart::GridLines === GoogleChart::Line.new
|
34
|
-
end
|
35
|
-
|
36
|
-
should 'include Legends module' do
|
37
|
-
assert GoogleChart::Legends === GoogleChart::Line.new
|
38
|
-
end
|
39
|
-
|
40
|
-
should 'include LineStyles module' do
|
41
|
-
assert GoogleChart::LineStyles === GoogleChart::Line.new
|
42
|
-
end
|
43
|
-
|
44
|
-
should 'include RangeMarkers module' do
|
45
|
-
assert GoogleChart::RangeMarkers === GoogleChart::Line.new
|
46
|
-
end
|
47
|
-
|
48
|
-
should 'include Sizes module' do
|
49
|
-
assert GoogleChart::Sizes === GoogleChart::Line.new
|
50
|
-
end
|
51
|
-
|
52
|
-
should 'include Titles module' do
|
53
|
-
assert GoogleChart::Titles === GoogleChart::Line.new
|
54
|
-
end
|
55
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
-
|
3
|
-
class TestSizes < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@klass = Class.new(MockChart).class_eval { include GoogleChart::Sizes }
|
6
|
-
end
|
7
|
-
|
8
|
-
should 'have a default size' do
|
9
|
-
assert_match(/\bchs=600x500\b/, @klass.new.to_url)
|
10
|
-
end
|
11
|
-
|
12
|
-
should 'accept custom size' do
|
13
|
-
assert_match(/\bchs=800x375\b/, @klass.new(:size => '800x375').to_url)
|
14
|
-
end
|
15
|
-
end
|