gregoryfoster-gchartrb 0.9
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/CREDITS +6 -0
- data/History.txt +69 -0
- data/Manifest.txt +47 -0
- data/README.txt +64 -0
- data/Rakefile +61 -0
- data/TODO +10 -0
- data/gchartrb.gemspec +18 -0
- data/lib/core_ext.rb +32 -0
- data/lib/example.rb +75 -0
- data/lib/gchartrb.rb +1 -0
- data/lib/google_chart.rb +39 -0
- data/lib/google_chart/bar_chart.rb +83 -0
- data/lib/google_chart/base.rb +148 -0
- data/lib/google_chart/line_chart.rb +19 -0
- data/lib/google_chart/linexy_chart.rb +20 -0
- data/lib/google_chart/map_chart.rb +74 -0
- data/lib/google_chart/modules/axis.rb +62 -0
- data/lib/google_chart/modules/color.rb +15 -0
- data/lib/google_chart/modules/data_array.rb +57 -0
- data/lib/google_chart/modules/fills.rb +102 -0
- data/lib/google_chart/modules/grid.rb +27 -0
- data/lib/google_chart/modules/label.rb +27 -0
- data/lib/google_chart/modules/legend.rb +24 -0
- data/lib/google_chart/modules/markers.rb +88 -0
- data/lib/google_chart/pie_chart.rb +44 -0
- data/lib/google_chart/radar_chart.rb +33 -0
- data/lib/google_chart/scatter_plot.rb +34 -0
- data/lib/google_chart/sparkline_chart.rb +19 -0
- data/lib/google_chart/venn_diagram.rb +41 -0
- data/lib/test.rb +252 -0
- data/scripts/iso3166_en_code_lists.txt +250 -0
- data/scripts/process_country_codes.rb +27 -0
- data/spec/gchartrb/axis_spec.rb +125 -0
- data/spec/gchartrb/bar_chart_spec.rb +128 -0
- data/spec/gchartrb/fills_spec.rb +124 -0
- data/spec/gchartrb/grid_spec.rb +59 -0
- data/spec/gchartrb/line_chart_spec.rb +78 -0
- data/spec/gchartrb/linexy_chart_spec.rb +31 -0
- data/spec/gchartrb/markers_spec.rb +160 -0
- data/spec/gchartrb/pie_chart_spec.rb +36 -0
- data/spec/gchartrb/radar_chart_spec.rb +40 -0
- data/spec/gchartrb/scatter_plot_spec.rb +37 -0
- data/spec/gchartrb/sparkline_chart_spec.rb +16 -0
- data/spec/gchartrb/venn_diagram_spec.rb +57 -0
- data/spec/gchartrb_spec.rb +117 -0
- data/spec/helper.rb +15 -0
- data/spec/spec.opts +7 -0
- metadata +102 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../helper")
|
|
2
|
+
|
|
3
|
+
describe GoogleChart::Fills do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@chart = GoogleChart::LineChart.new
|
|
6
|
+
@chart.data "Series 1", [1,2,3,4,5], "ff00ff"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "is supported by LineChart, LineXYChart, BarChart, ScatterPlot and SparklineChart" do
|
|
10
|
+
[GoogleChart::LineChart, GoogleChart::LineXYChart,
|
|
11
|
+
GoogleChart::BarChart, GoogleChart::ScatterPlot, GoogleChart::SparklineChart].each do |klass|
|
|
12
|
+
klass.new.should respond_to(:fill)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "throws ArgumentError if the the fill method is called with an invalid fill type" do
|
|
17
|
+
lambda { @chart.fill(:gibberish) }.should raise_error(ArgumentError)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should throw an ArgumentError on accessing some property which does not exist" do
|
|
21
|
+
lambda { @chart.fill(:solid, :gibberish => "Yo") }.should raise_error(NoMethodError)
|
|
22
|
+
lambda do
|
|
23
|
+
@chart.fill :solid do |f|
|
|
24
|
+
f.gibberish = "Yo"
|
|
25
|
+
end
|
|
26
|
+
end.should raise_error(NoMethodError)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe "Solid Fill" do
|
|
30
|
+
it "should be able to initialise the properties from within a block" do
|
|
31
|
+
@chart.fill :solid do |f|
|
|
32
|
+
f.type = :background
|
|
33
|
+
f.color = "00ff00"
|
|
34
|
+
end
|
|
35
|
+
@chart.query_params[:chf].should be_eql("bg,s,00ff00")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "should be able to initialise the properties via a hash" do
|
|
39
|
+
@chart.fill(:solid, :type => :background, :color => "00ff00")
|
|
40
|
+
@chart.query_params[:chf].should be_eql("bg,s,00ff00")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "raises error on invalid type" do
|
|
44
|
+
lambda { @chart.fill(:solid, :type => :gibberish, :color => "00ff00") }.should raise_error(ArgumentError)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "raises error on invalid colors" do
|
|
48
|
+
lambda { @chart.fill(:solid, :type => :background) }.should raise_error(ArgumentError)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should raise ArgumentError if a non-background fill is not supported"
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe "Gradient Fill" do
|
|
56
|
+
|
|
57
|
+
before(:each) { @valid_gradient_values = {:type => :background, :angle => 45, :colors => ["ff00ff", "00ffff"], :offsets => [0,0.75]} }
|
|
58
|
+
it "should be able to initialise the properties from within a block" do
|
|
59
|
+
@chart.fill :gradient do |f|
|
|
60
|
+
f.type = :background
|
|
61
|
+
f.angle = 45
|
|
62
|
+
f.colors = ["ff00ff", "00ffff"]
|
|
63
|
+
f.offsets = [0,0.75]
|
|
64
|
+
end
|
|
65
|
+
@chart.query_params[:chf].should be_eql("bg,lg,45,ff00ff,0,00ffff,0.75")
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "should be able to initialise the properties via a hash" do
|
|
69
|
+
@chart.fill(:gradient, @valid_gradient_values)
|
|
70
|
+
@chart.query_params[:chf].should be_eql("bg,lg,45,ff00ff,0,00ffff,0.75")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "should raise an error for invalid value of angle" do
|
|
74
|
+
lambda { @chart.fill(:gradient, @valid_gradient_values.merge(:angle => "gibberish")) }.should raise_error(ArgumentError)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "raises an error on invalid value for type" do
|
|
78
|
+
lambda { @chart.fill(:gradient, @valid_gradient_values.merge(:type => :gibberish)) }.should raise_error(ArgumentError)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "raises an error on invalid value for colors" do
|
|
82
|
+
lambda { @chart.fill(:gradient, @valid_gradient_values.merge(:colors => [nil, 23, "ff00ff"])) }.should raise_error(ArgumentError)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "raises an error on invalid value for offests" do
|
|
86
|
+
lambda { @chart.fill(:gradient, @valid_gradient_values.merge(:offsets => [nil, 23, "ff00ff"])) }.should raise_error(ArgumentError)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
describe "Stripes" do
|
|
91
|
+
before(:each) { @valid_stripe_values = {:type => :background, :angle => 45, :colors => ["ff00ff", "00ffff"], :widths => [0.25,0.75]} }
|
|
92
|
+
|
|
93
|
+
it "should be able to initialise the properties from within a block" do
|
|
94
|
+
@chart.fill :stripes do |f|
|
|
95
|
+
f.type = :background
|
|
96
|
+
f.angle = 45
|
|
97
|
+
f.colors = ["ff00ff", "00ffff"]
|
|
98
|
+
f.widths = [0.25,0.75]
|
|
99
|
+
end
|
|
100
|
+
@chart.query_params[:chf].should be_eql("bg,ls,45,ff00ff,0.25,00ffff,0.75")
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "should be able to initialise the properties via a hash" do
|
|
104
|
+
@chart.fill(:stripes, @valid_stripe_values)
|
|
105
|
+
@chart.query_params[:chf].should be_eql("bg,ls,45,ff00ff,0.25,00ffff,0.75")
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "should raise an error on invalid value for type" do
|
|
109
|
+
lambda { @chart.fill(:stripes, @valid_stripe_values.merge(:type => :gibberish)) }.should raise_error(ArgumentError)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "should raise an error on invalid value for angle" do
|
|
113
|
+
lambda { @chart.fill(:stripes, @valid_stripe_values.merge(:angle => "gibberish")) }.should raise_error(ArgumentError)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it "raise an error on invalid value for colors" do
|
|
117
|
+
lambda { @chart.fill(:stripes, @valid_stripe_values.merge(:colors => [:gibberish])) }.should raise_error(ArgumentError)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "raise an error on invalid value for widths" do
|
|
121
|
+
lambda { @chart.fill(:stripes, @valid_stripe_values.merge(:widths => ["hi", "there"])) }.should raise_error(ArgumentError)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../helper")
|
|
2
|
+
|
|
3
|
+
describe GoogleChart::Grid do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@chart = GoogleChart::LineChart.new
|
|
6
|
+
@chart.data "Series 1", [1,2,3,4,5], "ff00ff"
|
|
7
|
+
@valid_grid_params = { :x_step => 20, :y_step => 50, :line_segment => 1, :blank_segment => 5 }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "is supported by LineChart, LineXYChart, BarChart, ScatterPlot and SparklineChart" do
|
|
11
|
+
[GoogleChart::LineChart, GoogleChart::LineXYChart,
|
|
12
|
+
GoogleChart::BarChart, GoogleChart::ScatterPlot, GoogleChart::SparklineChart].each do |klass|
|
|
13
|
+
klass.new.should respond_to(:grid)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should be able to take in values via a hash and generate a correct URL" do
|
|
18
|
+
@chart.grid(@valid_grid_params)
|
|
19
|
+
@chart.query_params[:chg].should == "20,50,1,5"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should be able to take in values via a block and generate a correct URL" do
|
|
23
|
+
@chart.grid do |g|
|
|
24
|
+
g.x_step = 20
|
|
25
|
+
g.y_step = 50
|
|
26
|
+
g.line_segment = 1
|
|
27
|
+
g.blank_segment = 5
|
|
28
|
+
end
|
|
29
|
+
@chart.query_params[:chg].should == "20,50,1,5"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should raise an error if any of the values is non numeric" do
|
|
33
|
+
params = @valid_grid_params.except(:x_step)
|
|
34
|
+
params[:x_step] = "yo"
|
|
35
|
+
lambda { @chart.grid(params) }.should raise_error(ArgumentError)
|
|
36
|
+
|
|
37
|
+
params = @valid_grid_params.except(:y_step)
|
|
38
|
+
params[:y_step] = "yo"
|
|
39
|
+
lambda { @chart.grid(params) }.should raise_error(ArgumentError)
|
|
40
|
+
|
|
41
|
+
params = @valid_grid_params.except(:line_segment)
|
|
42
|
+
params[:line_segment] = "yo"
|
|
43
|
+
lambda { @chart.grid(params) }.should raise_error(ArgumentError)
|
|
44
|
+
|
|
45
|
+
params = @valid_grid_params.except(:blank_segment)
|
|
46
|
+
params[:blank_segment] = "yo"
|
|
47
|
+
lambda { @chart.grid(params) }.should raise_error(ArgumentError)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should throw an error if x_step or y_step are not within 0 to 100" do
|
|
51
|
+
params = @valid_grid_params.except(:x_step)
|
|
52
|
+
params[:x_step] = 200
|
|
53
|
+
lambda { @chart.grid(params) }.should raise_error(ArgumentError)
|
|
54
|
+
|
|
55
|
+
params = @valid_grid_params.except(:y_step)
|
|
56
|
+
params[:y_step] = 200
|
|
57
|
+
lambda { @chart.grid(params) }.should raise_error(ArgumentError)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../helper")
|
|
2
|
+
|
|
3
|
+
describe GoogleChart::LineChart do
|
|
4
|
+
before(:each) { @line_chart = GoogleChart::LineChart.new }
|
|
5
|
+
it "should have the correct type" do
|
|
6
|
+
@line_chart.chart_type == "lc"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should initialise the default values" do
|
|
10
|
+
@line_chart.width.should == 320
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should raise error when the data is not an array of numeric" do
|
|
14
|
+
lambda { @line_chart.data("Series 1", [[1,2],[2,3]]) }.should raise_error(ArgumentError)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should add a data and a legend" do
|
|
18
|
+
@line_chart.data("Series 1", [1,2,3])
|
|
19
|
+
@line_chart.instance_variable_get("@data").first.should == [1,2,3]
|
|
20
|
+
@line_chart.instance_variable_get("@legends").first.should == "Series 1"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "should contain a simple set of query parameters after adding data" do
|
|
24
|
+
@line_chart.title = "Chart"
|
|
25
|
+
@line_chart.data("Series 1", [1,1,1])
|
|
26
|
+
|
|
27
|
+
@line_chart.query_params[:cht].should == "lc"
|
|
28
|
+
@line_chart.query_params[:chtt].should == "Chart"
|
|
29
|
+
@line_chart.query_params[:chd].should == "s:999"
|
|
30
|
+
@line_chart.query_params[:chs].should == "320x200"
|
|
31
|
+
|
|
32
|
+
@line_chart.data("Series 2", [2,2,2])
|
|
33
|
+
@line_chart.query_params[:chd].should == "s:fff,999"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should render the URL properly when to_url is called" do
|
|
37
|
+
@line_chart.data("Series 1", [1,1,1])
|
|
38
|
+
query_string_to_hash(@line_chart.to_url)[:chd].should == "s:999"
|
|
39
|
+
query_string_to_hash(@line_chart.to_url)[:cht].should == "lc"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "should accept extra parameters in the to_url method" do
|
|
43
|
+
@line_chart.data("Series 1", [1,1,1])
|
|
44
|
+
query_string_to_hash(@line_chart.to_url(:chtt => "test"))[:chtt].should == "test"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "should replace newline in title to pipe" do
|
|
48
|
+
@line_chart.title="test\nnewline"
|
|
49
|
+
@line_chart.title.should == "test|newline"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "should show legend if the show_legend attribute is set to true" do
|
|
53
|
+
@line_chart.data("Series", [1,2,3])
|
|
54
|
+
@line_chart.show_legend = true
|
|
55
|
+
@line_chart.query_params[:chdl].should_not be_nil
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should not show legend if show_legend attribute is set to true but legends are nil" do
|
|
59
|
+
@line_chart.data("Test", [1,2,3])
|
|
60
|
+
@line_chart.data(nil, [1,2,3])
|
|
61
|
+
@line_chart.show_legend = true
|
|
62
|
+
@line_chart.query_params[:chdl].should == "Test|"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "should have legend support" do
|
|
66
|
+
@line_chart.respond_to?(:legend, true).should be_true
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "should have color support" do
|
|
70
|
+
@line_chart.respond_to?(:color, true).should be_true
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "should have the max attribute defined" do
|
|
74
|
+
@line_chart.should respond_to(:max)
|
|
75
|
+
@line_chart.should_not respond_to(:max_x)
|
|
76
|
+
@line_chart.should_not respond_to(:max_y)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../helper")
|
|
2
|
+
|
|
3
|
+
describe GoogleChart::LineXYChart do
|
|
4
|
+
before(:each) { @linexy_chart = GoogleChart::LineXYChart.new }
|
|
5
|
+
it "should have the correct type" do
|
|
6
|
+
@linexy_chart.chart_type == "lxy"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should not accept a one dimensional array as input" do
|
|
10
|
+
lambda { @linexy_chart.data("Series 1",[1,2,3,4,5]) }.should raise_error(ArgumentError)
|
|
11
|
+
lambda { @linexy_chart.data("Series 1",[1,[2,3],3,4,5]) }.should raise_error(ArgumentError)
|
|
12
|
+
lambda { @linexy_chart.data("Series 1",[[1,2],[2,"a"]]) }.should raise_error(ArgumentError)
|
|
13
|
+
lambda { @linexy_chart.data("Series 1",[[1,2],[2,3]]) }.should_not raise_error(ArgumentError)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should have legend support" do
|
|
17
|
+
@linexy_chart.respond_to?(:legend, true).should be_true
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should process X and Y values correctly" do
|
|
21
|
+
@linexy_chart.data("Series 1",[[1,1],[2,2]])
|
|
22
|
+
@linexy_chart.query_params[:chd].should == "s:f9,f9"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should have a max_x and a max_y value defined" do
|
|
26
|
+
@linexy_chart.should respond_to(:max_x)
|
|
27
|
+
@linexy_chart.should respond_to(:max_y)
|
|
28
|
+
@linexy_chart.should_not respond_to(:max)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../helper")
|
|
2
|
+
|
|
3
|
+
describe GoogleChart::Markers do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@chart = GoogleChart::LineChart.new
|
|
6
|
+
@chart.data "Series 1", [1,2,3,4,5], "ff00ff"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "is supported by LineChart, LineXYChart, BarChart, ScatterPlot and SparklineChart" do
|
|
10
|
+
[GoogleChart::LineChart, GoogleChart::LineXYChart,
|
|
11
|
+
GoogleChart::BarChart, GoogleChart::ScatterPlot, GoogleChart::SparklineChart].each do |klass|
|
|
12
|
+
klass.new.should respond_to(:shape_marker)
|
|
13
|
+
klass.new.should respond_to(:range_marker)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe ".shape_marker" do
|
|
18
|
+
before(:each) { @valid_shape_marker = { :color => "ff00ff", :data_set => 0, :data_point => 1, :size => 4, :priority => :low } }
|
|
19
|
+
|
|
20
|
+
it "should be able to initialise the marker with an orientation and options hash" do
|
|
21
|
+
@chart.shape_marker(:arrow, @valid_shape_marker)
|
|
22
|
+
@chart.query_params[:chm].should == "a,ff00ff,0,1,4,-1"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should be able to initialise the marker with an orientation and block passed in" do
|
|
26
|
+
@chart.shape_marker(:arrow) do |marker|
|
|
27
|
+
marker.color = "ff00ff"
|
|
28
|
+
marker.data_set = 0
|
|
29
|
+
marker.data_point = 1
|
|
30
|
+
marker.size = 4
|
|
31
|
+
marker.priority = :low
|
|
32
|
+
end
|
|
33
|
+
@chart.query_params[:chm].should == "a,ff00ff,0,1,4,-1"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should raise an error if the shape is invalid" do
|
|
37
|
+
lambda { @chart.shape_marker(:gibberish,@valid_shape_marker) }.should raise_error(ArgumentError)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should raise error if color is not a string" do
|
|
41
|
+
params = @valid_shape_marker.except(:color)
|
|
42
|
+
params[:color] = :hi
|
|
43
|
+
lambda { @chart.shape_marker(:arrow,params) }.should raise_error(ArgumentError)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should raise error if data set is not an integer and is greater than the available number of data sets" do
|
|
47
|
+
params = @valid_shape_marker.except(:data_set)
|
|
48
|
+
params[:data_set] = 1
|
|
49
|
+
lambda { @chart.shape_marker(:arrow,params) }.should raise_error(ArgumentError)
|
|
50
|
+
|
|
51
|
+
params[:data_set] = -1
|
|
52
|
+
lambda { @chart.shape_marker(:arrow,params) }.should raise_error(ArgumentError)
|
|
53
|
+
|
|
54
|
+
params[:data_set] = "hi"
|
|
55
|
+
lambda { @chart.shape_marker(:arrow,params) }.should raise_error(ArgumentError)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should raise error if data point is not an integer and is greater than the available number of data points for the data set" do
|
|
59
|
+
params = @valid_shape_marker.except(:data_point)
|
|
60
|
+
params[:data_point] = 5
|
|
61
|
+
lambda { @chart.shape_marker(:arrow,params) }.should raise_error(ArgumentError)
|
|
62
|
+
|
|
63
|
+
params[:data_point] = -1
|
|
64
|
+
lambda { @chart.shape_marker(:arrow,params) }.should raise_error(ArgumentError)
|
|
65
|
+
|
|
66
|
+
params[:data_point] = "hi"
|
|
67
|
+
lambda { @chart.shape_marker(:arrow,params) }.should raise_error(ArgumentError)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should raise error if the priority is not :low or :high" do
|
|
71
|
+
params = @valid_shape_marker.except(:priority)
|
|
72
|
+
params[:priority] = 5
|
|
73
|
+
lambda { @chart.shape_marker(:arrow,params) }.should raise_error(ArgumentError)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "should not raise error if the priority is nil" do
|
|
77
|
+
params = @valid_shape_marker.except(:priority)
|
|
78
|
+
params[:priority] = nil
|
|
79
|
+
lambda { @chart.shape_marker(:arrow,params) }.should_not raise_error(ArgumentError)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "should raise error if size is not an integer" do
|
|
83
|
+
params = @valid_shape_marker.except(:size)
|
|
84
|
+
params[:size] = "hi"
|
|
85
|
+
lambda { @chart.shape_marker(:arrow,params) }.should raise_error(ArgumentError)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "should accept a text option for a text marker" do
|
|
89
|
+
@chart.shape_marker(:text, @valid_shape_marker.merge(:text => "Hi There"))
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "should not accept a text option for a text marker" do
|
|
93
|
+
lambda { @chart.shape_marker(:arrow, @valid_shape_marker.merge(:text => "Hi There")) }.should raise_error(ArgumentError)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "should format the text marker correctly" do
|
|
97
|
+
@chart.shape_marker(:text, @valid_shape_marker.merge(:text => "Hi There"))
|
|
98
|
+
@chart.query_params[:chm].should == "tHi+There,ff00ff,0,1,4,-1"
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
describe ".range_marker" do
|
|
104
|
+
|
|
105
|
+
before(:each) { @valid_range_marker = {:color => "ff00ff", :start => 0.5, :end => 0.7} }
|
|
106
|
+
|
|
107
|
+
it "should be able to initialise the marker with an orientation and options hash" do
|
|
108
|
+
@chart.range_marker(:vertical,@valid_range_marker)
|
|
109
|
+
@chart.query_params[:chm].should == "R,ff00ff,0,0.5,0.7"
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "should be able to initialise the marker with an orientation and block passed in" do
|
|
113
|
+
@chart.range_marker(:horizontal) do |marker|
|
|
114
|
+
marker.color = "ff00ff"
|
|
115
|
+
marker.start = 0.5
|
|
116
|
+
marker.end = 0.7
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
@chart.query_params[:chm].should == "r,ff00ff,0,0.5,0.7"
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "should raise error if the orientation is invalid" do
|
|
123
|
+
lambda { @chart.range_marker(:gibberish,@valid_range_marker) }.should raise_error(ArgumentError)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "should raise error if color is not a string" do
|
|
127
|
+
params = @valid_range_marker.except(:color)
|
|
128
|
+
params[:color] = nil
|
|
129
|
+
lambda { @chart.range_marker(:vertical,params) }.should raise_error(ArgumentError)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it "should raise error if start and end are not numeric" do
|
|
133
|
+
params = @valid_range_marker.except(:start)
|
|
134
|
+
params[:start] = "hi"
|
|
135
|
+
lambda { @chart.range_marker(:vertical,params) }.should raise_error(ArgumentError)
|
|
136
|
+
|
|
137
|
+
params = @valid_range_marker.except(:end)
|
|
138
|
+
params[:end] = "hi"
|
|
139
|
+
lambda { @chart.range_marker(:vertical,params) }.should raise_error(ArgumentError)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
it "should raise error if start and end are not within 0 and 1" do
|
|
144
|
+
params = @valid_range_marker.except(:start)
|
|
145
|
+
params[:start] = -1
|
|
146
|
+
lambda { @chart.range_marker(:vertical,params) }.should raise_error(ArgumentError)
|
|
147
|
+
|
|
148
|
+
params = @valid_range_marker.except(:end)
|
|
149
|
+
params[:end] = 5
|
|
150
|
+
lambda { @chart.range_marker(:vertical,params) }.should raise_error(ArgumentError)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it "should raise error if end < start" do
|
|
154
|
+
params = @valid_range_marker.except(:start, :end)
|
|
155
|
+
params[:start] = 0.9
|
|
156
|
+
params[:end] = 0.7
|
|
157
|
+
lambda { @chart.range_marker(:vertical,params) }.should raise_error(ArgumentError)
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|