ncri-seer 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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
@@ -0,0 +1,51 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Seer::PieChart" do
4
+
5
+ before :each do
6
+ @chart = Seer::PieChart.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
+ [: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|
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 =~ /piechart/).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
data/spec/seer_spec.rb ADDED
@@ -0,0 +1,134 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Seer" do
4
+
5
+ require 'rubygems'
6
+
7
+ it 'validates hexadecimal numbers' do
8
+ invalid = [nil, '', 'food', 'bdadce', 123456]
9
+ valid = ['#000000','#ffffff']
10
+ invalid.each{ |e| Seer.valid_hex_number?(e).should be_false }
11
+ valid.each { |e| Seer.valid_hex_number?(e).should be_true }
12
+ end
13
+
14
+ describe 'visualize' do
15
+
16
+ it 'raises an error for invalid visualizaters' do
17
+ invalid = [:random, 'something']
18
+ invalid.each do |e|
19
+ lambda do
20
+ Seer.visualize([1,2,3], :as => e)
21
+ end.should raise_error(ArgumentError)
22
+ end
23
+ end
24
+
25
+ it 'raises an error for missing data' do
26
+ _data = []
27
+ lambda do
28
+ Seer.visualize(_data, :as => :bar_chart)
29
+ end.should raise_error(ArgumentError)
30
+ end
31
+
32
+ it 'accepts valid visualizers' do
33
+ Seer::VISUALIZERS.each do |v|
34
+ lambda do
35
+ Seer::visualize(
36
+ [0,1,2,3],
37
+ :as => v,
38
+ :in_element => 'chart',
39
+ :series => {:label => 'to_s', :data => 'size'},
40
+ :chart_options => {}
41
+ )
42
+ end.should_not raise_error(ArgumentError)
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ describe 'private chart methods' do
49
+
50
+ it 'renders an area chart' do
51
+ (Seer.send(:area_chart,
52
+ [0,1,2,3],
53
+ :as => :area_chart,
54
+ :in_element => 'chart',
55
+ :series => {
56
+ :series_label => 'to_s',
57
+ :data_label => 'to_s',
58
+ :data_method => 'size',
59
+ :data_series => [[1,2,3],[3,4,5]]
60
+ },
61
+ :chart_options => {}
62
+ ) =~ /areachart/).should be_true
63
+ end
64
+
65
+ it 'renders a bar chart' do
66
+ (Seer.send(:bar_chart,
67
+ [0,1,2,3],
68
+ :as => :bar_chart,
69
+ :in_element => 'chart',
70
+ :series => {
71
+ :series_label => 'to_s',
72
+ :data_method => 'size'
73
+ },
74
+ :chart_options => {}
75
+ ) =~ /barchart/).should be_true
76
+ end
77
+
78
+ it 'renders a column chart' do
79
+ (Seer.send(:column_chart,
80
+ [0,1,2,3],
81
+ :as => :column_chart,
82
+ :in_element => 'chart',
83
+ :series => {
84
+ :series_label => 'to_s',
85
+ :data_method => 'size'
86
+ },
87
+ :chart_options => {}
88
+ ) =~ /columnchart/).should be_true
89
+ end
90
+
91
+ it 'renders a gauge' do
92
+ (Seer.send(:gauge,
93
+ [0,1,2,3],
94
+ :as => :gauge,
95
+ :in_element => 'chart',
96
+ :series => {
97
+ :series_label => 'to_s',
98
+ :data_method => 'size'
99
+ },
100
+ :chart_options => {}
101
+ ) =~ /gauge/).should be_true
102
+ end
103
+
104
+ it 'renders a line chart' do
105
+ (Seer.send(:line_chart,
106
+ [0,1,2,3],
107
+ :as => :line_chart,
108
+ :in_element => 'chart',
109
+ :series => {
110
+ :series_label => 'to_s',
111
+ :data_label => 'to_s',
112
+ :data_method => 'size',
113
+ :data_series => [[1,2,3],[3,4,5]]
114
+ },
115
+ :chart_options => {}
116
+ ) =~ /linechart/).inspect #should be_true
117
+ end
118
+
119
+ it 'renders a pie chart' do
120
+ (Seer.send(:pie_chart,
121
+ [0,1,2,3],
122
+ :as => :pie_chart,
123
+ :in_element => 'chart',
124
+ :series => {
125
+ :series_label => 'to_s',
126
+ :data_method => 'size'
127
+ },
128
+ :chart_options => {}
129
+ ) =~ /piechart/).should be_true
130
+ end
131
+
132
+ end
133
+
134
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
4
+ require 'actionpack'
5
+ require 'active_support'
6
+ require 'spec'
7
+ require 'spec/autorun'
8
+ require 'seer'
9
+ require File.dirname(__FILE__) + "/custom_matchers"
10
+ require File.dirname(__FILE__) + '/helpers'
11
+ Spec::Runner.configure do |config|
12
+ config.include(CustomMatcher)
13
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ncri-seer
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 0
9
+ version: 0.5.1
10
+ platform: ruby
11
+ authors:
12
+ - Corey Ehmke / SEO Logic
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-03 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ description: " Seer is a lightweight, semantically rich wrapper for the Google Visualization API. It allows you to easily create a visualization of data in a variety of formats, including area charts, bar charts, column charts, gauges, line charts, and pie charts."
35
+ email: corey@seologic.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - LICENSE
42
+ - README.rdoc
43
+ files:
44
+ - CONTRIBUTORS
45
+ - LICENSE
46
+ - README.rdoc
47
+ - Rakefile
48
+ - init.rb
49
+ - lib/seer.rb
50
+ - lib/seer/area_chart.rb
51
+ - lib/seer/bar_chart.rb
52
+ - lib/seer/chart.rb
53
+ - lib/seer/column_chart.rb
54
+ - lib/seer/gauge.rb
55
+ - lib/seer/line_chart.rb
56
+ - lib/seer/pie_chart.rb
57
+ - spec/seer_spec.rb
58
+ - spec/spec.opts
59
+ - spec/spec_helper.rb
60
+ - spec/area_chart_spec.rb
61
+ - spec/bar_chart_spec.rb
62
+ - spec/chart_spec.rb
63
+ - spec/column_chart_spec.rb
64
+ - spec/custom_matchers.rb
65
+ - spec/gauge_spec.rb
66
+ - spec/helpers.rb
67
+ - spec/line_chart_spec.rb
68
+ - spec/pie_chart_spec.rb
69
+ has_rdoc: true
70
+ homepage: http://github.com/Bantik/seer
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --charset=UTF-8
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.3.6
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Seer is a lightweight, semantically rich wrapper for the Google Visualization API.
99
+ test_files:
100
+ - spec/area_chart_spec.rb
101
+ - spec/bar_chart_spec.rb
102
+ - spec/chart_spec.rb
103
+ - spec/column_chart_spec.rb
104
+ - spec/custom_matchers.rb
105
+ - spec/gauge_spec.rb
106
+ - spec/helpers.rb
107
+ - spec/line_chart_spec.rb
108
+ - spec/pie_chart_spec.rb
109
+ - spec/seer_spec.rb
110
+ - spec/spec_helper.rb