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,250 @@
|
|
|
1
|
+
Source: http://www.iso.org/iso/iso3166_en_code_lists.txt
|
|
2
|
+
|
|
3
|
+
This list states the country names (official short names in English) in alphabetical order as given in ISO 3166-1 and the corresponding ISO 3166-1-alpha-2 code elements. The list is updated whenever a change to the official code list in ISO 3166-1 is effected by the ISO 3166/MA. It lists 240 official short names and code elements. One line of text contains one entry. A country name and its code element are separated by a semicolon (;).
|
|
4
|
+
|
|
5
|
+
AFGHANISTAN;AF
|
|
6
|
+
ÅLAND ISLANDS;AX
|
|
7
|
+
ALBANIA;AL
|
|
8
|
+
ALGERIA;DZ
|
|
9
|
+
AMERICAN SAMOA;AS
|
|
10
|
+
ANDORRA;AD
|
|
11
|
+
ANGOLA;AO
|
|
12
|
+
ANGUILLA;AI
|
|
13
|
+
ANTARCTICA;AQ
|
|
14
|
+
ANTIGUA AND BARBUDA;AG
|
|
15
|
+
ARGENTINA;AR
|
|
16
|
+
ARMENIA;AM
|
|
17
|
+
ARUBA;AW
|
|
18
|
+
AUSTRALIA;AU
|
|
19
|
+
AUSTRIA;AT
|
|
20
|
+
AZERBAIJAN;AZ
|
|
21
|
+
BAHAMAS;BS
|
|
22
|
+
BAHRAIN;BH
|
|
23
|
+
BANGLADESH;BD
|
|
24
|
+
BARBADOS;BB
|
|
25
|
+
BELARUS;BY
|
|
26
|
+
BELGIUM;BE
|
|
27
|
+
BELIZE;BZ
|
|
28
|
+
BENIN;BJ
|
|
29
|
+
BERMUDA;BM
|
|
30
|
+
BHUTAN;BT
|
|
31
|
+
BOLIVIA;BO
|
|
32
|
+
BOSNIA AND HERZEGOVINA;BA
|
|
33
|
+
BOTSWANA;BW
|
|
34
|
+
BOUVET ISLAND;BV
|
|
35
|
+
BRAZIL;BR
|
|
36
|
+
BRITISH INDIAN OCEAN TERRITORY;IO
|
|
37
|
+
BRUNEI DARUSSALAM;BN
|
|
38
|
+
BULGARIA;BG
|
|
39
|
+
BURKINA FASO;BF
|
|
40
|
+
BURUNDI;BI
|
|
41
|
+
CAMBODIA;KH
|
|
42
|
+
CAMEROON;CM
|
|
43
|
+
CANADA;CA
|
|
44
|
+
CAPE VERDE;CV
|
|
45
|
+
CAYMAN ISLANDS;KY
|
|
46
|
+
CENTRAL AFRICAN REPUBLIC;CF
|
|
47
|
+
CHAD;TD
|
|
48
|
+
CHILE;CL
|
|
49
|
+
CHINA;CN
|
|
50
|
+
CHRISTMAS ISLAND;CX
|
|
51
|
+
COCOS (KEELING) ISLANDS;CC
|
|
52
|
+
COLOMBIA;CO
|
|
53
|
+
COMOROS;KM
|
|
54
|
+
CONGO;CG
|
|
55
|
+
CONGO, THE DEMOCRATIC REPUBLIC OF THE;CD
|
|
56
|
+
COOK ISLANDS;CK
|
|
57
|
+
COSTA RICA;CR
|
|
58
|
+
CÔTE D'IVOIRE;CI
|
|
59
|
+
CROATIA;HR
|
|
60
|
+
CUBA;CU
|
|
61
|
+
CYPRUS;CY
|
|
62
|
+
CZECH REPUBLIC;CZ
|
|
63
|
+
DENMARK;DK
|
|
64
|
+
DJIBOUTI;DJ
|
|
65
|
+
DOMINICA;DM
|
|
66
|
+
DOMINICAN REPUBLIC;DO
|
|
67
|
+
ECUADOR;EC
|
|
68
|
+
EGYPT;EG
|
|
69
|
+
EL SALVADOR;SV
|
|
70
|
+
EQUATORIAL GUINEA;GQ
|
|
71
|
+
ERITREA;ER
|
|
72
|
+
ESTONIA;EE
|
|
73
|
+
ETHIOPIA;ET
|
|
74
|
+
FALKLAND ISLANDS (MALVINAS);FK
|
|
75
|
+
FAROE ISLANDS;FO
|
|
76
|
+
FIJI;FJ
|
|
77
|
+
FINLAND;FI
|
|
78
|
+
FRANCE;FR
|
|
79
|
+
FRENCH GUIANA;GF
|
|
80
|
+
FRENCH POLYNESIA;PF
|
|
81
|
+
FRENCH SOUTHERN TERRITORIES;TF
|
|
82
|
+
GABON;GA
|
|
83
|
+
GAMBIA;GM
|
|
84
|
+
GEORGIA;GE
|
|
85
|
+
GERMANY;DE
|
|
86
|
+
GHANA;GH
|
|
87
|
+
GIBRALTAR;GI
|
|
88
|
+
GREECE;GR
|
|
89
|
+
GREENLAND;GL
|
|
90
|
+
GRENADA;GD
|
|
91
|
+
GUADELOUPE;GP
|
|
92
|
+
GUAM;GU
|
|
93
|
+
GUATEMALA;GT
|
|
94
|
+
GUERNSEY;GG
|
|
95
|
+
GUINEA;GN
|
|
96
|
+
GUINEA-BISSAU;GW
|
|
97
|
+
GUYANA;GY
|
|
98
|
+
HAITI;HT
|
|
99
|
+
HEARD ISLAND AND MCDONALD ISLANDS;HM
|
|
100
|
+
HOLY SEE (VATICAN CITY STATE);VA
|
|
101
|
+
HONDURAS;HN
|
|
102
|
+
HONG KONG;HK
|
|
103
|
+
HUNGARY;HU
|
|
104
|
+
ICELAND;IS
|
|
105
|
+
INDIA;IN
|
|
106
|
+
INDONESIA;ID
|
|
107
|
+
IRAN, ISLAMIC REPUBLIC OF;IR
|
|
108
|
+
IRAQ;IQ
|
|
109
|
+
IRELAND;IE
|
|
110
|
+
ISLE OF MAN;IM
|
|
111
|
+
ISRAEL;IL
|
|
112
|
+
ITALY;IT
|
|
113
|
+
JAMAICA;JM
|
|
114
|
+
JAPAN;JP
|
|
115
|
+
JERSEY;JE
|
|
116
|
+
JORDAN;JO
|
|
117
|
+
KAZAKHSTAN;KZ
|
|
118
|
+
KENYA;KE
|
|
119
|
+
KIRIBATI;KI
|
|
120
|
+
KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF;KP
|
|
121
|
+
KOREA, REPUBLIC OF;KR
|
|
122
|
+
KUWAIT;KW
|
|
123
|
+
KYRGYZSTAN;KG
|
|
124
|
+
LAO PEOPLE'S DEMOCRATIC REPUBLIC;LA
|
|
125
|
+
LATVIA;LV
|
|
126
|
+
LEBANON;LB
|
|
127
|
+
LESOTHO;LS
|
|
128
|
+
LIBERIA;LR
|
|
129
|
+
LIBYAN ARAB JAMAHIRIYA;LY
|
|
130
|
+
LIECHTENSTEIN;LI
|
|
131
|
+
LITHUANIA;LT
|
|
132
|
+
LUXEMBOURG;LU
|
|
133
|
+
MACAO;MO
|
|
134
|
+
MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF;MK
|
|
135
|
+
MADAGASCAR;MG
|
|
136
|
+
MALAWI;MW
|
|
137
|
+
MALAYSIA;MY
|
|
138
|
+
MALDIVES;MV
|
|
139
|
+
MALI;ML
|
|
140
|
+
MALTA;MT
|
|
141
|
+
MARSHALL ISLANDS;MH
|
|
142
|
+
MARTINIQUE;MQ
|
|
143
|
+
MAURITANIA;MR
|
|
144
|
+
MAURITIUS;MU
|
|
145
|
+
MAYOTTE;YT
|
|
146
|
+
MEXICO;MX
|
|
147
|
+
MICRONESIA, FEDERATED STATES OF;FM
|
|
148
|
+
MOLDOVA, REPUBLIC OF;MD
|
|
149
|
+
MONACO;MC
|
|
150
|
+
MONGOLIA;MN
|
|
151
|
+
MONTENEGRO;ME
|
|
152
|
+
MONTSERRAT;MS
|
|
153
|
+
MOROCCO;MA
|
|
154
|
+
MOZAMBIQUE;MZ
|
|
155
|
+
MYANMAR;MM
|
|
156
|
+
NAMIBIA;NA
|
|
157
|
+
NAURU;NR
|
|
158
|
+
NEPAL;NP
|
|
159
|
+
NETHERLANDS;NL
|
|
160
|
+
NETHERLANDS ANTILLES;AN
|
|
161
|
+
NEW CALEDONIA;NC
|
|
162
|
+
NEW ZEALAND;NZ
|
|
163
|
+
NICARAGUA;NI
|
|
164
|
+
NIGER;NE
|
|
165
|
+
NIGERIA;NG
|
|
166
|
+
NIUE;NU
|
|
167
|
+
NORFOLK ISLAND;NF
|
|
168
|
+
NORTHERN MARIANA ISLANDS;MP
|
|
169
|
+
NORWAY;NO
|
|
170
|
+
OMAN;OM
|
|
171
|
+
PAKISTAN;PK
|
|
172
|
+
PALAU;PW
|
|
173
|
+
PALESTINIAN TERRITORY, OCCUPIED;PS
|
|
174
|
+
PANAMA;PA
|
|
175
|
+
PAPUA NEW GUINEA;PG
|
|
176
|
+
PARAGUAY;PY
|
|
177
|
+
PERU;PE
|
|
178
|
+
PHILIPPINES;PH
|
|
179
|
+
PITCAIRN;PN
|
|
180
|
+
POLAND;PL
|
|
181
|
+
PORTUGAL;PT
|
|
182
|
+
PUERTO RICO;PR
|
|
183
|
+
QATAR;QA
|
|
184
|
+
REUNION;RE
|
|
185
|
+
ROMANIA;RO
|
|
186
|
+
RUSSIAN FEDERATION;RU
|
|
187
|
+
RWANDA;RW
|
|
188
|
+
SAINT BARTHÉLEMY;BL
|
|
189
|
+
SAINT HELENA;SH
|
|
190
|
+
SAINT KITTS AND NEVIS;KN
|
|
191
|
+
SAINT LUCIA;LC
|
|
192
|
+
SAINT MARTIN;MF
|
|
193
|
+
SAINT PIERRE AND MIQUELON;PM
|
|
194
|
+
SAINT VINCENT AND THE GRENADINES;VC
|
|
195
|
+
SAMOA;WS
|
|
196
|
+
SAN MARINO;SM
|
|
197
|
+
SAO TOME AND PRINCIPE;ST
|
|
198
|
+
SAUDI ARABIA;SA
|
|
199
|
+
SENEGAL;SN
|
|
200
|
+
SERBIA;RS
|
|
201
|
+
SEYCHELLES;SC
|
|
202
|
+
SIERRA LEONE;SL
|
|
203
|
+
SINGAPORE;SG
|
|
204
|
+
SLOVAKIA;SK
|
|
205
|
+
SLOVENIA;SI
|
|
206
|
+
SOLOMON ISLANDS;SB
|
|
207
|
+
SOMALIA;SO
|
|
208
|
+
SOUTH AFRICA;ZA
|
|
209
|
+
SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS;GS
|
|
210
|
+
SPAIN;ES
|
|
211
|
+
SRI LANKA;LK
|
|
212
|
+
SUDAN;SD
|
|
213
|
+
SURINAME;SR
|
|
214
|
+
SVALBARD AND JAN MAYEN;SJ
|
|
215
|
+
SWAZILAND;SZ
|
|
216
|
+
SWEDEN;SE
|
|
217
|
+
SWITZERLAND;CH
|
|
218
|
+
SYRIAN ARAB REPUBLIC;SY
|
|
219
|
+
TAIWAN, PROVINCE OF CHINA;TW
|
|
220
|
+
TAJIKISTAN;TJ
|
|
221
|
+
TANZANIA, UNITED REPUBLIC OF;TZ
|
|
222
|
+
THAILAND;TH
|
|
223
|
+
TIMOR-LESTE;TL
|
|
224
|
+
TOGO;TG
|
|
225
|
+
TOKELAU;TK
|
|
226
|
+
TONGA;TO
|
|
227
|
+
TRINIDAD AND TOBAGO;TT
|
|
228
|
+
TUNISIA;TN
|
|
229
|
+
TURKEY;TR
|
|
230
|
+
TURKMENISTAN;TM
|
|
231
|
+
TURKS AND CAICOS ISLANDS;TC
|
|
232
|
+
TUVALU;TV
|
|
233
|
+
UGANDA;UG
|
|
234
|
+
UKRAINE;UA
|
|
235
|
+
UNITED ARAB EMIRATES;AE
|
|
236
|
+
UNITED KINGDOM;GB
|
|
237
|
+
UNITED STATES;US
|
|
238
|
+
UNITED STATES MINOR OUTLYING ISLANDS;UM
|
|
239
|
+
URUGUAY;UY
|
|
240
|
+
UZBEKISTAN;UZ
|
|
241
|
+
VANUATU;VU
|
|
242
|
+
VENEZUELA;VE
|
|
243
|
+
VIET NAM;VN
|
|
244
|
+
VIRGIN ISLANDS, BRITISH;VG
|
|
245
|
+
VIRGIN ISLANDS, U.S.;VI
|
|
246
|
+
WALLIS AND FUTUNA;WF
|
|
247
|
+
WESTERN SAHARA;EH
|
|
248
|
+
YEMEN;YE
|
|
249
|
+
ZAMBIA;ZM
|
|
250
|
+
ZIMBABWE;ZW
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# Constants.
|
|
4
|
+
USAGE = 'ruby process_country_codes.rb [input_filename]'
|
|
5
|
+
COUNTRY_CODE_REGEX = /^.+;(\w{2})$/ # Regex to pull country code.
|
|
6
|
+
ROW_SEPARATOR = "\n"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
#
|
|
10
|
+
# Main Program.
|
|
11
|
+
#
|
|
12
|
+
# Read command-line arguments.
|
|
13
|
+
unless ARGV.length == 1
|
|
14
|
+
puts USAGE
|
|
15
|
+
exit
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
input_filename = File.dirname(__FILE__) + '/' + ARGV[0]
|
|
19
|
+
|
|
20
|
+
# Process the file contents line by line.
|
|
21
|
+
country_codes = []
|
|
22
|
+
IO.foreach(input_filename, ROW_SEPARATOR) do |line|
|
|
23
|
+
match = line.match(COUNTRY_CODE_REGEX)
|
|
24
|
+
country_codes << match[1].to_sym unless match.nil?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
puts "[ :#{country_codes.join(', :')} ]"
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../helper")
|
|
2
|
+
|
|
3
|
+
describe GoogleChart::Axis do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@chart = GoogleChart::LineChart.new
|
|
6
|
+
@chart.data "Series 1", [1,2,3,4,5], "ff00ff"
|
|
7
|
+
@valid_axis_params = {
|
|
8
|
+
:color => "ff00ff" ,
|
|
9
|
+
:font_size => 15,
|
|
10
|
+
:alignment => :center,
|
|
11
|
+
:range => 0..500,
|
|
12
|
+
:labels => ["a","b","c"],
|
|
13
|
+
:positions => [100,200,400]
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "is supported by LineChart, LineXYChart, BarChart, ScatterPlot and SparklineChart" do
|
|
18
|
+
[GoogleChart::LineChart, GoogleChart::LineXYChart,
|
|
19
|
+
GoogleChart::BarChart, GoogleChart::ScatterPlot, GoogleChart::SparklineChart].each do |klass|
|
|
20
|
+
klass.new.should respond_to(:axis)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "throws ArgumentError if the the fill method is called with an invalid position type" do
|
|
25
|
+
lambda { @chart.axis(:gibberish) }.should raise_error(ArgumentError)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should be able to initialise the properties from within a block" do
|
|
29
|
+
@chart.axis(:top) do |axis|
|
|
30
|
+
axis.color = "ff00ff"
|
|
31
|
+
axis.font_size = 15
|
|
32
|
+
axis.alignment = :center
|
|
33
|
+
axis.range = 0..500
|
|
34
|
+
axis.labels = ["a","b","c"]
|
|
35
|
+
axis.positions = [100,200,400]
|
|
36
|
+
end
|
|
37
|
+
@chart.query_params[:chxt].should eql("t")
|
|
38
|
+
@chart.query_params[:chxs].should eql("0,ff00ff,15,0")
|
|
39
|
+
@chart.query_params[:chxl].should eql("0:|a|b|c")
|
|
40
|
+
@chart.query_params[:chxp].should eql("0,100,200,400")
|
|
41
|
+
@chart.query_params[:chxr].should eql("0,0,500")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should raise error if color is not a string (unless it is nil)" do
|
|
45
|
+
params = @valid_axis_params.except(:color, :font_size, :alignment)
|
|
46
|
+
lambda { @chart.axis(:top, params) }.should_not raise_error(ArgumentError)
|
|
47
|
+
|
|
48
|
+
params[:color] = 35
|
|
49
|
+
lambda { @chart.axis(:top, params) }.should raise_error(ArgumentError)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "should raise error if font_size is not a number (unless it is nil)" do
|
|
53
|
+
params = @valid_axis_params.except(:font_size, :alignment)
|
|
54
|
+
lambda { @chart.axis(:top, params) }.should_not raise_error(ArgumentError)
|
|
55
|
+
|
|
56
|
+
params[:font_size] = "hi"
|
|
57
|
+
lambda { @chart.axis(:top, params) }.should raise_error(ArgumentError)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "should raise error if range does not belong to class range and is not numeric (unless it is nil)" do
|
|
61
|
+
params = @valid_axis_params.except(:range)
|
|
62
|
+
lambda { @chart.axis(:top, params) }.should_not raise_error(ArgumentError)
|
|
63
|
+
|
|
64
|
+
params[:range] = "hi"
|
|
65
|
+
lambda { @chart.axis(:top, params) }.should raise_error(ArgumentError)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "should raise error if labels is not an array (and is not nil)" do
|
|
69
|
+
params = @valid_axis_params.except(:labels, :positions)
|
|
70
|
+
lambda { @chart.axis(:top, params) }.should_not raise_error(ArgumentError)
|
|
71
|
+
|
|
72
|
+
params[:labels] = "hi"
|
|
73
|
+
lambda { @chart.axis(:top, params) }.should raise_error(ArgumentError)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "should raise error if positions is not numeric array" do
|
|
77
|
+
params = @valid_axis_params.except(:positions)
|
|
78
|
+
lambda { @chart.axis(:top, params) }.should_not raise_error(ArgumentError)
|
|
79
|
+
|
|
80
|
+
params[:positions] = %w(a b c)
|
|
81
|
+
lambda { @chart.axis(:top, params) }.should raise_error(ArgumentError)
|
|
82
|
+
|
|
83
|
+
params[:positions] = "hi"
|
|
84
|
+
lambda { @chart.axis(:top, params) }.should raise_error(ArgumentError)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "should raise error if the number of elements for labels and positions are not the same (unless they are nil)" do
|
|
88
|
+
params = @valid_axis_params.except(:labels)
|
|
89
|
+
params[:labels] = %w(a b c d)
|
|
90
|
+
lambda { @chart.axis(:top, params) }.should raise_error(ArgumentError)
|
|
91
|
+
|
|
92
|
+
params[:labels] = nil
|
|
93
|
+
lambda { @chart.axis(:top, params) }.should_not raise_error(ArgumentError)
|
|
94
|
+
|
|
95
|
+
params = @valid_axis_params.except(:labels, :positions)
|
|
96
|
+
lambda { @chart.axis(:top, params) }.should_not raise_error(ArgumentError)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "should raise error if font_size is given without color" do
|
|
100
|
+
params = @valid_axis_params.except(:color, :alignment)
|
|
101
|
+
lambda { @chart.axis(:top, params) }.should raise_error(ArgumentError)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "should raise error if alignment is given without a font size and color" do
|
|
105
|
+
params = @valid_axis_params.except(:color, :font_size)
|
|
106
|
+
lambda { @chart.axis(:top, params) }.should raise_error(ArgumentError)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "should raise error if an invalid alignment is given (unless it is nil)" do
|
|
110
|
+
params = @valid_axis_params.except(:alignment)
|
|
111
|
+
lambda { @chart.axis(:top, params) }.should_not raise_error(ArgumentError)
|
|
112
|
+
|
|
113
|
+
params[:alignment] = :gibberish
|
|
114
|
+
lambda { @chart.axis(:top, params) }.should raise_error(ArgumentError)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "should raise an error if both position and range are given and the positions are not in range" do
|
|
118
|
+
params = @valid_axis_params.except(:positions, :range)
|
|
119
|
+
params[:positions] = [0,1,2]
|
|
120
|
+
lambda { @chart.axis(:top, params) }.should_not raise_error(ArgumentError)
|
|
121
|
+
params[:range] = 100..200
|
|
122
|
+
lambda { @chart.axis(:top, params) }.should raise_error(ArgumentError)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../helper")
|
|
2
|
+
|
|
3
|
+
module BarChartHelper
|
|
4
|
+
def add_valid_data(chart)
|
|
5
|
+
chart.data "Series 1", [1,2,3,4,5]
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe GoogleChart::BarChart do
|
|
10
|
+
include BarChartHelper
|
|
11
|
+
|
|
12
|
+
before(:each) { @bar = GoogleChart::BarChart.new }
|
|
13
|
+
it "should have the default type as bvg" do
|
|
14
|
+
@bar.chart_type.should == "bvg"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should raise error when the data is not an array of numeric" do
|
|
18
|
+
lambda { @bar.data("Series 1", [[1,2],[2,3]]) } .should raise_error(ArgumentError)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should have legend support" do
|
|
22
|
+
@bar.respond_to?(:legend, true).should be_true
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should support orientation" do
|
|
26
|
+
lambda { @bar.orientation = :horizontal }.should_not raise_error(NoMethodError)
|
|
27
|
+
lambda { @bar.orientation = :vertical }.should_not raise_error(NoMethodError)
|
|
28
|
+
lambda { @bar.orientation = :gibberish }.should raise_error(ArgumentError)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "should support grouping" do
|
|
32
|
+
lambda { @bar.grouping = :grouped }.should_not raise_error(NoMethodError)
|
|
33
|
+
lambda { @bar.grouping = :stacked }.should_not raise_error(NoMethodError)
|
|
34
|
+
lambda { @bar.grouping = :gibberish }.should raise_error(ArgumentError)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should change chart type on changes in orientation and grouping" do
|
|
38
|
+
@bar.grouping = :stacked
|
|
39
|
+
@bar.orientation = :vertical
|
|
40
|
+
@bar.chart_type.should be_eql("bvs")
|
|
41
|
+
|
|
42
|
+
@bar.grouping = :stacked
|
|
43
|
+
@bar.orientation = :horizontal
|
|
44
|
+
@bar.chart_type.should be_eql("bhs")
|
|
45
|
+
|
|
46
|
+
@bar.grouping = :grouped
|
|
47
|
+
@bar.orientation = :vertical
|
|
48
|
+
@bar.chart_type.should be_eql("bvg")
|
|
49
|
+
|
|
50
|
+
@bar.grouping = :grouped
|
|
51
|
+
@bar.orientation = :horizontal
|
|
52
|
+
@bar.chart_type.should be_eql("bhg")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should support bar width in charts" do
|
|
56
|
+
add_valid_data(@bar)
|
|
57
|
+
@bar.bar_width = 5
|
|
58
|
+
@bar.query_params[:chbh].should == "5"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "should raise error if bar width is not an integer" do
|
|
62
|
+
add_valid_data(@bar)
|
|
63
|
+
lambda { @bar.bar_width = "hi" }.should raise_error(ArgumentError)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "support bar spacing (within a group)" do
|
|
67
|
+
add_valid_data(@bar)
|
|
68
|
+
@bar.bar_width = 5
|
|
69
|
+
@bar.bar_spacing = 5
|
|
70
|
+
@bar.query_params[:chbh].should == "5,5"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "should raise error if bar spacing is not an integer" do
|
|
74
|
+
add_valid_data(@bar)
|
|
75
|
+
@bar.bar_width = 5
|
|
76
|
+
lambda { @bar.bar_spacing = "hi" }.should raise_error(ArgumentError)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should not support bar spacing without bar width" do
|
|
80
|
+
add_valid_data(@bar)
|
|
81
|
+
lambda { @bar.bar_spacing = 5 }.should raise_error(ArgumentError)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "support group spacing" do
|
|
85
|
+
add_valid_data(@bar)
|
|
86
|
+
@bar.bar_width = 5
|
|
87
|
+
@bar.bar_spacing = 5
|
|
88
|
+
@bar.group_spacing = 5
|
|
89
|
+
@bar.query_params[:chbh].should == "5,5,5"
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "should raise error if group spacing is not an integer" do
|
|
93
|
+
add_valid_data(@bar)
|
|
94
|
+
@bar.bar_width = 5
|
|
95
|
+
@bar.bar_spacing = 5
|
|
96
|
+
lambda { @bar.group_spacing = "hi" }.should raise_error(ArgumentError)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "should not support group spacing without bar width and bar spacing" do
|
|
100
|
+
add_valid_data(@bar)
|
|
101
|
+
lambda { @bar.group_spacing = 5 }.should raise_error(ArgumentError)
|
|
102
|
+
@bar.bar_width = 5
|
|
103
|
+
lambda { @bar.group_spacing = 5 }.should raise_error(ArgumentError)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it "should encode properly encode the max value for the stacked bar chart" do
|
|
107
|
+
@bar.orientation = :vertical
|
|
108
|
+
@bar.grouping = :stacked
|
|
109
|
+
@bar.encoding = :extended
|
|
110
|
+
@bar.data "2^i", (0..8).to_a.collect{|i| 2**i}, "ff0000"
|
|
111
|
+
@bar.data "2.1^i", (0..8).to_a.collect{|i| 2.1**i}, "00ff00"
|
|
112
|
+
@bar.data "2.2^i", (0..8).to_a.collect{|i| 2.2**i}, "0000ff"
|
|
113
|
+
@bar.query_params[:chd].starts_with?("e:ADAHAOAcA3BvDeG7N2").should be_true
|
|
114
|
+
@bar.max.should == (2**8 + 2.1**8 + 2.2**8)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "should use the max value as an override if it is specified already" do
|
|
118
|
+
@bar.orientation = :vertical
|
|
119
|
+
@bar.grouping = :stacked
|
|
120
|
+
@bar.encoding = :extended
|
|
121
|
+
@bar.data "2^i", (0..8).to_a.collect{|i| 2**i}, "ff0000"
|
|
122
|
+
@bar.data "2.1^i", (0..8).to_a.collect{|i| 2.1**i}, "00ff00"
|
|
123
|
+
@bar.data "2.2^i", (0..8).to_a.collect{|i| 2.2**i}, "0000ff"
|
|
124
|
+
@bar.max = (2**8 + 2.1**8 + 2.2**8) * 2
|
|
125
|
+
@bar.query_params[:chd].starts_with?("e:ADAHAOAcA3BvDeG7N2").should be_false
|
|
126
|
+
@bar.max.should_not == (2**8 + 2.1**8 + 2.2**8)
|
|
127
|
+
end
|
|
128
|
+
end
|