sylvaing-seer 0.7.1

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.
@@ -0,0 +1,108 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Seer::AreaChart" do
4
+
5
+ before :each do
6
+ @chart = Seer::AreaChart.new(
7
+ :data => [0,1,2,3],
8
+ :series_label => 'to_s',
9
+ :data_series => [[1,2,3],[3,4,5]],
10
+ :data_label => 'to_s',
11
+ :data_method => 'size',
12
+ :chart_options => {},
13
+ :chart_element => 'chart'
14
+ )
15
+ end
16
+
17
+ describe 'defaults' do
18
+ it_should_behave_like 'it sets default values'
19
+ end
20
+
21
+ describe 'graph options' do
22
+
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|
24
+ it "sets its #{accessor} value" do
25
+ @chart.send("#{accessor}=", 'foo')
26
+ @chart.send(accessor).should == 'foo'
27
+ end
28
+ end
29
+
30
+ it_should_behave_like 'it has colors attribute'
31
+ end
32
+
33
+ it 'renders as JavaScript' do
34
+ (@chart.to_js =~ /javascript/).should be_true
35
+ (@chart.to_js =~ /areachart/).should be_true
36
+ end
37
+
38
+ it 'sets its data columns' do
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')
45
+ end
46
+
47
+ it 'sets its data table' do
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
84
+ end
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))
108
+ end
@@ -0,0 +1,51 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Seer::BarChart" do
4
+
5
+ before :each do
6
+ @chart = Seer::BarChart.new(
7
+ :data => [0,1,2,3],
8
+ :label_method => 'to_s',
9
+ :data_method => 'size',
10
+ :chart_options => {},
11
+ :chart_element => 'chart'
12
+ )
13
+ end
14
+
15
+ describe 'defaults' do
16
+ it_should_behave_like 'it sets default values'
17
+ end
18
+
19
+ describe 'graph options' do
20
+
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|
22
+ it "sets its #{accessor} value" do
23
+ @chart.send("#{accessor}=", 'foo')
24
+ @chart.send(accessor).should == 'foo'
25
+ end
26
+ end
27
+
28
+ it_should_behave_like 'it has colors attribute'
29
+ end
30
+
31
+ it 'renders as JavaScript' do
32
+ (@chart.to_js =~ /javascript/).should be_true
33
+ (@chart.to_js =~ /barchart/).should be_true
34
+ end
35
+
36
+ it 'sets its data columns' do
37
+ @chart.data_columns.should =~ /addRows\(4\)/
38
+ end
39
+
40
+ it 'sets its data table' do
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)
49
+ end
50
+
51
+ end
@@ -0,0 +1,62 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Seer::Chart" do
4
+
5
+ before :all do
6
+ @chart = Seer::AreaChart.new(
7
+ :data => [0,1,2,3],
8
+ :series_label => 'to_s',
9
+ :data_series => [[1,2,3],[3,4,5]],
10
+ :data_label => 'to_s',
11
+ :data_method => 'size',
12
+ :chart_options => {
13
+ :legend => 'right',
14
+ :title_x => 'Something'
15
+ },
16
+ :chart_element => 'chart'
17
+ )
18
+ end
19
+
20
+ it 'sets the chart element' do
21
+ @chart.in_element = 'foo'
22
+ @chart.chart_element.should == 'foo'
23
+ end
24
+
25
+ describe 'sets colors' do
26
+
27
+ it 'accepting valid values' do
28
+ @chart.colors = ["#ff0000", "#00ff00"]
29
+ @chart.colors.should == ["#ff0000", "#00ff00"]
30
+ end
31
+
32
+ it 'raising an error on invalid values' do
33
+ lambda do
34
+ @chart.colors = 'fred'
35
+ end.should raise_error(ArgumentError)
36
+ lambda do
37
+ @chart.colors = [0,1,2]
38
+ end.should raise_error(ArgumentError)
39
+ end
40
+
41
+ end
42
+
43
+ it 'formats colors' do
44
+ @chart.colors = ["#ff0000"]
45
+ @chart.formatted_colors.should == "['ff0000']"
46
+ end
47
+
48
+ it 'sets its data columns' do
49
+ @chart.data_columns.should =~ /addRows\(5\)/
50
+ @chart.data_columns.should =~ /addColumn\('string', 'Date'\)/
51
+ @chart.data_columns.should =~ /addColumn\('number', '0'\)/
52
+ @chart.data_columns.should =~ /addColumn\('number', '1'\)/
53
+ @chart.data_columns.should =~ /addColumn\('number', '2'\)/
54
+ @chart.data_columns.should =~ /addColumn\('number', '3'\)/
55
+ end
56
+
57
+ it 'sets its options' do
58
+ @chart.options.should =~ /options\['titleX'\] = 'Something'/
59
+ end
60
+
61
+
62
+ end
@@ -0,0 +1,51 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Seer::ColumnChart" do
4
+
5
+ before :each do
6
+ @chart = Seer::ColumnChart.new(
7
+ :data => [0,1,2,3],
8
+ :label_method => 'to_s',
9
+ :data_method => 'size',
10
+ :chart_options => {},
11
+ :chart_element => 'chart'
12
+ )
13
+ end
14
+
15
+ describe 'defaults' do
16
+ it_should_behave_like 'it sets default values'
17
+ end
18
+
19
+ describe 'graph options' do
20
+
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|
22
+ it "sets its #{accessor} value" do
23
+ @chart.send("#{accessor}=", 'foo')
24
+ @chart.send(accessor).should == 'foo'
25
+ end
26
+ end
27
+
28
+ it_should_behave_like 'it has colors attribute'
29
+ end
30
+
31
+ it 'renders as JavaScript' do
32
+ (@chart.to_js =~ /javascript/).should be_true
33
+ (@chart.to_js =~ /columnchart/).should be_true
34
+ end
35
+
36
+ it 'sets its data columns' do
37
+ @chart.data_columns.should =~ /addRows\(4\)/
38
+ end
39
+
40
+ it 'sets its data table' do
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)
49
+ end
50
+
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
@@ -0,0 +1,59 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Seer::Gauge" do
4
+
5
+ before :each do
6
+ @chart = Seer::Gauge.new(
7
+ :data => [0,1,2,3],
8
+ :label_method => 'to_s',
9
+ :data_method => 'size',
10
+ :chart_options => {},
11
+ :chart_element => 'chart'
12
+ )
13
+ end
14
+
15
+ describe 'defaults' do
16
+
17
+ it 'height' do
18
+ @chart.height.should == Seer::Chart::DEFAULT_HEIGHT
19
+ end
20
+
21
+ it 'width' do
22
+ @chart.width.should == Seer::Chart::DEFAULT_WIDTH
23
+ end
24
+
25
+ end
26
+
27
+ describe 'graph options' do
28
+
29
+ [:green_from, :green_to, :height, :major_ticks, :max, :min, :minor_ticks, :red_from, :red_to, :width, :yellow_from, :yellow_to].each do |accessor|
30
+ it "sets its #{accessor} value" do
31
+ @chart.send("#{accessor}=", 'foo')
32
+ @chart.send(accessor).should == 'foo'
33
+ end
34
+ end
35
+
36
+ it_should_behave_like 'it has colors attribute'
37
+ end
38
+
39
+ it 'renders as JavaScript' do
40
+ (@chart.to_js =~ /javascript/).should be_true
41
+ (@chart.to_js =~ /gauge/).should be_true
42
+ end
43
+
44
+ it 'sets its data columns' do
45
+ @chart.data_columns.should =~ /addRows\(4\)/
46
+ end
47
+
48
+ it 'sets its data table' do
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)
57
+ end
58
+
59
+ end
@@ -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
@@ -0,0 +1,86 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Seer::LineChart" do
4
+
5
+ before :each do
6
+ @chart = Seer::LineChart.new(
7
+ :data => [0,1,2,3],
8
+ :series_label => 'to_s',
9
+ :data_series => [[1,2,3],[3,4,5]],
10
+ :data_label => 'to_s',
11
+ :data_method => 'size',
12
+ :chart_options => {},
13
+ :chart_element => 'chart'
14
+ )
15
+ end
16
+
17
+ describe 'defaults' do
18
+ it_should_behave_like 'it sets default values'
19
+ end
20
+
21
+ describe 'graph options' do
22
+
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|
24
+ it "sets its #{accessor} value" do
25
+ @chart.send("#{accessor}=", 'foo')
26
+ @chart.send(accessor).should == 'foo'
27
+ end
28
+ end
29
+
30
+ it_should_behave_like 'it has colors attribute'
31
+ end
32
+
33
+ it 'renders as JavaScript' do
34
+ (@chart.to_js =~ /javascript/).should be_true
35
+ (@chart.to_js =~ /linechart/).should be_true
36
+ end
37
+
38
+ it 'sets its data columns' do
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')
45
+ end
46
+
47
+ it 'sets its data table' do
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
84
+ end
85
+
86
+ end