seer 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CONTRIBUTORS +4 -0
- data/README.rdoc +3 -1
- data/Rakefile +1 -0
- data/lib/seer/area_chart.rb +12 -6
- data/lib/seer/bar_chart.rb +2 -2
- data/lib/seer/chart.rb +5 -3
- data/lib/seer/column_chart.rb +2 -2
- data/lib/seer/gauge.rb +2 -2
- data/lib/seer/line_chart.rb +10 -4
- data/lib/seer/pie_chart.rb +2 -2
- data/spec/area_chart_spec.rb +69 -34
- data/spec/bar_chart_spec.rb +12 -26
- data/spec/chart_spec.rb +2 -3
- data/spec/column_chart_spec.rb +13 -27
- data/spec/custom_matchers.rb +23 -0
- data/spec/gauge_spec.rb +10 -8
- data/spec/helpers.rb +37 -0
- data/spec/line_chart_spec.rb +47 -34
- data/spec/pie_chart_spec.rb +13 -27
- data/spec/seer_spec.rb +6 -6
- data/spec/spec_helper.rb +5 -3
- metadata +5 -2
data/CONTRIBUTORS
ADDED
data/README.rdoc
CHANGED
@@ -20,7 +20,7 @@ In your controller:
|
|
20
20
|
|
21
21
|
In your view:
|
22
22
|
|
23
|
-
<div id="chart"
|
23
|
+
<div id="chart"></div>
|
24
24
|
|
25
25
|
<%= Seer::visualize(
|
26
26
|
@widgets,
|
@@ -44,6 +44,8 @@ In your view:
|
|
44
44
|
|
45
45
|
For examples of additional chart types, refer to the documentation for each of the individual chart objects, or see the blog post announcing Seer: {Simple, Semantic Graphing for Ruby on Rails with Seer}[http://www.idolhands.com/ruby-on-rails/gems-plugins-and-engines/graphing-for-ruby-on-rails-with-seer]
|
46
46
|
|
47
|
+
A {sample project}[http://github.com/Bantik/seer_sample] that demonstrates each of the chart types is available on GitHub.
|
48
|
+
|
47
49
|
Seer is developed and maintained by {Corey Ehmke}[http://www.idolhands.com/] at {SEO Logic}[http://www.seologic.com/].
|
48
50
|
|
49
51
|
Copyright (c) 2010 Corey Ehmke / SEO Logic, released under the MIT license
|
data/Rakefile
CHANGED
data/lib/seer/area_chart.rb
CHANGED
@@ -11,7 +11,7 @@ module Seer
|
|
11
11
|
#
|
12
12
|
# In your view:
|
13
13
|
#
|
14
|
-
# <div id="chart"
|
14
|
+
# <div id="chart"></div>
|
15
15
|
#
|
16
16
|
# <%= Seer::visualize(
|
17
17
|
# @data,
|
@@ -66,7 +66,7 @@ module Seer
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def data_columns #:nodoc:
|
69
|
-
_data_columns = " data.addRows(#{
|
69
|
+
_data_columns = " data.addRows(#{data_rows.size});\r"
|
70
70
|
_data_columns << " data.addColumn('string', 'Date');\r"
|
71
71
|
data.each do |datum|
|
72
72
|
_data_columns << " data.addColumn('number', '#{datum.send(series_label)}');\r"
|
@@ -75,20 +75,26 @@ module Seer
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def data_table #:nodoc:
|
78
|
-
_rows =
|
78
|
+
_rows = data_rows
|
79
79
|
_rows.each_with_index do |r,i|
|
80
80
|
@data_table << " data.setCell(#{i}, 0,'#{r}');\r"
|
81
81
|
end
|
82
82
|
data_series.each_with_index do |column,i|
|
83
83
|
column.each_with_index do |c,j|
|
84
|
-
@data_table << "data.setCell(#{j},#{i+1},#{c.send(data_method)});\r"
|
84
|
+
@data_table << " data.setCell(#{j},#{i+1},#{c.send(data_method)});\r"
|
85
85
|
end
|
86
86
|
end
|
87
87
|
@data_table
|
88
88
|
end
|
89
|
+
|
90
|
+
def data_rows
|
91
|
+
data_series.inject([]) do |rows, element|
|
92
|
+
rows |= element.map { |e| e.send(data_label) }
|
93
|
+
end
|
94
|
+
end
|
89
95
|
|
90
96
|
def nonstring_options #:nodoc:
|
91
|
-
[ :axis_font_size, :colors, :enable_tooltip, :height, :legend_font_size, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width]
|
97
|
+
[ :axis_font_size, :colors, :enable_tooltip, :height, :is_stacked, :legend_font_size, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width]
|
92
98
|
end
|
93
99
|
|
94
100
|
def string_options #:nodoc:
|
@@ -107,7 +113,7 @@ module Seer
|
|
107
113
|
#{data_table.to_s}
|
108
114
|
var options = {};
|
109
115
|
#{options}
|
110
|
-
var container = document.getElementById('
|
116
|
+
var container = document.getElementById('#{self.chart_element}');
|
111
117
|
var chart = new google.visualization.AreaChart(container);
|
112
118
|
chart.draw(data, options);
|
113
119
|
}
|
data/lib/seer/bar_chart.rb
CHANGED
@@ -9,7 +9,7 @@ module Seer
|
|
9
9
|
#
|
10
10
|
# In your view:
|
11
11
|
#
|
12
|
-
# <div id="chart"
|
12
|
+
# <div id="chart"></div>
|
13
13
|
#
|
14
14
|
# <%= Seer::visualize(
|
15
15
|
# @widgets,
|
@@ -100,7 +100,7 @@ module Seer
|
|
100
100
|
#{data_table.to_s}
|
101
101
|
var options = {};
|
102
102
|
#{options}
|
103
|
-
var container = document.getElementById('
|
103
|
+
var container = document.getElementById('#{self.chart_element}');
|
104
104
|
var chart = new google.visualization.BarChart(container);
|
105
105
|
chart.draw(data, options);
|
106
106
|
}
|
data/lib/seer/chart.rb
CHANGED
@@ -41,14 +41,16 @@ module Seer
|
|
41
41
|
def options
|
42
42
|
_options = ""
|
43
43
|
nonstring_options.each do |opt|
|
44
|
+
next unless self.send(opt)
|
44
45
|
if opt == :colors
|
45
|
-
_options << " options['#{opt.to_s.camelize(:lower)}'] = #{self.send(:formatted_colors)};\r"
|
46
|
+
_options << " options['#{opt.to_s.camelize(:lower)}'] = #{self.send(:formatted_colors)};\r"
|
46
47
|
else
|
47
|
-
_options << " options['#{opt.to_s.camelize(:lower)}'] = #{self.send(opt)};\r"
|
48
|
+
_options << " options['#{opt.to_s.camelize(:lower)}'] = #{self.send(opt)};\r"
|
48
49
|
end
|
49
50
|
end
|
50
51
|
string_options.each do |opt|
|
51
|
-
|
52
|
+
next unless self.send(opt)
|
53
|
+
_options << " options['#{opt.to_s.camelize(:lower)}'] = '#{self.send(opt)}';\r"
|
52
54
|
end
|
53
55
|
_options
|
54
56
|
end
|
data/lib/seer/column_chart.rb
CHANGED
@@ -9,7 +9,7 @@ module Seer
|
|
9
9
|
#
|
10
10
|
# In your view:
|
11
11
|
#
|
12
|
-
# <div id="chart"
|
12
|
+
# <div id="chart"></div>
|
13
13
|
#
|
14
14
|
# <%= Seer::visualize(
|
15
15
|
# @widgets,
|
@@ -100,7 +100,7 @@ module Seer
|
|
100
100
|
#{data_table.to_s}
|
101
101
|
var options = {};
|
102
102
|
#{options}
|
103
|
-
var container = document.getElementById('
|
103
|
+
var container = document.getElementById('#{self.chart_element}');
|
104
104
|
var chart = new google.visualization.ColumnChart(container);
|
105
105
|
chart.draw(data, options);
|
106
106
|
}
|
data/lib/seer/gauge.rb
CHANGED
@@ -9,7 +9,7 @@ module Seer
|
|
9
9
|
#
|
10
10
|
# In your view:
|
11
11
|
#
|
12
|
-
# <div id="chart"
|
12
|
+
# <div id="chart"></div>
|
13
13
|
#
|
14
14
|
# <%= Seer::visualize(
|
15
15
|
# @data,
|
@@ -92,7 +92,7 @@ module Seer
|
|
92
92
|
function drawChart() {
|
93
93
|
var data = new google.visualization.DataTable();
|
94
94
|
#{data_columns}
|
95
|
-
#{data_table.
|
95
|
+
#{data_table.join}
|
96
96
|
var options = {};
|
97
97
|
#{options}
|
98
98
|
var container = document.getElementById('#{self.chart_element}');
|
data/lib/seer/line_chart.rb
CHANGED
@@ -11,7 +11,7 @@ module Seer
|
|
11
11
|
#
|
12
12
|
# In your view:
|
13
13
|
#
|
14
|
-
# <div id="chart"
|
14
|
+
# <div id="chart"></div>
|
15
15
|
#
|
16
16
|
# <%= Seer::visualize(
|
17
17
|
# @data,
|
@@ -66,7 +66,7 @@ module Seer
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def data_columns #:nodoc:
|
69
|
-
_data_columns = " data.addRows(#{
|
69
|
+
_data_columns = " data.addRows(#{data_rows.size});\r"
|
70
70
|
_data_columns << " data.addColumn('string', 'Date');\r"
|
71
71
|
data.each do |datum|
|
72
72
|
_data_columns << " data.addColumn('number', '#{datum.send(series_label)}');\r"
|
@@ -75,7 +75,7 @@ module Seer
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def data_table #:nodoc:
|
78
|
-
_rows =
|
78
|
+
_rows = data_rows
|
79
79
|
_rows.each_with_index do |r,i|
|
80
80
|
@data_table << " data.setCell(#{i}, 0,'#{r}');\r"
|
81
81
|
end
|
@@ -86,6 +86,12 @@ module Seer
|
|
86
86
|
end
|
87
87
|
@data_table
|
88
88
|
end
|
89
|
+
|
90
|
+
def data_rows
|
91
|
+
data_series.inject([]) do |rows, element|
|
92
|
+
rows |= element.map { |e| e.send(data_label) }
|
93
|
+
end
|
94
|
+
end
|
89
95
|
|
90
96
|
def nonstring_options #:nodoc:
|
91
97
|
[ :axis_font_size, :colors, :enable_tooltip, :height, :legend_font_size, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :smooth_line, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width]
|
@@ -107,7 +113,7 @@ module Seer
|
|
107
113
|
#{data_table.to_s}
|
108
114
|
var options = {};
|
109
115
|
#{options}
|
110
|
-
var container = document.getElementById('
|
116
|
+
var container = document.getElementById('#{self.chart_element}');
|
111
117
|
var chart = new google.visualization.LineChart(container);
|
112
118
|
chart.draw(data, options);
|
113
119
|
}
|
data/lib/seer/pie_chart.rb
CHANGED
@@ -9,7 +9,7 @@ module Seer
|
|
9
9
|
#
|
10
10
|
# In your view:
|
11
11
|
#
|
12
|
-
# <div id="chart"
|
12
|
+
# <div id="chart"></div>
|
13
13
|
#
|
14
14
|
# <%= Seer::visualize(
|
15
15
|
# @data,
|
@@ -92,7 +92,7 @@ module Seer
|
|
92
92
|
#{data_table.to_s}
|
93
93
|
var options = {};
|
94
94
|
#{options}
|
95
|
-
var container = document.getElementById('
|
95
|
+
var container = document.getElementById('#{self.chart_element}');
|
96
96
|
var chart = new google.visualization.PieChart(container);
|
97
97
|
chart.draw(data, options);
|
98
98
|
}
|
data/spec/area_chart_spec.rb
CHANGED
@@ -14,34 +14,20 @@ describe "Seer::AreaChart" do
|
|
14
14
|
)
|
15
15
|
end
|
16
16
|
|
17
|
-
describe 'defaults' do
|
18
|
-
|
19
|
-
it 'colors' do
|
20
|
-
@chart.colors.should == Seer::Chart::DEFAULT_COLORS
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'legend' do
|
24
|
-
@chart.legend.should == Seer::Chart::DEFAULT_LEGEND_LOCATION
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'height' do
|
28
|
-
@chart.height.should == Seer::Chart::DEFAULT_HEIGHT
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'width' do
|
32
|
-
@chart.width.should == Seer::Chart::DEFAULT_WIDTH
|
33
|
-
end
|
34
|
-
|
17
|
+
describe 'defaults' do
|
18
|
+
it_should_behave_like 'it sets default values'
|
35
19
|
end
|
36
20
|
|
37
21
|
describe 'graph options' do
|
38
22
|
|
39
|
-
[:axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :
|
23
|
+
[:axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :is_stacked, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :number, :tooltip_width, :width].each do |accessor|
|
40
24
|
it "sets its #{accessor} value" do
|
41
25
|
@chart.send("#{accessor}=", 'foo')
|
42
26
|
@chart.send(accessor).should == 'foo'
|
43
27
|
end
|
44
28
|
end
|
29
|
+
|
30
|
+
it_should_behave_like 'it has colors attribute'
|
45
31
|
end
|
46
32
|
|
47
33
|
it 'renders as JavaScript' do
|
@@ -50,24 +36,73 @@ describe "Seer::AreaChart" do
|
|
50
36
|
end
|
51
37
|
|
52
38
|
it 'sets its data columns' do
|
53
|
-
@chart.data_columns.should =~ /addRows\(
|
54
|
-
@chart.data_columns.should
|
55
|
-
@chart.data_columns.should
|
56
|
-
@chart.data_columns.should
|
57
|
-
@chart.data_columns.should
|
58
|
-
@chart.data_columns.should
|
59
|
-
@chart.data_columns.should =~ /addColumn\('number', '3'\)/
|
39
|
+
@chart.data_columns.should =~ /addRows\(5\)/
|
40
|
+
@chart.data_columns.should add_column('string', 'Date')
|
41
|
+
@chart.data_columns.should add_column('number', '0')
|
42
|
+
@chart.data_columns.should add_column('number', '1')
|
43
|
+
@chart.data_columns.should add_column('number', '2')
|
44
|
+
@chart.data_columns.should add_column('number', '3')
|
60
45
|
end
|
61
46
|
|
62
47
|
it 'sets its data table' do
|
63
|
-
@chart.data_table.to_s.should
|
64
|
-
@chart.data_table.to_s.should
|
65
|
-
@chart.data_table.to_s.should
|
66
|
-
@chart.data_table.to_s.should
|
67
|
-
@chart.data_table.to_s.should
|
68
|
-
@chart.data_table.to_s.should
|
69
|
-
@chart.data_table.to_s.should
|
70
|
-
@chart.data_table.to_s.should
|
48
|
+
@chart.data_table.to_s.should set_cell(0, 0,'1')
|
49
|
+
@chart.data_table.to_s.should set_cell(1, 0,'2')
|
50
|
+
@chart.data_table.to_s.should set_cell(2, 0,'3')
|
51
|
+
@chart.data_table.to_s.should set_cell(3, 0,'4')
|
52
|
+
@chart.data_table.to_s.should set_cell(4, 0,'5')
|
53
|
+
@chart.data_table.to_s.should set_cell(0,1,8)
|
54
|
+
@chart.data_table.to_s.should set_cell(2,1,8)
|
55
|
+
@chart.data_table.to_s.should set_cell(0,2,8)
|
56
|
+
@chart.data_table.to_s.should set_cell(1,2,8)
|
57
|
+
@chart.data_table.to_s.should set_cell(2,2,8)
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'when data_series is an array of arrays of arrays/hashes' do
|
61
|
+
before(:each) do
|
62
|
+
data_series = Array.new(3) {|i| [[i, i+1], [i+1, i+2]]}
|
63
|
+
@chart = Seer::AreaChart.new(
|
64
|
+
:data => [0,1,2,3],
|
65
|
+
:series_label => 'to_s',
|
66
|
+
:data_series => data_series,
|
67
|
+
:data_label => 'first',
|
68
|
+
:data_method => 'size',
|
69
|
+
:chart_options => {},
|
70
|
+
:chart_element => 'chart'
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'calculates number of rows' do
|
75
|
+
@chart.data_columns.should =~ /addRows\(4\)/
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'sets its data table' do
|
79
|
+
@chart.data_table.to_s.should set_cell(0, 0,'0')
|
80
|
+
@chart.data_table.to_s.should set_cell(1, 0,'1')
|
81
|
+
@chart.data_table.to_s.should set_cell(2, 0,'2')
|
82
|
+
@chart.data_table.to_s.should set_cell(3, 0,'3')
|
83
|
+
end
|
71
84
|
end
|
72
85
|
|
86
|
+
describe 'should receive options' do
|
87
|
+
before(:each) do
|
88
|
+
data_series = Array.new(3) {|i| [[i, i+1], [i+1, i+2]]}
|
89
|
+
@options = {
|
90
|
+
:data => [0,1,2,3],
|
91
|
+
:series_label => 'to_s',
|
92
|
+
:data_series => data_series,
|
93
|
+
:data_label => 'first',
|
94
|
+
:data_method => 'size',
|
95
|
+
:chart_options => {},
|
96
|
+
:chart_element => 'chart'
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should receive :is_stacked option' do
|
101
|
+
create_chart_with_option(:is_stacked => true).to_js.should =~ /options\['isStacked'\] = true/
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def create_chart_with_option(option)
|
107
|
+
Seer::AreaChart.new(@options.merge(option))
|
73
108
|
end
|
data/spec/bar_chart_spec.rb
CHANGED
@@ -13,33 +13,19 @@ describe "Seer::BarChart" do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
describe 'defaults' do
|
16
|
-
|
17
|
-
it 'colors' do
|
18
|
-
@chart.colors.should == Seer::Chart::DEFAULT_COLORS
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'legend' do
|
22
|
-
@chart.legend.should == Seer::Chart::DEFAULT_LEGEND_LOCATION
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'height' do
|
26
|
-
@chart.height.should == Seer::Chart::DEFAULT_HEIGHT
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'width' do
|
30
|
-
@chart.width.should == Seer::Chart::DEFAULT_WIDTH
|
31
|
-
end
|
32
|
-
|
16
|
+
it_should_behave_like 'it sets default values'
|
33
17
|
end
|
34
18
|
|
35
19
|
describe 'graph options' do
|
36
20
|
|
37
|
-
[:axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :
|
21
|
+
[:axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :is_3_d, :is_stacked, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :log_scale, :max, :min, :reverse_axis, :show_categories, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width].each do |accessor|
|
38
22
|
it "sets its #{accessor} value" do
|
39
23
|
@chart.send("#{accessor}=", 'foo')
|
40
24
|
@chart.send(accessor).should == 'foo'
|
41
25
|
end
|
42
26
|
end
|
27
|
+
|
28
|
+
it_should_behave_like 'it has colors attribute'
|
43
29
|
end
|
44
30
|
|
45
31
|
it 'renders as JavaScript' do
|
@@ -52,14 +38,14 @@ describe "Seer::BarChart" do
|
|
52
38
|
end
|
53
39
|
|
54
40
|
it 'sets its data table' do
|
55
|
-
@chart.data_table.to_s.should
|
56
|
-
@chart.data_table.to_s.should
|
57
|
-
@chart.data_table.to_s.should
|
58
|
-
@chart.data_table.to_s.should
|
59
|
-
@chart.data_table.to_s.should
|
60
|
-
@chart.data_table.to_s.should
|
61
|
-
@chart.data_table.to_s.should
|
62
|
-
@chart.data_table.to_s.should
|
41
|
+
@chart.data_table.to_s.should set_value(0, 0,'0')
|
42
|
+
@chart.data_table.to_s.should set_value(0, 1, 8)
|
43
|
+
@chart.data_table.to_s.should set_value(1, 0,'1')
|
44
|
+
@chart.data_table.to_s.should set_value(1, 1, 8)
|
45
|
+
@chart.data_table.to_s.should set_value(2, 0,'2')
|
46
|
+
@chart.data_table.to_s.should set_value(2, 1, 8)
|
47
|
+
@chart.data_table.to_s.should set_value(3, 0,'3')
|
48
|
+
@chart.data_table.to_s.should set_value(3, 1, 8)
|
63
49
|
end
|
64
50
|
|
65
51
|
end
|
data/spec/chart_spec.rb
CHANGED
@@ -46,8 +46,7 @@ describe "Seer::Chart" do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'sets its data columns' do
|
49
|
-
@chart.data_columns.should =~ /addRows\(
|
50
|
-
@chart.data_columns.should =~ /addColumn\('string', 'Date'\)/
|
49
|
+
@chart.data_columns.should =~ /addRows\(5\)/
|
51
50
|
@chart.data_columns.should =~ /addColumn\('string', 'Date'\)/
|
52
51
|
@chart.data_columns.should =~ /addColumn\('number', '0'\)/
|
53
52
|
@chart.data_columns.should =~ /addColumn\('number', '1'\)/
|
@@ -56,7 +55,7 @@ describe "Seer::Chart" do
|
|
56
55
|
end
|
57
56
|
|
58
57
|
it 'sets its options' do
|
59
|
-
|
58
|
+
@chart.options.should =~ /options\['titleX'\] = 'Something'/
|
60
59
|
end
|
61
60
|
|
62
61
|
|
data/spec/column_chart_spec.rb
CHANGED
@@ -12,34 +12,20 @@ describe "Seer::ColumnChart" do
|
|
12
12
|
)
|
13
13
|
end
|
14
14
|
|
15
|
-
describe 'defaults' do
|
16
|
-
|
17
|
-
it 'colors' do
|
18
|
-
@chart.colors.should == Seer::Chart::DEFAULT_COLORS
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'legend' do
|
22
|
-
@chart.legend.should == Seer::Chart::DEFAULT_LEGEND_LOCATION
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'height' do
|
26
|
-
@chart.height.should == Seer::Chart::DEFAULT_HEIGHT
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'width' do
|
30
|
-
@chart.width.should == Seer::Chart::DEFAULT_WIDTH
|
31
|
-
end
|
32
|
-
|
15
|
+
describe 'defaults' do
|
16
|
+
it_should_behave_like 'it sets default values'
|
33
17
|
end
|
34
18
|
|
35
19
|
describe 'graph options' do
|
36
20
|
|
37
|
-
[:axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :
|
21
|
+
[:axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :is_3_d, :is_stacked, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :log_scale, :max, :min, :reverse_axis, :show_categories, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width].each do |accessor|
|
38
22
|
it "sets its #{accessor} value" do
|
39
23
|
@chart.send("#{accessor}=", 'foo')
|
40
24
|
@chart.send(accessor).should == 'foo'
|
41
25
|
end
|
42
26
|
end
|
27
|
+
|
28
|
+
it_should_behave_like 'it has colors attribute'
|
43
29
|
end
|
44
30
|
|
45
31
|
it 'renders as JavaScript' do
|
@@ -52,14 +38,14 @@ describe "Seer::ColumnChart" do
|
|
52
38
|
end
|
53
39
|
|
54
40
|
it 'sets its data table' do
|
55
|
-
@chart.data_table.to_s.should
|
56
|
-
@chart.data_table.to_s.should
|
57
|
-
@chart.data_table.to_s.should
|
58
|
-
@chart.data_table.to_s.should
|
59
|
-
@chart.data_table.to_s.should
|
60
|
-
@chart.data_table.to_s.should
|
61
|
-
@chart.data_table.to_s.should
|
62
|
-
@chart.data_table.to_s.should
|
41
|
+
@chart.data_table.to_s.should set_value(0, 0,'0')
|
42
|
+
@chart.data_table.to_s.should set_value(0, 1, 8)
|
43
|
+
@chart.data_table.to_s.should set_value(1, 0,'1')
|
44
|
+
@chart.data_table.to_s.should set_value(1, 1, 8)
|
45
|
+
@chart.data_table.to_s.should set_value(2, 0,'2')
|
46
|
+
@chart.data_table.to_s.should set_value(2, 1, 8)
|
47
|
+
@chart.data_table.to_s.should set_value(3, 0,'3')
|
48
|
+
@chart.data_table.to_s.should set_value(3, 1, 8)
|
63
49
|
end
|
64
50
|
|
65
51
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module CustomMatcher
|
2
|
+
def set_cell(row, column, value)
|
3
|
+
value = "'#{value}'" if value.is_a?(String)
|
4
|
+
|
5
|
+
simple_matcher("setCell(#{row}, #{column}, #{value})") do |actual|
|
6
|
+
actual =~ /data\.setCell\(#{row},\s*#{column},\s*#{value}\)/
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def set_value(row, column, value)
|
11
|
+
value = "'#{value}'" if value.is_a?(String)
|
12
|
+
|
13
|
+
simple_matcher("setValue(#{row}, #{column}, #{value})") do |actual|
|
14
|
+
actual =~ /data\.setValue\(#{row},\s*#{column},\s*#{value}\)/
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_column(column_type, value)
|
19
|
+
simple_matcher("addColumn('#{column_type}', '#{value}')") do |actual|
|
20
|
+
actual =~ /data\.addColumn\('#{column_type}',\s*'#{value}'\)/
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/gauge_spec.rb
CHANGED
@@ -32,6 +32,8 @@ describe "Seer::Gauge" do
|
|
32
32
|
@chart.send(accessor).should == 'foo'
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
it_should_behave_like 'it has colors attribute'
|
35
37
|
end
|
36
38
|
|
37
39
|
it 'renders as JavaScript' do
|
@@ -44,14 +46,14 @@ describe "Seer::Gauge" do
|
|
44
46
|
end
|
45
47
|
|
46
48
|
it 'sets its data table' do
|
47
|
-
@chart.data_table.to_s.should
|
48
|
-
@chart.data_table.to_s.should
|
49
|
-
@chart.data_table.to_s.should
|
50
|
-
@chart.data_table.to_s.should
|
51
|
-
@chart.data_table.to_s.should
|
52
|
-
@chart.data_table.to_s.should
|
53
|
-
@chart.data_table.to_s.should
|
54
|
-
@chart.data_table.to_s.should
|
49
|
+
@chart.data_table.to_s.should set_value(0, 0,'0')
|
50
|
+
@chart.data_table.to_s.should set_value(0, 1, 8)
|
51
|
+
@chart.data_table.to_s.should set_value(1, 0,'1')
|
52
|
+
@chart.data_table.to_s.should set_value(1, 1, 8)
|
53
|
+
@chart.data_table.to_s.should set_value(2, 0,'2')
|
54
|
+
@chart.data_table.to_s.should set_value(2, 1, 8)
|
55
|
+
@chart.data_table.to_s.should set_value(3, 0,'3')
|
56
|
+
@chart.data_table.to_s.should set_value(3, 1, 8)
|
55
57
|
end
|
56
58
|
|
57
59
|
end
|
data/spec/helpers.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
describe "it has colors attribute", :shared => true do
|
2
|
+
it 'sets its colors value' do
|
3
|
+
color_list = ['#7e7587','#990000','#009900', '#3e5643', '#660000', '#003300']
|
4
|
+
@chart.colors = color_list
|
5
|
+
@chart.colors.should == color_list
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'colors should be an array' do
|
9
|
+
lambda {
|
10
|
+
@chart.colors = '#000000'
|
11
|
+
}.should raise_error(ArgumentError)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'colors should be valid hex values' do
|
15
|
+
lambda {
|
16
|
+
@chart.colors = ['#000000', 'NOTHEX']
|
17
|
+
}.should raise_error(ArgumentError)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "it sets default values", :shared => true do
|
22
|
+
it 'colors' do
|
23
|
+
@chart.colors.should == Seer::Chart::DEFAULT_COLORS
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'legend' do
|
27
|
+
@chart.legend.should == Seer::Chart::DEFAULT_LEGEND_LOCATION
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'height' do
|
31
|
+
@chart.height.should == Seer::Chart::DEFAULT_HEIGHT
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'width' do
|
35
|
+
@chart.width.should == Seer::Chart::DEFAULT_WIDTH
|
36
|
+
end
|
37
|
+
end
|
data/spec/line_chart_spec.rb
CHANGED
@@ -14,34 +14,20 @@ describe "Seer::LineChart" do
|
|
14
14
|
)
|
15
15
|
end
|
16
16
|
|
17
|
-
describe 'defaults' do
|
18
|
-
|
19
|
-
it 'colors' do
|
20
|
-
@chart.colors.should == Seer::Chart::DEFAULT_COLORS
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'legend' do
|
24
|
-
@chart.legend.should == Seer::Chart::DEFAULT_LEGEND_LOCATION
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'height' do
|
28
|
-
@chart.height.should == Seer::Chart::DEFAULT_HEIGHT
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'width' do
|
32
|
-
@chart.width.should == Seer::Chart::DEFAULT_WIDTH
|
33
|
-
end
|
34
|
-
|
17
|
+
describe 'defaults' do
|
18
|
+
it_should_behave_like 'it sets default values'
|
35
19
|
end
|
36
20
|
|
37
21
|
describe 'graph options' do
|
38
22
|
|
39
|
-
[:axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :
|
23
|
+
[:axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :smooth_line, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :number, :tooltip_width, :width].each do |accessor|
|
40
24
|
it "sets its #{accessor} value" do
|
41
25
|
@chart.send("#{accessor}=", 'foo')
|
42
26
|
@chart.send(accessor).should == 'foo'
|
43
27
|
end
|
44
28
|
end
|
29
|
+
|
30
|
+
it_should_behave_like 'it has colors attribute'
|
45
31
|
end
|
46
32
|
|
47
33
|
it 'renders as JavaScript' do
|
@@ -50,24 +36,51 @@ describe "Seer::LineChart" do
|
|
50
36
|
end
|
51
37
|
|
52
38
|
it 'sets its data columns' do
|
53
|
-
@chart.data_columns.should =~ /addRows\(
|
54
|
-
@chart.data_columns.should
|
55
|
-
@chart.data_columns.should
|
56
|
-
@chart.data_columns.should
|
57
|
-
@chart.data_columns.should
|
58
|
-
@chart.data_columns.should
|
59
|
-
@chart.data_columns.should =~ /addColumn\('number', '3'\)/
|
39
|
+
@chart.data_columns.should =~ /addRows\(5\)/
|
40
|
+
@chart.data_columns.should add_column('string', 'Date')
|
41
|
+
@chart.data_columns.should add_column('number', '0')
|
42
|
+
@chart.data_columns.should add_column('number', '1')
|
43
|
+
@chart.data_columns.should add_column('number', '2')
|
44
|
+
@chart.data_columns.should add_column('number', '3')
|
60
45
|
end
|
61
46
|
|
62
47
|
it 'sets its data table' do
|
63
|
-
@chart.data_table.to_s.should
|
64
|
-
@chart.data_table.to_s.should
|
65
|
-
@chart.data_table.to_s.should
|
66
|
-
@chart.data_table.to_s.should
|
67
|
-
@chart.data_table.to_s.should
|
68
|
-
@chart.data_table.to_s.should
|
69
|
-
@chart.data_table.to_s.should
|
70
|
-
@chart.data_table.to_s.should
|
48
|
+
@chart.data_table.to_s.should set_cell(0, 0,'1')
|
49
|
+
@chart.data_table.to_s.should set_cell(1, 0,'2')
|
50
|
+
@chart.data_table.to_s.should set_cell(2, 0,'3')
|
51
|
+
@chart.data_table.to_s.should set_cell(3, 0,'4')
|
52
|
+
@chart.data_table.to_s.should set_cell(4, 0,'5')
|
53
|
+
@chart.data_table.to_s.should set_cell(0,1,8)
|
54
|
+
@chart.data_table.to_s.should set_cell(2,1,8)
|
55
|
+
@chart.data_table.to_s.should set_cell(0,2,8)
|
56
|
+
@chart.data_table.to_s.should set_cell(1,2,8)
|
57
|
+
@chart.data_table.to_s.should set_cell(2,2,8)
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'when data_series is an array of arrays of arrays/hashes' do
|
61
|
+
before(:each) do
|
62
|
+
data_series = Array.new(3) {|i| [[i, i+1], [i+1, i+2]]}
|
63
|
+
@chart = Seer::LineChart.new(
|
64
|
+
:data => [0,1,2,3],
|
65
|
+
:series_label => 'to_s',
|
66
|
+
:data_series => data_series,
|
67
|
+
:data_label => 'first',
|
68
|
+
:data_method => 'size',
|
69
|
+
:chart_options => {},
|
70
|
+
:chart_element => 'chart'
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'calculates number of rows' do
|
75
|
+
@chart.data_columns.should =~ /addRows\(4\)/
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'sets its data table' do
|
79
|
+
@chart.data_table.to_s.should set_cell(0, 0,'0')
|
80
|
+
@chart.data_table.to_s.should set_cell(1, 0,'1')
|
81
|
+
@chart.data_table.to_s.should set_cell(2, 0,'2')
|
82
|
+
@chart.data_table.to_s.should set_cell(3, 0,'3')
|
83
|
+
end
|
71
84
|
end
|
72
85
|
|
73
86
|
end
|
data/spec/pie_chart_spec.rb
CHANGED
@@ -12,34 +12,20 @@ describe "Seer::PieChart" do
|
|
12
12
|
)
|
13
13
|
end
|
14
14
|
|
15
|
-
describe 'defaults' do
|
16
|
-
|
17
|
-
it 'colors' do
|
18
|
-
@chart.colors.should == Seer::Chart::DEFAULT_COLORS
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'legend' do
|
22
|
-
@chart.legend.should == Seer::Chart::DEFAULT_LEGEND_LOCATION
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'height' do
|
26
|
-
@chart.height.should == Seer::Chart::DEFAULT_HEIGHT
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'width' do
|
30
|
-
@chart.width.should == Seer::Chart::DEFAULT_WIDTH
|
31
|
-
end
|
32
|
-
|
15
|
+
describe 'defaults' do
|
16
|
+
it_should_behave_like 'it sets default values'
|
33
17
|
end
|
34
18
|
|
35
19
|
describe 'graph options' do
|
36
20
|
|
37
|
-
[:background_color, :border_color, :
|
21
|
+
[:background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :is_3_d, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :pie_join_angle, :pie_minimal_angle, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width].each do |accessor|
|
38
22
|
it "sets its #{accessor} value" do
|
39
23
|
@chart.send("#{accessor}=", 'foo')
|
40
24
|
@chart.send(accessor).should == 'foo'
|
41
25
|
end
|
42
26
|
end
|
27
|
+
|
28
|
+
it_should_behave_like 'it has colors attribute'
|
43
29
|
end
|
44
30
|
|
45
31
|
it 'renders as JavaScript' do
|
@@ -52,14 +38,14 @@ describe "Seer::PieChart" do
|
|
52
38
|
end
|
53
39
|
|
54
40
|
it 'sets its data table' do
|
55
|
-
@chart.data_table.to_s.should
|
56
|
-
@chart.data_table.to_s.should
|
57
|
-
@chart.data_table.to_s.should
|
58
|
-
@chart.data_table.to_s.should
|
59
|
-
@chart.data_table.to_s.should
|
60
|
-
@chart.data_table.to_s.should
|
61
|
-
@chart.data_table.to_s.should
|
62
|
-
@chart.data_table.to_s.should
|
41
|
+
@chart.data_table.to_s.should set_value(0, 0,'0')
|
42
|
+
@chart.data_table.to_s.should set_value(0, 1, 8)
|
43
|
+
@chart.data_table.to_s.should set_value(1, 0,'1')
|
44
|
+
@chart.data_table.to_s.should set_value(1, 1, 8)
|
45
|
+
@chart.data_table.to_s.should set_value(2, 0,'2')
|
46
|
+
@chart.data_table.to_s.should set_value(2, 1, 8)
|
47
|
+
@chart.data_table.to_s.should set_value(3, 0,'3')
|
48
|
+
@chart.data_table.to_s.should set_value(3, 1, 8)
|
63
49
|
end
|
64
50
|
|
65
51
|
end
|
data/spec/seer_spec.rb
CHANGED
@@ -68,8 +68,8 @@ describe "Seer" do
|
|
68
68
|
:as => :bar_chart,
|
69
69
|
:in_element => 'chart',
|
70
70
|
:series => {
|
71
|
-
:
|
72
|
-
:
|
71
|
+
:series_label => 'to_s',
|
72
|
+
:data_method => 'size'
|
73
73
|
},
|
74
74
|
:chart_options => {}
|
75
75
|
) =~ /barchart/).should be_true
|
@@ -81,8 +81,8 @@ describe "Seer" do
|
|
81
81
|
:as => :column_chart,
|
82
82
|
:in_element => 'chart',
|
83
83
|
:series => {
|
84
|
-
:
|
85
|
-
:
|
84
|
+
:series_label => 'to_s',
|
85
|
+
:data_method => 'size'
|
86
86
|
},
|
87
87
|
:chart_options => {}
|
88
88
|
) =~ /columnchart/).should be_true
|
@@ -94,8 +94,8 @@ describe "Seer" do
|
|
94
94
|
:as => :gauge,
|
95
95
|
:in_element => 'chart',
|
96
96
|
:series => {
|
97
|
-
:
|
98
|
-
:
|
97
|
+
:series_label => 'to_s',
|
98
|
+
:data_method => 'size'
|
99
99
|
},
|
100
100
|
:chart_options => {}
|
101
101
|
) =~ /gauge/).should be_true
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'rubygems'
|
3
4
|
require 'actionpack'
|
4
|
-
require '
|
5
|
+
require 'active_support'
|
5
6
|
require 'spec'
|
6
7
|
require 'spec/autorun'
|
7
8
|
require 'seer'
|
8
|
-
|
9
|
+
require File.dirname(__FILE__) + "/custom_matchers"
|
10
|
+
require File.dirname(__FILE__) + '/helpers'
|
9
11
|
Spec::Runner.configure do |config|
|
10
|
-
|
12
|
+
config.include(CustomMatcher)
|
11
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Ehmke / SEO Logic
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-03-03 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,6 +32,7 @@ extra_rdoc_files:
|
|
32
32
|
- LICENSE
|
33
33
|
- README.rdoc
|
34
34
|
files:
|
35
|
+
- CONTRIBUTORS
|
35
36
|
- LICENSE
|
36
37
|
- README.rdoc
|
37
38
|
- Rakefile
|
@@ -80,7 +81,9 @@ test_files:
|
|
80
81
|
- spec/bar_chart_spec.rb
|
81
82
|
- spec/chart_spec.rb
|
82
83
|
- spec/column_chart_spec.rb
|
84
|
+
- spec/custom_matchers.rb
|
83
85
|
- spec/gauge_spec.rb
|
86
|
+
- spec/helpers.rb
|
84
87
|
- spec/line_chart_spec.rb
|
85
88
|
- spec/pie_chart_spec.rb
|
86
89
|
- spec/seer_spec.rb
|