gchartrb 0.5.1 → 0.5.2

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 CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.5.2 / 2007-12-14
2
+
3
+ * Added support for title color via title_color attribute
4
+ * Added support for vertical and horizontal range markers using the range_marker method
5
+ * Removed show_labels from base.rb and added it only for pie charts
6
+
1
7
  == 0.5.1 / 2007-12-12
2
8
 
3
9
  * Added support for max_value method to specify maximum values to plot against
data/README.txt CHANGED
@@ -36,12 +36,13 @@ The following features are pending :
36
36
 
37
37
  However, you can still make use of the API to insert arbitrary parameters
38
38
 
39
- # Adding Extra params
40
- lc = GoogleChart::LineChart.new('320x200', "Line Chart", false)
41
- lc.data "Trend 1", [5,4,3,1,3,5,6], '0000ff'
42
- lc.data "Trend 2", [1,2,3,4,5,6], '00ff00'
43
- lc.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
44
- puts lc.to_url({:chm => "r,000000,0,0.1,0.5"}) # Single black line as a horizontal marker by inserting arbitrary param
39
+ # Plotting a sparklines chart (using extra params)
40
+ sparklines = GoogleChart::LineChart.new('100x50', nil, false)
41
+ sparklines.data "Test", [4,3,2,4,6,8,10]
42
+ sparklines.show_legend = false
43
+ sparklines.axis :x, :labels => [] # Empty labels
44
+ sparklines.axis :y, :labels => [] # Empty labels
45
+ puts sparklines.to_url(:chxs => "0,000000,10,0,_|1,000000,10,0,_")
45
46
 
46
47
  == SYNOPSIS:
47
48
 
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.5.1") do |p|
11
+ Hoe.new('gchartrb', "0.5.2") do |p|
12
12
  p.rubyforge_name = 'gchartrb'
13
13
  p.author = 'Deepak Jois'
14
14
  p.email = 'deepak.jois@gmail.com'
@@ -19,4 +19,25 @@ Hoe.new('gchartrb', "0.5.1") do |p|
19
19
  p.remote_rdoc_dir = ''
20
20
  end
21
21
 
22
+
23
+ RDOC_OPTS = [
24
+ '--quiet',
25
+ '--title', 'gchartrb API',
26
+ '--main', 'README.txt',
27
+ '--charset', 'utf-8',
28
+ '--inline-source',
29
+ '--tab-width', '2',
30
+ '--line-numbers',
31
+ ]
32
+
33
+ Rake::RDocTask.new do |rdoc|
34
+ rdoc.rdoc_dir = 'doc/'
35
+ rdoc.options = RDOC_OPTS
36
+ rdoc.main = "README.txt"
37
+ rdoc.rdoc_files.add [
38
+ 'README.txt',
39
+ 'History.txt',
40
+ 'lib/**/*.rb'
41
+ ]
42
+ end
22
43
  # vim: syntax=Ruby
data/lib/example.rb CHANGED
@@ -56,9 +56,6 @@ series_2_x.each_with_index do |v,i|
56
56
  series_2_xy[i] = [v-1, series_2_y[i ] ]
57
57
  end
58
58
 
59
- puts series_1_xy.inspect
60
- puts series_2_xy.inspect
61
-
62
59
  lcxy = GoogleChart::LineChart.new('800x300', "Projected Christmas Cheer for 2007", true)
63
60
  lcxy.data "2006", series_1_xy, '458B00'
64
61
  lcxy.data "2007", series_2_xy, 'CD2626'
@@ -68,3 +65,14 @@ lcxy.axis :x, :labels => x_axis_labels
68
65
  lcxy.axis :y, :labels => y_axis_labels
69
66
  lcxy.grid :x_step => 3.333, :y_step => 10, :length_segment => 1, :length_blank => 3
70
67
  puts lcxy.to_url
68
+
69
+
70
+ # Plotting a sparklines chart
71
+ sparklines = GoogleChart::LineChart.new('100x40', nil, false)
72
+ sparklines.data "Test", [4,3,2,4,6,8,10]
73
+ sparklines.show_legend = false
74
+ sparklines.axis :x, :labels => []
75
+ sparklines.axis :y, :labels => []
76
+ puts sparklines.to_url(:chxs => "0,000000,10,0,_|1,000000,10,0,_")
77
+
78
+
@@ -18,7 +18,6 @@ module GoogleChart
18
18
  @alignment = alignment
19
19
  @stacked = stacked
20
20
  set_chart_type
21
- self.show_labels = false
22
21
  self.show_legend = true
23
22
  end
24
23
 
@@ -13,19 +13,41 @@ module GoogleChart
13
13
  end
14
14
  end
15
15
 
16
- attr_accessor :chart_size, :chart_type, :chart_title, :data_encoding, :params, :show_legend, :show_labels
17
-
16
+ # Size of the chart in WIDTHxHEIGHT format
17
+ attr_accessor :chart_size
18
+
19
+ # Type of the chart. Usually, you do not need to set this yourself
20
+ attr_accessor :chart_type
21
+
22
+ # Chart title
23
+ attr_accessor :chart_title
24
+
25
+ # RRGGBB hex value for the color of the title
26
+ attr_accessor :title_color
27
+
28
+ # Font size of the title
29
+ attr_accessor :title_font_size
30
+
31
+ # Data encoding to use. Can be one of <tt>:simple</tt>, <tt>:text</tt> or <tt>:extended</tt> (see http://code.google.com/apis/chart/#chart_data)
32
+ attr_accessor :data_encoding
33
+
34
+ # A hash of the params used to construct the URL
35
+ attr_accessor :params
36
+
37
+ # Set to <tt>true</tt> or <tt>false</tt> to show or hide the chart legend. Not applicable for Scatter Chart.
38
+ attr_accessor :show_legend
39
+
18
40
  def initialize(chart_size, chart_title)
19
41
  self.params = Hash.new
20
42
  @labels = []
21
43
  @data = []
22
44
  @colors = []
23
45
  @axis = []
46
+ @range_markers = []
24
47
  self.chart_size = chart_size
25
48
  self.chart_title = chart_title
26
49
  self.data_encoding = :simple
27
50
  self.show_legend = true
28
- self.show_labels = false
29
51
  end
30
52
 
31
53
  # Generates the URL string that can be used to retrieve the graph image in PNG format.
@@ -43,10 +65,11 @@ module GoogleChart
43
65
  set_type
44
66
  set_colors
45
67
  set_fill_options
46
- add_axis
68
+ add_axis unless @axis.empty?
47
69
  add_grid
48
70
  add_data
49
- add_labels(@labels) if show_labels
71
+ add_range_markers unless @range_markers.empty?
72
+ add_labels(@labels) if [:p, :p3].member?(self.chart_type)
50
73
  add_legend(@labels) if show_legend
51
74
  add_title if chart_title.to_s.length > 0
52
75
 
@@ -111,11 +134,11 @@ module GoogleChart
111
134
  # * A <tt>:color</tt> option which specifies the RGB hex value of the color to be used as a fill. For e.g <tt>lc.fill(:chart, :solid, {:color => 'ffcccc'})</tt>
112
135
  #
113
136
  # For <tt>:gradient</tt> type
114
- # * An <tt>:angle</p>, which is the angle of the gradient between 0(horizontal) and 90(vertical)
137
+ # * An <tt>:angle</tt>, which is the angle of the gradient between 0(horizontal) and 90(vertical)
115
138
  # * A <tt>:color</tt> option which is a 2D array containing the colors and an offset each, which specifies at what point the color is pure where: 0 specifies the right-most chart position and 1 the left-most. e,g <tt>lc.fill :background, :gradient, :angle => 0, :color => [['76A4FB',1],['ffffff',0]]</tt>
116
139
  #
117
140
  # For <tt>:stripes</tt> type
118
- # * An <tt>:angle</p>, which is the angle of the stripe between 0(horizontal) and 90(vertical)
141
+ # * An <tt>:angle</tt>, which is the angle of the stripe between 0(horizontal) and 90(vertical)
119
142
  # * A <tt>:color</tt> option which is a 2D array containing the colors and width value each, which must be between 0 and 1 where 1 is the full width of the chart. for e.g <tt>lc.fill :chart, :stripes, :angle => 90, :color => [ ['76A4FB',0.2], ['ffffff',0.2] ]</tt>
120
143
  def fill(bg_or_c, type, options = {})
121
144
  case bg_or_c
@@ -162,13 +185,32 @@ module GoogleChart
162
185
  #
163
186
  # === Examples
164
187
  # lc.grid :x_step => 5, :y_step => 5, :length_segment => 1, :length_blank => 0
165
- #
166
-
188
+ #
167
189
  def grid(options={})
168
190
  @grid_str = "#{options[:x_step].to_f},#{options[:y_step].to_f}"
169
191
  if options[:length_segment] or options[:length_blank]
170
192
  @grid_str += ",#{options[:length_segment].to_f},#{options[:length_blank].to_f}"
171
193
  end
194
+ end
195
+
196
+ # Defines a horizontal or vertical range marker. Applicable for line charts and vertical charts
197
+ #
198
+ # [+alignment+] can be <tt>:horizontal</tt> or <tt>:vertical</tt>
199
+ # [+options+] specifies the color, start point and end point
200
+ #
201
+ # ==== Options
202
+ # [<tt>:color</tt>] RRGGBB hex value for the color of the range marker
203
+ # [<tt>:start_point</tt>] position on the x-axis/y-axis at which the range starts where 0.00 is the left/bottom and 1.00 is the right/top
204
+ # [<tt>:end_point</tt>] position on the x-axis/y-axis at which the range ends where 0.00 is the left/bottom and 1.00 is the right/top
205
+ #
206
+ # ==== Examples
207
+ # lc.range_marker :horizontal, :color => 'E5ECF9', :start_point => 0.1, :end_point => 0.5
208
+ # lc.range_marker :vertical, :color => 'a0bae9', :start_point => 0.1, :end_point => 0.5
209
+ def range_marker(alignment, options={})
210
+ raise "Invalid alignment specified" unless [:horizontal, :vertical].member?(alignment)
211
+ str = (alignment == :horizontal ) ? "r" : "R"
212
+ str += ",#{options[:color]},0,#{options[:start_point]},#{options[:end_point]}"
213
+ @range_markers << str
172
214
  end
173
215
 
174
216
  protected
@@ -203,7 +245,7 @@ module GoogleChart
203
245
  end
204
246
 
205
247
  def add_labels(labels)
206
- params.merge!({:chl => labels.collect{|l| l.to_s}.join("|") })
248
+ params.merge!({:chl => labels.collect{|l| l.to_s}.join("|") }) if self.show_labels
207
249
  end
208
250
 
209
251
  def add_legend(labels)
@@ -212,6 +254,7 @@ module GoogleChart
212
254
 
213
255
  def add_title
214
256
  params.merge!({:chtt => chart_title})
257
+ params.merge!({:chts => title_color}) if title_color
215
258
  end
216
259
 
217
260
  def add_axis
@@ -281,6 +324,10 @@ module GoogleChart
281
324
  params.merge!({ :chg => @grid_str }) if @grid_str
282
325
  end
283
326
 
327
+ def add_range_markers
328
+ params.merge!({:chm => @range_markers.join("|")})
329
+ end
330
+
284
331
  def add_data
285
332
  converted_data = process_data
286
333
  case data_encoding
@@ -357,9 +404,7 @@ module GoogleChart
357
404
  def max_data_value
358
405
  @max_data or @data.flatten.max
359
406
  end
360
-
361
- ## Applicable to Line Charts and Scatter Charts only
362
-
407
+
363
408
  def max_x_value
364
409
  @max_x or x_data.flatten.max
365
410
  end
@@ -1,15 +1,19 @@
1
1
  require File.dirname(__FILE__) + '/base'
2
2
  module GoogleChart
3
3
  class PieChart < Base
4
-
4
+
5
+ # set to <tt>true</tt> or <tt>false</tt> to indicate if this is a 3d chart
5
6
  attr_accessor :is_3d
7
+
8
+ # set to <tt>true</tt> or <tt>false</tt> to show or hide pie chart labels
9
+ attr_accessor :show_labels
6
10
 
7
11
  # Initializes a Pie Chart object with a +chart_size+ and +chart_title+. Specify <tt>is_3d</tt> as +true+ to generate a 3D Pie chart
8
12
  def initialize(chart_size='300x200', chart_title=nil, is_3d = false)
9
13
  super(chart_size, chart_title)
10
14
  self.is_3d = is_3d
11
- self.show_labels = true
12
15
  self.show_legend = false
16
+ self.show_labels = true
13
17
  end
14
18
 
15
19
  # Set this value to <tt>true</tt> if you want the Pie Chart to be rendered as a 3D image
data/lib/test.rb CHANGED
@@ -9,11 +9,15 @@ pc.data "Orange", 60
9
9
  puts "\nPie Chart"
10
10
  puts pc.to_url
11
11
 
12
+ # Pie Chart with no labels
13
+ pc.show_labels = false
14
+ puts "\nPie Chart (with no labels)"
15
+ puts pc.to_url
16
+
12
17
  # Line Chart
13
18
  lc = GoogleChart::LineChart.new('320x200', "Line Chart", false)
14
19
  lc.data "Trend 1", [5,4,3,1,3,5,6], '0000ff'
15
- lc.show_legend = true
16
- lc.show_labels = false
20
+ lc.show_legend = true
17
21
  lc.data "Trend 2", [1,2,3,4,5,6], '00ff00'
18
22
  lc.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
19
23
  lc.axis :y, :range => [0,6], :color => 'ff00ff', :font_size => 16, :alignment => :center
@@ -83,12 +87,15 @@ puts lc.to_url
83
87
 
84
88
  # Adding Extra params
85
89
  lc = GoogleChart::LineChart.new('320x200', "Line Chart", false)
90
+ lc.title_color = 'ff00ff'
86
91
  lc.data "Trend 1", [5,4,3,1,3,5,6], '0000ff'
87
92
  lc.data "Trend 2", [1,2,3,4,5,6], '00ff00'
88
93
  lc.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
89
- lc.max_value 10 # Setting max value for simple line chart
90
- puts "\nLine Chart with Horizontal range marker using extra params"
91
- puts lc.to_url({:chm => "r,000000,0,0.1,0.5"}) # Single black region as a horizontal range marker
94
+ lc.max_value 10 # Setting max value for simple line chart
95
+ lc.range_marker :horizontal, :color => 'E5ECF9', :start_point => 0.1, :end_point => 0.5
96
+ lc.range_marker :vertical, :color => 'a0bae9', :start_point => 0.1, :end_point => 0.5
97
+ puts "\nLine Chart with range markers"
98
+ puts lc.to_url
92
99
 
93
100
  # Bryan Error condition
94
101
  lcxy = GoogleChart::LineChart.new('320x200', "Line XY Chart", true)
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: gchartrb
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.1
7
- date: 2007-12-12 00:00:00 +08:00
6
+ version: 0.5.2
7
+ date: 2007-12-14 00:00:00 +08:00
8
8
  summary: Ruby Wrapper for the Google Chart API
9
9
  require_paths:
10
10
  - lib