gregoryfoster-gchartrb 0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/CREDITS +6 -0
  2. data/History.txt +69 -0
  3. data/Manifest.txt +47 -0
  4. data/README.txt +64 -0
  5. data/Rakefile +61 -0
  6. data/TODO +10 -0
  7. data/gchartrb.gemspec +18 -0
  8. data/lib/core_ext.rb +32 -0
  9. data/lib/example.rb +75 -0
  10. data/lib/gchartrb.rb +1 -0
  11. data/lib/google_chart.rb +39 -0
  12. data/lib/google_chart/bar_chart.rb +83 -0
  13. data/lib/google_chart/base.rb +148 -0
  14. data/lib/google_chart/line_chart.rb +19 -0
  15. data/lib/google_chart/linexy_chart.rb +20 -0
  16. data/lib/google_chart/map_chart.rb +74 -0
  17. data/lib/google_chart/modules/axis.rb +62 -0
  18. data/lib/google_chart/modules/color.rb +15 -0
  19. data/lib/google_chart/modules/data_array.rb +57 -0
  20. data/lib/google_chart/modules/fills.rb +102 -0
  21. data/lib/google_chart/modules/grid.rb +27 -0
  22. data/lib/google_chart/modules/label.rb +27 -0
  23. data/lib/google_chart/modules/legend.rb +24 -0
  24. data/lib/google_chart/modules/markers.rb +88 -0
  25. data/lib/google_chart/pie_chart.rb +44 -0
  26. data/lib/google_chart/radar_chart.rb +33 -0
  27. data/lib/google_chart/scatter_plot.rb +34 -0
  28. data/lib/google_chart/sparkline_chart.rb +19 -0
  29. data/lib/google_chart/venn_diagram.rb +41 -0
  30. data/lib/test.rb +252 -0
  31. data/scripts/iso3166_en_code_lists.txt +250 -0
  32. data/scripts/process_country_codes.rb +27 -0
  33. data/spec/gchartrb/axis_spec.rb +125 -0
  34. data/spec/gchartrb/bar_chart_spec.rb +128 -0
  35. data/spec/gchartrb/fills_spec.rb +124 -0
  36. data/spec/gchartrb/grid_spec.rb +59 -0
  37. data/spec/gchartrb/line_chart_spec.rb +78 -0
  38. data/spec/gchartrb/linexy_chart_spec.rb +31 -0
  39. data/spec/gchartrb/markers_spec.rb +160 -0
  40. data/spec/gchartrb/pie_chart_spec.rb +36 -0
  41. data/spec/gchartrb/radar_chart_spec.rb +40 -0
  42. data/spec/gchartrb/scatter_plot_spec.rb +37 -0
  43. data/spec/gchartrb/sparkline_chart_spec.rb +16 -0
  44. data/spec/gchartrb/venn_diagram_spec.rb +57 -0
  45. data/spec/gchartrb_spec.rb +117 -0
  46. data/spec/helper.rb +15 -0
  47. data/spec/spec.opts +7 -0
  48. metadata +102 -0
@@ -0,0 +1,36 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../helper")
2
+
3
+ describe GoogleChart::PieChart do
4
+ before(:each) { @pie = GoogleChart::PieChart.new(:encoding => :text) }
5
+ it "should have the correct type by default" do
6
+ @pie.chart_type.should == "p"
7
+ end
8
+
9
+ it "should have fills,color and label support" do
10
+ @pie.respond_to?(:label,true).should be_true
11
+ @pie.should respond_to(:fill)
12
+ @pie.respond_to?(:color,true).should be_true
13
+ end
14
+
15
+ it "should change type to p3 if the is_3d option is set to true" do
16
+ @pie.is_3d = true
17
+ @pie.chart_type.should == "p3"
18
+ @pie.is_3d?.should be_true
19
+ end
20
+
21
+ it "should have show_labels set to true by default" do
22
+ @pie.show_labels?.should be_true
23
+ end
24
+
25
+ it "should take in data and render the params correctly" do
26
+ @pie.data "Series 1", 20
27
+ @pie.data "Series 2", 100
28
+ @pie.data "Series 3", 40
29
+ @pie.query_params[:chd].should == "t:20.0,100.0,40.0"
30
+ @pie.query_params[:chl].should == "Series 1|Series 2|Series 3"
31
+ end
32
+
33
+ it "should not accept non numeric data" do
34
+ lambda { @pie.data "Series", [1,2,3] }.should raise_error(ArgumentError)
35
+ end
36
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../helper")
2
+
3
+ module RadarChartHelper
4
+ def add_valid_data(chart)
5
+ chart.data "Series 1", [1,2,3,4,5]
6
+ end
7
+ end
8
+
9
+ describe GoogleChart::RadarChart do
10
+ include RadarChartHelper
11
+
12
+ before(:each) { @radar = GoogleChart::RadarChart.new }
13
+
14
+ it "should have legend,axis,grid,fill and marker support" do
15
+ @radar.respond_to?(:legend, true).should be_true
16
+ @radar.respond_to?(:axis).should be_true
17
+ @radar.respond_to?(:grid).should be_true
18
+ @radar.respond_to?(:fill).should be_true
19
+ @radar.respond_to?(:range_marker).should be_true
20
+ end
21
+
22
+ it "should have the default type as r" do
23
+ @radar.chart_type.should == "r"
24
+ end
25
+
26
+ it "should change types when the value of splines is set to true" do
27
+ @radar.splines = true
28
+ @radar.chart_type.should == "rs"
29
+ end
30
+
31
+ it "should raise error if the splines value is not true or false" do
32
+ lambda { @radar.splines = "hi" }.should raise_error(ArgumentError)
33
+ end
34
+
35
+ it "should raise error when the data is not an array of numeric" do
36
+ lambda { @radar.data("Series 1", [[1,2],[2,3]]) } .should raise_error(ArgumentError)
37
+ end
38
+
39
+
40
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../helper")
2
+
3
+ describe GoogleChart::ScatterPlot do
4
+ before(:each) { @scatter = GoogleChart::ScatterPlot.new(:encoding => :text) }
5
+ it "should have the correct type" do
6
+ @scatter.chart_type == "s"
7
+ end
8
+
9
+ it "should not accept a one dimensional array as input" do
10
+ lambda { @scatter.data("Series 1",[1,2,3,4,5]) }.should raise_error(ArgumentError)
11
+ lambda { @scatter.data("Series 1",[1,[2,3],3,4,5]) }.should raise_error(ArgumentError)
12
+ lambda { @scatter.data("Series 1",[[1,2],[2,"a"]]) }.should raise_error(ArgumentError)
13
+ lambda { @scatter.data("Series 1",[[1,2],[2,3]]) }.should_not raise_error(ArgumentError)
14
+ end
15
+
16
+
17
+ it "should have legend support" do
18
+ @scatter.respond_to?(:legend, true).should be_true
19
+ end
20
+
21
+ it "should have support for point sizes" do
22
+ @scatter.data("Series 1",[[50,50],[100,100]])
23
+ @scatter.point_sizes [15,15]
24
+ @scatter.query_params[:chd].should == "t:50.0,100.0|50.0,100.0|100.0,100.0"
25
+ end
26
+
27
+ it "should have raise error if point sizes array is greater than data size" do
28
+ @scatter.data("Series 1",[[50,50],[100,100]])
29
+ lambda { @scatter.point_sizes [15,15,15] }.should raise_error(ArgumentError)
30
+ end
31
+
32
+
33
+ it "should raise error if point size is not an array" do
34
+ @scatter.data("Series 1",[[50,50],[100,100]])
35
+ lambda { @scatter.point_sizes :gibberish }.should raise_error(ArgumentError)
36
+ end
37
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../helper")
2
+
3
+ describe GoogleChart::SparklineChart do
4
+ before(:each) { @sparkline = GoogleChart::SparklineChart.new }
5
+ it "should have the correct type" do
6
+ @sparkline.chart_type == "ls"
7
+ end
8
+
9
+ it "should raise error when the data is not an array of numeric" do
10
+ lambda { @sparkline.data("Series 1", [[1,2],[2,3]]) } .should raise_error(ArgumentError)
11
+ end
12
+
13
+ it "should have legend support" do
14
+ @sparkline.respond_to?(:legend, true).should be_true
15
+ end
16
+ end
@@ -0,0 +1,57 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../helper")
2
+
3
+ describe GoogleChart::VennDiagram do
4
+ before(:each) { @venn = GoogleChart::VennDiagram.new(:encoding => :text) }
5
+ it "should have the correct type" do
6
+ @venn.chart_type.should == "v"
7
+ end
8
+
9
+ it "should have legend,fills and color support" do
10
+ @venn.respond_to?(:legend,true).should be_true
11
+ @venn.should respond_to(:fill)
12
+ @venn.respond_to?(:color,true).should be_true
13
+ end
14
+
15
+ it "should accept at most 3 data points with an integer value" do
16
+ @venn.data "Circle 1", 5
17
+ @venn.data "Circle 2", 5
18
+ @venn.data "Circle 3", 5
19
+ lambda { @venn.data "Circle 4", 5 }.should raise_error(ArgumentError)
20
+ end
21
+
22
+ it "should raise error if the data point is non numeric" do
23
+ lambda { @venn.data "Circle 1", "gibberish" }.should raise_error(ArgumentError)
24
+ end
25
+
26
+ it "should accept a maximum of 4 intersection points" do
27
+ @venn.data "Circle 1", 5
28
+ @venn.data "Circle 2", 5
29
+ @venn.data "Circle 3", 5
30
+ @venn.intersections 2,3,4,5
31
+ lambda { @venn.intersections 2,3,4,5,6 }.should raise_error(ArgumentError)
32
+ end
33
+
34
+ it "should raise error if no data is entered and intersections are being added" do
35
+ lambda { @venn.intersections 2,3,4 }.should raise_error(ArgumentError)
36
+ end
37
+
38
+ it "should raise error if number of intersections is greater than the number of data points + 1" do
39
+ @venn.data "Circle 1", 5
40
+ @venn.data "Circle 2", 5
41
+ lambda { @venn.intersections 2,3,4,5 }.should raise_error(ArgumentError)
42
+ end
43
+
44
+ it "should raise error if the intersection values are not integers" do
45
+ @venn.data "Circle 1", 5
46
+ @venn.data "Circle 2", 5
47
+ lambda { @venn.intersections "hi",3 }.should raise_error(ArgumentError)
48
+ end
49
+
50
+ it "should encode values and intersections correctly" do
51
+ @venn.encoding = :text
52
+ @venn.data "Circle 1", 100
53
+ @venn.data "Circle 2", 100
54
+ @venn.intersections 5
55
+ @venn.query_params[:chd].should == "t:100.0,100.0,0.0,5.0"
56
+ end
57
+ end
@@ -0,0 +1,117 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/helper")
2
+
3
+ describe GoogleChart::Base do
4
+ before(:each) do
5
+ # Evil metaprogramming. Not sure if I am doing the right thing ;)
6
+ self.instance_eval <<-EOF
7
+ class GoogleChart::Dummy < GoogleChart::Base
8
+ class <<self ; public :new ; end
9
+ end
10
+ EOF
11
+ end
12
+
13
+ it "cannot be initialised directly" do
14
+ lambda { GoogleChart::Base.new }.should raise_error(NoMethodError)
15
+ end
16
+
17
+ describe GoogleChart::Base, "new instance" do
18
+ before(:each) { @dummy = GoogleChart::Dummy.new }
19
+
20
+ it "show have valid height and width values when it is initialised" do
21
+ dummy = GoogleChart::Dummy.new(:height => 200, :width => 400)
22
+ dummy.width.should == 400
23
+ dummy.height.should == 200
24
+ end
25
+
26
+ it "should have a default size of 320x200" do
27
+ @dummy.width.should == 320
28
+ @dummy.height.should == 200
29
+ end
30
+
31
+ it "should able to initialise size via a WIDTHxHEIGHT string" do
32
+ @dummy.size.should == "320x200"
33
+ @dummy.size = "400x500"
34
+ @dummy.width.should == 400
35
+ @dummy.height.should == 500
36
+ end
37
+
38
+ it "should raise an error if the height or width is greater than 1000" do
39
+ lambda { @dummy.height = 1001 }.should raise_error(ArgumentError)
40
+ lambda { @dummy.width = 1001 }.should raise_error(ArgumentError)
41
+ end
42
+
43
+ it "should raise error if width x height is greater than 300000" do
44
+ lambda { @dummy.size = "400x1000" }.should raise_error(ArgumentError)
45
+ end
46
+
47
+ it "should have a default encoding of :simple" do
48
+ @dummy.encoding.should == :simple
49
+ end
50
+
51
+ it "should have attributes for title, title font size and title color" do
52
+ %w(title title_color title_font_size encoding).each { |m| @dummy.respond_to?(:title).should be(true) }
53
+ end
54
+
55
+ it "should throw an error on specifying an illegal encoding" do
56
+ lambda { @dummy.encoding = :gibberish }.should raise_error(ArgumentError)
57
+ lambda { @dummy.encoding = :extended }.should_not raise_error(ArgumentError)
58
+ end
59
+
60
+ it "should raise an exception when trying to specify type directly" do
61
+ lambda { @dummy.type = :line_xy }.should raise_error(NoMethodError)
62
+ end
63
+ end
64
+ end
65
+
66
+ # Blatantly copied from GChart(http://gchart.rubyforge.org)
67
+ describe GoogleChart, ".encode" do
68
+ it "supports the simple, text, and extended encoding" do
69
+ lambda { GoogleChart.encode(:simple, 4, 10) }.should_not raise_error(ArgumentError)
70
+ lambda { GoogleChart.encode(:text, 4, 10) }.should_not raise_error(ArgumentError)
71
+ lambda { GoogleChart.encode(:extended, 4, 10) }.should_not raise_error(ArgumentError)
72
+ lambda { GoogleChart.encode(:monkey, 4, 10) }.should raise_error(ArgumentError)
73
+ end
74
+
75
+ it "implements the simple encoding" do
76
+ expected = {
77
+ 0 => "A", 19 => "T", 27 => "b", 53 => "1", 61 => "9",
78
+ 12 => "M", 39 => "n", 57 => "5", 45 => "t", 51 => "z"
79
+ }
80
+
81
+ expected.each do |original, encoded|
82
+ GoogleChart.encode(:simple, original, 61).should == encoded
83
+ end
84
+ end
85
+
86
+ it "implements the text encoding" do
87
+ expected = {
88
+ 0 => "0.0", 10 => "10.0", 58 => "58.0", 95 => "95.0", 30 => "30.0", 8 => "8.0", 63 => "63.0", 100 => "100.0"
89
+ }
90
+
91
+ expected.each do |original, encoded|
92
+ GoogleChart.encode(:text, original, 100).should == encoded
93
+ end
94
+ end
95
+
96
+ it "implements the extended encoding" do
97
+ expected = {
98
+ 0 => "AA", 25 => "AZ", 26 => "Aa", 51 => "Az", 52 => "A0", 61 => "A9", 62 => "A-", 63 => "A.",
99
+ 64 => "BA", 89 => "BZ", 90 => "Ba", 115 => "Bz", 116 => "B0", 125 => "B9", 126 => "B-", 127 => "B.",
100
+ 4032 => ".A", 4057 => ".Z", 4058 => ".a", 4083 => ".z", 4084 => ".0", 4093 => ".9", 4094 => ".-", 4095 => ".."
101
+ }
102
+
103
+ expected.each do |original, encoded|
104
+ GoogleChart.encode(:extended, original, 4095).should == encoded
105
+ end
106
+ end
107
+
108
+ it "encodes nil correctly" do
109
+ GoogleChart.encode(:simple, nil, 1).should == "_"
110
+ GoogleChart.encode(:text, nil, 1).should == "-1"
111
+ GoogleChart.encode(:extended, nil, 1).should == "__"
112
+ end
113
+
114
+ it "encodes 0 with a max of 0 correctly" do
115
+ GoogleChart.encode(:extended, 0, 0).should == "AA"
116
+ end
117
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.expand_path("#{File.dirname(__FILE__)}/../lib"))
2
+ require 'uri'
3
+ def query_string_to_hash(url)
4
+ uri = URI.parse(url)
5
+ uri.query.split("&").inject({}) { |h,a| param,val = a.split("=") ; h[param.to_sym] = val ; h }
6
+ end
7
+
8
+ class Hash
9
+ def except(*rejected)
10
+ reject { |k,v| rejected.include?(k) }
11
+ end
12
+ end
13
+
14
+ require "spec"
15
+ require "gchartrb"
data/spec/spec.opts ADDED
@@ -0,0 +1,7 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
7
+
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gregoryfoster-gchartrb
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.9"
5
+ platform: ruby
6
+ authors:
7
+ - Deepak Jois
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: gchartrb is a Ruby wrapper around the Google Chart API, located at http://code.google.com/apis/chart/. Visit http://code.google.com/p/gchartrb to track development regarding gchartrb.
17
+ email: deepak.jois@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - History.txt
24
+ - Manifest.txt
25
+ - README.txt
26
+ files:
27
+ - CREDITS
28
+ - History.txt
29
+ - Manifest.txt
30
+ - README.txt
31
+ - Rakefile
32
+ - TODO
33
+ - gchartrb.gemspec
34
+ - lib/core_ext.rb
35
+ - lib/example.rb
36
+ - lib/gchartrb.rb
37
+ - lib/google_chart.rb
38
+ - lib/google_chart/bar_chart.rb
39
+ - lib/google_chart/base.rb
40
+ - lib/google_chart/line_chart.rb
41
+ - lib/google_chart/linexy_chart.rb
42
+ - lib/google_chart/map_chart.rb
43
+ - lib/google_chart/modules/axis.rb
44
+ - lib/google_chart/modules/color.rb
45
+ - lib/google_chart/modules/data_array.rb
46
+ - lib/google_chart/modules/fills.rb
47
+ - lib/google_chart/modules/grid.rb
48
+ - lib/google_chart/modules/label.rb
49
+ - lib/google_chart/modules/legend.rb
50
+ - lib/google_chart/modules/markers.rb
51
+ - lib/google_chart/pie_chart.rb
52
+ - lib/google_chart/radar_chart.rb
53
+ - lib/google_chart/scatter_plot.rb
54
+ - lib/google_chart/sparkline_chart.rb
55
+ - lib/google_chart/venn_diagram.rb
56
+ - lib/test.rb
57
+ - scripts/iso3166_en_code_lists.txt
58
+ - scripts/process_country_codes.rb
59
+ - spec/gchartrb/axis_spec.rb
60
+ - spec/gchartrb/bar_chart_spec.rb
61
+ - spec/gchartrb/fills_spec.rb
62
+ - spec/gchartrb/grid_spec.rb
63
+ - spec/gchartrb/line_chart_spec.rb
64
+ - spec/gchartrb/linexy_chart_spec.rb
65
+ - spec/gchartrb/markers_spec.rb
66
+ - spec/gchartrb/pie_chart_spec.rb
67
+ - spec/gchartrb/radar_chart_spec.rb
68
+ - spec/gchartrb/scatter_plot_spec.rb
69
+ - spec/gchartrb/sparkline_chart_spec.rb
70
+ - spec/gchartrb/venn_diagram_spec.rb
71
+ - spec/gchartrb_spec.rb
72
+ - spec/helper.rb
73
+ - spec/spec.opts
74
+ has_rdoc: true
75
+ homepage: http://code.google.com/p/gchartrb
76
+ post_install_message:
77
+ rdoc_options:
78
+ - --main
79
+ - README.txt
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ version:
94
+ requirements: []
95
+
96
+ rubyforge_project: gchartrb
97
+ rubygems_version: 1.0.1
98
+ signing_key:
99
+ specification_version: 2
100
+ summary: Ruby Wrapper for the Google Chart API
101
+ test_files: []
102
+