googlecharts 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +3 -0
- data/lib/gchart.rb +25 -1
- data/lib/gchart/version.rb +1 -1
- data/spec/gchart_spec.rb +38 -2
- data/website/index.html +30 -3
- data/website/index.txt +21 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
data/lib/gchart.rb
CHANGED
@@ -15,7 +15,7 @@ class Gchart
|
|
15
15
|
@@file_name = 'chart.png'
|
16
16
|
|
17
17
|
attr_accessor :title, :type, :width, :height, :horizontal, :grouped, :legend, :data, :encoding, :max_value, :bar_colors,
|
18
|
-
:title_color, :title_size, :custom, :axis_with_labels, :axis_labels
|
18
|
+
:title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing
|
19
19
|
|
20
20
|
class << self
|
21
21
|
# Support for Gchart.line(:title => 'my title', :size => '400x600')
|
@@ -174,6 +174,28 @@ class Gchart
|
|
174
174
|
"chco=#{@bar_colors}"
|
175
175
|
end
|
176
176
|
|
177
|
+
# set bar spacing
|
178
|
+
# chbh=
|
179
|
+
# <bar width in pixels>,
|
180
|
+
# <optional space between bars in a group>,
|
181
|
+
# <optional space between groups>
|
182
|
+
def set_bar_width_and_spacing
|
183
|
+
width_and_spacing_values = case @bar_width_and_spacing
|
184
|
+
when String
|
185
|
+
@bar_width_and_spacing
|
186
|
+
when Array
|
187
|
+
@bar_width_and_spacing.join(',')
|
188
|
+
when Hash
|
189
|
+
width = @bar_width_and_spacing[:width] || 23
|
190
|
+
spacing = @bar_width_and_spacing[:spacing] || 4
|
191
|
+
group_spacing = @bar_width_and_spacing[:group_spacing] || 8
|
192
|
+
[width,spacing,group_spacing].join(',')
|
193
|
+
else
|
194
|
+
@bar_width_and_spacing.to_s
|
195
|
+
end
|
196
|
+
"chbh=#{width_and_spacing_values}"
|
197
|
+
end
|
198
|
+
|
177
199
|
def fill_for(type=nil, color='', angle=nil)
|
178
200
|
unless type.nil?
|
179
201
|
case type
|
@@ -353,6 +375,8 @@ class Gchart
|
|
353
375
|
set_data unless @data == []
|
354
376
|
when '@bar_colors'
|
355
377
|
set_bar_colors
|
378
|
+
when '@bar_width_and_spacing'
|
379
|
+
set_bar_width_and_spacing
|
356
380
|
when '@axis_with_labels'
|
357
381
|
set_axis_with_labels
|
358
382
|
when '@axis_labels'
|
data/lib/gchart/version.rb
CHANGED
data/spec/gchart_spec.rb
CHANGED
@@ -161,6 +161,42 @@ describe "a bar graph" do
|
|
161
161
|
Gchart.bar(:bar_colors => ['efefef','00ffff']).include?('chco=efefef,00ffff').should be_true
|
162
162
|
end
|
163
163
|
|
164
|
+
it 'should be able to accept a string of width and spacing options' do
|
165
|
+
Gchart.bar(:bar_width_and_spacing => '25,6').include?('chbh=25,6').should be_true
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should be able to accept a single fixnum width and spacing option to set the bar width' do
|
169
|
+
Gchart.bar(:bar_width_and_spacing => 25).include?('chbh=25').should be_true
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should be able to accept an array of width and spacing options' do
|
173
|
+
Gchart.bar(:bar_width_and_spacing => [25,6,12]).include?('chbh=25,6,12').should be_true
|
174
|
+
Gchart.bar(:bar_width_and_spacing => [25,6]).include?('chbh=25,6').should be_true
|
175
|
+
Gchart.bar(:bar_width_and_spacing => [25]).include?('chbh=25').should be_true
|
176
|
+
end
|
177
|
+
|
178
|
+
describe "with a hash of width and spacing options" do
|
179
|
+
|
180
|
+
before(:each) do
|
181
|
+
@default_width = 23
|
182
|
+
@default_spacing = 4
|
183
|
+
@default_group_spacing = 8
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'should be able to have a custom bar width' do
|
187
|
+
Gchart.bar(:bar_width_and_spacing => {:width => 19}).include?("chbh=19,#{@default_spacing},#{@default_group_spacing}").should be_true
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'should be able to have custom spacing' do
|
191
|
+
Gchart.bar(:bar_width_and_spacing => {:spacing => 19}).include?("chbh=#{@default_width},19,#{@default_group_spacing}").should be_true
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should be able to have custom group spacing' do
|
195
|
+
Gchart.bar(:bar_width_and_spacing => {:group_spacing => 19}).include?("chbh=#{@default_width},#{@default_spacing},19").should be_true
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
|
164
200
|
end
|
165
201
|
|
166
202
|
describe "a line chart" do
|
@@ -220,7 +256,7 @@ describe "a line chart" do
|
|
220
256
|
end
|
221
257
|
|
222
258
|
it "should be able to render a graph where all the data values are 0" do
|
223
|
-
Gchart.line(:data => [0, 0, 0]).include?("chd=s:AAA").should
|
259
|
+
Gchart.line(:data => [0, 0, 0]).include?("chd=s:AAA").should be_true
|
224
260
|
end
|
225
261
|
|
226
262
|
end
|
@@ -324,7 +360,7 @@ describe "a google-o-meter" do
|
|
324
360
|
@chart = Gchart.meter(:data => @data)
|
325
361
|
end
|
326
362
|
|
327
|
-
it "should
|
363
|
+
it "should create a meter" do
|
328
364
|
@chart.include?('cht=gom').should be_true
|
329
365
|
end
|
330
366
|
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>Googlecharts</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/googlecharts"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/googlecharts" class="numbers">1.3.
|
36
|
+
<a href="http://rubyforge.org/projects/googlecharts" class="numbers">1.3.1</a>
|
37
37
|
</div>
|
38
38
|
<h2>→ ‘Sexy Charts using Google <span class="caps">API</span> & Ruby’</h2>
|
39
39
|
|
@@ -232,6 +232,32 @@ If you never added <a href="http://github.com">GitHub</a> as a gem source, you w
|
|
232
232
|
<p><img src="http://chart.apis.google.com/chart?cht=bvg&chs=300x200&chd=s:9UGo,Uo9C&chco=FF0000,00FF00" title="grouped bars" alt="grouped bars" /></p>
|
233
233
|
|
234
234
|
|
235
|
+
<p><strong>bar chart width and spacing</strong></p>
|
236
|
+
|
237
|
+
|
238
|
+
<p>A bar chart can accept options to set the width of the bars, spacing between bars and spacing between bar groups. To set these, you can either provide a string, array or hash.</p>
|
239
|
+
|
240
|
+
|
241
|
+
<p>The Google <span class="caps">API</span> sets these options in the order of width, spacing, and group spacing, with both spacing values being optional. So, if you provide a string or array, provide them in that order:</p>
|
242
|
+
|
243
|
+
|
244
|
+
<p><pre class='syntax'>
|
245
|
+
<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=></span> <span class="attribute">@data</span><span class="punct">,</span> <span class="symbol">:bar_width_and_spacing</span> <span class="punct">=></span> <span class="punct">'</span><span class="string">25,6</span><span class="punct">')</span> <span class="comment"># width of 25, spacing of 6</span>
|
246
|
+
<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=></span> <span class="attribute">@data</span><span class="punct">,</span> <span class="symbol">:bar_width_and_spacing</span> <span class="punct">=></span> <span class="punct">'</span><span class="string">25,6,12</span><span class="punct">')</span> <span class="comment"># width of 25, spacing of 6, group spacing of 12</span>
|
247
|
+
<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=></span> <span class="attribute">@data</span><span class="punct">,</span> <span class="symbol">:bar_width_and_spacing</span> <span class="punct">=></span> <span class="punct">[</span><span class="number">25</span><span class="punct">,</span><span class="number">6</span><span class="punct">])</span> <span class="comment"># width of 25, spacing of 6</span>
|
248
|
+
<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=></span> <span class="attribute">@data</span><span class="punct">,</span> <span class="symbol">:bar_width_and_spacing</span> <span class="punct">=></span> <span class="number">25</span><span class="punct">)</span> <span class="comment"># width of 25</span>
|
249
|
+
</pre></p>
|
250
|
+
|
251
|
+
|
252
|
+
<p>The hash lets you set these values directly, with the Google default values set for any options you don’t include:</p>
|
253
|
+
|
254
|
+
|
255
|
+
<p><pre class='syntax'>
|
256
|
+
<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=></span> <span class="attribute">@data</span><span class="punct">,</span> <span class="symbol">:bar_width_and_spacing</span> <span class="punct">=></span> <span class="punct">{</span><span class="symbol">:width</span> <span class="punct">=></span> <span class="number">19</span><span class="punct">})</span>
|
257
|
+
<span class="constant">Gchart</span><span class="punct">.</span><span class="ident">bar</span><span class="punct">(</span><span class="symbol">:data</span> <span class="punct">=></span> <span class="attribute">@data</span><span class="punct">,</span> <span class="symbol">:bar_width_and_spacing</span> <span class="punct">=></span> <span class="punct">{</span><span class="symbol">:spacing</span> <span class="punct">=></span> <span class="number">10</span><span class="punct">,</span> <span class="symbol">:group_spacing</span> <span class="punct">=></span> <span class="number">12</span><span class="punct">})</span>
|
258
|
+
</pre></p>
|
259
|
+
|
260
|
+
|
235
261
|
<p><strong>pie chart</strong></p>
|
236
262
|
|
237
263
|
|
@@ -639,9 +665,10 @@ Data set:
|
|
639
665
|
<h3>Contributors</h3>
|
640
666
|
|
641
667
|
|
642
|
-
<p><a href="http://github.com/dbgrandi">David Grandinetti</a
|
668
|
+
<p><a href="http://github.com/dbgrandi">David Grandinetti</a>
|
669
|
+
<a href="http://github.com/takeo">Toby Sterrett</a></p>
|
643
670
|
<p class="coda">
|
644
|
-
<a href="mattaimonetti@gmail.com">Matt Aimonetti</a>,
|
671
|
+
<a href="mattaimonetti@gmail.com">Matt Aimonetti</a>, 8th May 2008<br>
|
645
672
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
646
673
|
</p>
|
647
674
|
</div>
|
data/website/index.txt
CHANGED
@@ -145,6 +145,26 @@ The problem now, is that we can't see the first value of the second dataset sinc
|
|
145
145
|
|
146
146
|
!http://chart.apis.google.com/chart?cht=bvg&chs=300x200&chd=s:9UGo,Uo9C&chco=FF0000,00FF00(grouped bars)!
|
147
147
|
|
148
|
+
*bar chart width and spacing*
|
149
|
+
|
150
|
+
A bar chart can accept options to set the width of the bars, spacing between bars and spacing between bar groups. To set these, you can either provide a string, array or hash.
|
151
|
+
|
152
|
+
The Google API sets these options in the order of width, spacing, and group spacing, with both spacing values being optional. So, if you provide a string or array, provide them in that order:
|
153
|
+
|
154
|
+
<pre syntax="ruby">
|
155
|
+
Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6') # width of 25, spacing of 6
|
156
|
+
Gchart.bar(:data => @data, :bar_width_and_spacing => '25,6,12') # width of 25, spacing of 6, group spacing of 12
|
157
|
+
Gchart.bar(:data => @data, :bar_width_and_spacing => [25,6]) # width of 25, spacing of 6
|
158
|
+
Gchart.bar(:data => @data, :bar_width_and_spacing => 25) # width of 25
|
159
|
+
</pre>
|
160
|
+
|
161
|
+
The hash lets you set these values directly, with the Google default values set for any options you don't include:
|
162
|
+
|
163
|
+
<pre syntax="ruby">
|
164
|
+
Gchart.bar(:data => @data, :bar_width_and_spacing => {:width => 19})
|
165
|
+
Gchart.bar(:data => @data, :bar_width_and_spacing => {:spacing => 10, :group_spacing => 12})
|
166
|
+
</pre>
|
167
|
+
|
148
168
|
|
149
169
|
*pie chart*
|
150
170
|
|
@@ -453,3 +473,4 @@ Comments are welcome. Send an email to "Matt Aimonetti":mailto:mattaimonetti@gma
|
|
453
473
|
h3. Contributors
|
454
474
|
|
455
475
|
"David Grandinetti":http://github.com/dbgrandi
|
476
|
+
"Toby Sterrett":http://github.com/takeo
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: googlecharts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Aimonetti
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
ZR7qHIpykzr3ezcNiWtBWw==
|
31
31
|
-----END CERTIFICATE-----
|
32
32
|
|
33
|
-
date: 2008-05-
|
33
|
+
date: 2008-05-08 00:00:00 -07:00
|
34
34
|
default_executable:
|
35
35
|
dependencies: []
|
36
36
|
|
metadata.gz.sig
CHANGED
Binary file
|