gchartrb 0.6 → 0.7
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/History.txt +6 -0
- data/Rakefile +1 -1
- data/TODO +1 -1
- data/lib/google_chart/bar_chart.rb +1 -1
- data/lib/google_chart/base.rb +75 -15
- data/lib/test.rb +26 -0
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 0.7 / 2008-02-04
|
2
|
+
|
3
|
+
* Added fill area feature
|
4
|
+
* Added to_escaped_url method for encoding the URLs properly
|
5
|
+
* Fixed bug where wrong variable name was being used in method
|
6
|
+
|
1
7
|
== 0.6 / 2008-01-27
|
2
8
|
|
3
9
|
* Added experimental support for undocumented Financial Line Chart (lfi)
|
data/Rakefile
CHANGED
@@ -8,7 +8,7 @@ class Hoe
|
|
8
8
|
def extra_deps; @extra_deps.reject { |x| Array(x).first == "hoe" } end
|
9
9
|
end # copied from the Rakefile of the sup project
|
10
10
|
|
11
|
-
Hoe.new('gchartrb', "0.
|
11
|
+
Hoe.new('gchartrb', "0.7") do |p|
|
12
12
|
p.rubyforge_name = 'gchartrb'
|
13
13
|
p.author = 'Deepak Jois'
|
14
14
|
p.email = 'deepak.jois@gmail.com'
|
data/TODO
CHANGED
data/lib/google_chart/base.rb
CHANGED
@@ -74,25 +74,30 @@ module GoogleChart
|
|
74
74
|
# lc.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
|
75
75
|
# puts lc.to_url({:chm => "000000,0,0.1,0.11"}) # Single black line as a horizontal marker
|
76
76
|
def to_url(extras={})
|
77
|
-
|
78
|
-
set_size
|
79
|
-
set_type
|
80
|
-
set_colors
|
81
|
-
set_fill_options
|
82
|
-
add_axis unless @axis.empty?
|
83
|
-
add_grid
|
84
|
-
add_data
|
85
|
-
add_line_styles unless @line_styles.empty?
|
86
|
-
set_bar_width_spacing_options if @bar_width_spacing_options
|
87
|
-
add_markers unless @markers.empty?
|
88
|
-
add_labels(@labels) if [:p, :p3].member?(self.chart_type)
|
89
|
-
add_legend(@labels) if show_legend
|
90
|
-
add_title if chart_title.to_s.length > 0
|
91
|
-
|
77
|
+
prepare_params
|
92
78
|
params.merge!(extras)
|
93
79
|
query_string = params.map { |k,v| "#{k}=#{URI.escape(v.to_s).gsub(/%20/,'+').gsub(/%7C/,'|')}" }.join('&')
|
94
80
|
BASE_URL + query_string
|
95
81
|
end
|
82
|
+
|
83
|
+
# Generates a fully encoded URL string that can be used to retrieve the graph image in PNG format.
|
84
|
+
# For less verbose URLs, use the <tt>to_url</tt> method. Use this only if you are doing further
|
85
|
+
# processing with the URLs, like passing the URL to a method for downloading the images
|
86
|
+
#
|
87
|
+
# Use this after assigning all the properties to the graph
|
88
|
+
# You can pass in additional params as a hash for features that may not have been implemented
|
89
|
+
# For e.g
|
90
|
+
# lc = GoogleChart::LineChart.new('320x200', "Line Chart", false)
|
91
|
+
# lc.data "Trend 1", [5,4,3,1,3,5,6], '0000ff'
|
92
|
+
# lc.data "Trend 2", [1,2,3,4,5,6], '00ff00'
|
93
|
+
# lc.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
|
94
|
+
# puts lc.to_escaped_url({:chm => "000000,0,0.1,0.11"}) # Single black line as a horizontal marker
|
95
|
+
def to_escaped_url(extras={})
|
96
|
+
prepare_params
|
97
|
+
params.merge!(extras)
|
98
|
+
query_string = params.map { |k,v| "#{k}=#{URI.escape(v.to_s)}" }.join('&')
|
99
|
+
BASE_URL + query_string
|
100
|
+
end
|
96
101
|
|
97
102
|
# Adds the data to the chart, according to the type of the graph being generated.
|
98
103
|
#
|
@@ -248,8 +253,63 @@ module GoogleChart
|
|
248
253
|
shape_marker_str = "#{SHAPE_MARKERS[type]},#{options[:color]},#{options[:data_set_index]},#{options[:data_point_index]},#{options[:pixel_size]}"
|
249
254
|
@markers << shape_marker_str
|
250
255
|
end
|
256
|
+
|
257
|
+
# Defines a Fill area. Applicable for line charts only
|
258
|
+
#
|
259
|
+
# [+color+] is the color of the fill area
|
260
|
+
# [+start_index+] is the index of the line at which the fill starts. This is 0 for the first data set, 1 for the second and so on.
|
261
|
+
# [+end_index+] is the index of the line at which the fill ends.
|
262
|
+
#
|
263
|
+
# ==== Examples
|
264
|
+
# # Fill Area (Multiple Datasets)
|
265
|
+
# lc = GoogleChart::LineChart.new('320x200', "Line Chart", false) do |lc|
|
266
|
+
# lc.show_legend = false
|
267
|
+
# lc.data "Trend 1", [5,5,6,5,5], 'ff0000'
|
268
|
+
# lc.data "Trend 2", [3,3,4,3,3], '00ff00'
|
269
|
+
# lc.data "Trend 3", [1,1,2,1,1], '0000ff'
|
270
|
+
# lc.data "Trend 4", [0,0,0,0,0], 'ffffff'
|
271
|
+
# lc.fill_area '0000ff',2,3
|
272
|
+
# lc.fill_area '00ff00',1,2
|
273
|
+
# lc.fill_area 'ff0000',0,1
|
274
|
+
# end
|
275
|
+
# puts "\nFill Area (Multiple Datasets)"
|
276
|
+
# puts lc.to_url
|
277
|
+
#
|
278
|
+
# # Fill Area (Single Dataset)
|
279
|
+
# lc = GoogleChart::LineChart.new('320x200', "Line Chart", false) do |lc|
|
280
|
+
# lc.show_legend = false
|
281
|
+
# lc.data "Trend 1", [5,5,6,5,5], 'ff0000'
|
282
|
+
# lc.fill_area 'cc6633', 0, 0
|
283
|
+
# end
|
284
|
+
# puts "\nFill Area (Single Dataset)"
|
285
|
+
# puts lc.to_url
|
286
|
+
#
|
287
|
+
def fill_area(color, start_index, end_index)
|
288
|
+
if (start_index == 0 and end_index == 0)
|
289
|
+
@markers << "B,#{color},0,0,0"
|
290
|
+
else
|
291
|
+
@markers << "b,#{color},#{start_index},#{end_index},0"
|
292
|
+
end
|
293
|
+
end
|
251
294
|
|
252
295
|
protected
|
296
|
+
|
297
|
+
def prepare_params
|
298
|
+
params.clear
|
299
|
+
set_size
|
300
|
+
set_type
|
301
|
+
set_colors
|
302
|
+
set_fill_options
|
303
|
+
add_axis unless @axis.empty?
|
304
|
+
add_grid
|
305
|
+
add_data
|
306
|
+
add_line_styles unless @line_styles.empty?
|
307
|
+
set_bar_width_spacing_options if @bar_width_spacing_options
|
308
|
+
add_markers unless @markers.empty?
|
309
|
+
add_labels(@labels) if [:p, :p3].member?(self.chart_type)
|
310
|
+
add_legend(@labels) if show_legend
|
311
|
+
add_title if chart_title.to_s.length > 0
|
312
|
+
end
|
253
313
|
|
254
314
|
def process_fill_options(type, options)
|
255
315
|
case type
|
data/lib/test.rb
CHANGED
@@ -174,3 +174,29 @@ lc = GoogleChart::LineChart.new('320x200', "Line Chart", false) do |lc|
|
|
174
174
|
end
|
175
175
|
puts "\nLine Styles"
|
176
176
|
puts lc.to_url
|
177
|
+
|
178
|
+
puts "\nLine Styles (encoded URL)"
|
179
|
+
puts lc.to_escaped_url
|
180
|
+
|
181
|
+
# Fill Area (Multiple Datasets)
|
182
|
+
lc = GoogleChart::LineChart.new('320x200', "Line Chart", false) do |lc|
|
183
|
+
lc.show_legend = false
|
184
|
+
lc.data "Trend 1", [5,5,6,5,5], 'ff0000'
|
185
|
+
lc.data "Trend 2", [3,3,4,3,3], '00ff00'
|
186
|
+
lc.data "Trend 3", [1,1,2,1,1], '0000ff'
|
187
|
+
lc.data "Trend 4", [0,0,0,0,0], 'ffffff'
|
188
|
+
lc.fill_area '0000ff',2,3
|
189
|
+
lc.fill_area '00ff00',1,2
|
190
|
+
lc.fill_area 'ff0000',0,1
|
191
|
+
end
|
192
|
+
puts "\nFill Area (Multiple Datasets)"
|
193
|
+
puts lc.to_url
|
194
|
+
|
195
|
+
# Fill Area (Single Datasets)
|
196
|
+
lc = GoogleChart::LineChart.new('320x200', "Line Chart", false) do |lc|
|
197
|
+
lc.show_legend = false
|
198
|
+
lc.data "Trend 1", [5,5,6,5,5], 'ff0000'
|
199
|
+
lc.fill_area 'cc6633', 0, 0
|
200
|
+
end
|
201
|
+
puts "\nFill Area (Single Dataset)"
|
202
|
+
puts lc.to_url
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gchartrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.7"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Deepak Jois
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-02-04 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|