gchartrb 0.6 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.6") do |p|
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
@@ -2,7 +2,7 @@ TODO List (Features)
2
2
  ====================
3
3
  * Line Styles DONE
4
4
  * Customisable Width for bar charts DONE
5
- * Fill Area
5
+ * Fill Area DONE
6
6
  * Download Image
7
7
 
8
8
  * Friendly Color Values
@@ -29,7 +29,7 @@ module GoogleChart
29
29
  end
30
30
 
31
31
  # If you want the bar chart to be stacked, set the value to <tt>true</tt>, otherwise set the value to <tt>false</tt> to group it.
32
- def stacked=(stacked)
32
+ def stacked=(value)
33
33
  @stacked = value
34
34
  set_chart_type
35
35
  end
@@ -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
- params.clear
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
@@ -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.6"
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-01-27 00:00:00 +08:00
12
+ date: 2008-02-04 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15