gchartrb 0.4.1 → 0.5

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,8 @@
1
+ == 0.5
2
+
3
+ * Added Scatter Chart Support
4
+ * Documentation Updates
5
+
1
6
  == 0.4.1
2
7
 
3
8
  * Removed some spurious debug statements
data/Manifest.txt CHANGED
@@ -9,5 +9,6 @@ lib/google_chart/bar_chart.rb
9
9
  lib/google_chart/base.rb
10
10
  lib/google_chart/line_chart.rb
11
11
  lib/google_chart/pie_chart.rb
12
+ lib/google_chart/scatter_chart.rb
12
13
  lib/google_chart/venn_diagram.rb
13
14
  lib/test.rb
data/README.txt CHANGED
@@ -95,7 +95,15 @@ However, you can still make use of the API to insert arbitrary parameters
95
95
  vd.data "Red", 60, 'ff0000'
96
96
  vd.intersections 30,30,30,10
97
97
  puts vd.to_url
98
-
98
+
99
+ # Scatter Chart
100
+ sc = GoogleChart::ScatterChart.new('320x200',"Scatter Chart")
101
+ sc.data "Scatter Set", [[1,1,], [2,2], [3,3], [4,4]]
102
+ sc.axis :x, :range => [0,4]
103
+ sc.axis :y, :range => [0,4]
104
+ sc.point_sizes [10,15,30,55] # Optional
105
+ puts sc.to_url
106
+
99
107
  # Solid fill
100
108
  lc.fill(:background, :solid, {:color => 'fff2cc'})
101
109
  lc.fill(:chart, :solid, {:color => 'ffcccc'})
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.4.1") do |p|
11
+ Hoe.new('gchartrb', "0.5") 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
@@ -4,7 +4,6 @@ TODO List (Features)
4
4
  * Line Styles
5
5
  * Fill Area
6
6
  * Handle Missing Values (?)
7
- * Other charts (Scatter)
8
7
  * Download image
9
8
  * Friendly color values
10
9
  * Helper methods for standard chart types like Sparklines etc.
@@ -127,7 +127,7 @@ module GoogleChart
127
127
  @axis << [type, options]
128
128
  end
129
129
 
130
- # Adds a grid to the graph. Applicable only for Line Chart (GoogleChart::LineChart) and Scatter Chart (available soon)
130
+ # Adds a grid to the graph. Applicable only for Line Chart (GoogleChart::LineChart) and Scatter Chart (GoogleChart::ScatterChart)
131
131
  #
132
132
  # [+options+] is a hash containing the options (see below)
133
133
  #
@@ -330,5 +330,27 @@ module GoogleChart
330
330
  def join_encoded_data(encoded_data)
331
331
  encoded_data.join((self.data_encoding == :simple) ? "," : "|")
332
332
  end
333
+
334
+ ## Applicable to Line Charts and Scatter Charts only
335
+
336
+ def max_x_value
337
+ x_data.flatten.max
338
+ end
339
+
340
+ def max_y_value
341
+ y_data.flatten.max
342
+ end
343
+
344
+ def x_data
345
+ @data.collect do |series|
346
+ series.collect { |val| val.first }
347
+ end
348
+ end
349
+
350
+ def y_data
351
+ @data.collect do |series|
352
+ series.collect { |val| val.last }
353
+ end
354
+ end
333
355
  end
334
356
  end
@@ -1,13 +1,38 @@
1
1
  require File.dirname(__FILE__) + '/base'
2
2
  module GoogleChart
3
+
4
+ # Generates a Line chart. An option can be passed that allows you to create a Line XY Chart
5
+ #
6
+ # ==== Examples
7
+ #
8
+ # # Line Chart
9
+ # lc = GoogleChart::LineChart.new('320x200', "Line Chart", false)
10
+ # lc.data "Trend 1", [5,4,3,1,3,5,6], '0000ff'
11
+ # lc.data "Trend 2", [1,2,3,4,5,6], '00ff00'
12
+ # lc.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
13
+ # lc.axis :y, :range => [0,6], :color => 'ff00ff', :font_size => 16, :alignment => :center
14
+ # lc.axis :x, :range => [0,6], :color => '00ffff', :font_size => 16, :alignment => :center
15
+ #
16
+ # # Line XY Chart
17
+ # lcxy = GoogleChart::LineChart.new('320x200', "Line XY Chart", true)
18
+ # lcxy.data "Trend 1", [[1,1], [2,2], [3,3], [4,4]], '0000ff'
19
+ # lcxy.data "Trend 2", [[4,5], [2,2], [1,1], [3,4]], '00ff00'
20
+ # puts lcxy.to_url
3
21
  class LineChart < Base
4
22
  attr_accessor :is_xy
5
23
 
24
+ # Specify the
25
+ # * +chart_size+ in WIDTHxHEIGHT format
26
+ # * +chart_title+ as a string
27
+ # * +is_xy+ is <tt>false</tt> by default. Set it to <tt>true</tt> if you want to plot a Line XY chart
6
28
  def initialize(chart_size='300x200', chart_title=nil, is_xy=false)
7
29
  super(chart_size, chart_title)
8
30
  self.is_xy = is_xy
9
31
  end
10
32
 
33
+ # Pass in <tt>true</tt> here to create a Line XY.
34
+ #
35
+ # Note: This must be done before passing in any data to the chart
11
36
  def is_xy=(value)
12
37
  @is_xy = value
13
38
  if value
@@ -17,26 +42,6 @@ module GoogleChart
17
42
  end
18
43
  end
19
44
 
20
- def max_x_value
21
- x_data.flatten.max
22
- end
23
-
24
- def max_y_value
25
- y_data.flatten.max
26
- end
27
-
28
- def x_data
29
- @data.collect do |series|
30
- series.collect { |val| val.first }
31
- end
32
- end
33
-
34
- def y_data
35
- @data.collect do |series|
36
- series.collect { |val| val.last }
37
- end
38
- end
39
-
40
45
  def process_data
41
46
  if self.is_xy or @data.size > 1
42
47
  if self.is_xy # XY Line graph data series
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/base'
2
+ module GoogleChart
3
+
4
+ # Generates a Scatter chart.
5
+ #
6
+ # ==== Example
7
+ # sc = GoogleChart::ScatterChart.new('320x200',"Scatter Chart")
8
+ # sc.data "Scatter Set", [[1,1,], [2,2], [3,3], [4,4]]
9
+ # sc.point_sizes [10,15,30,55]
10
+ # puts sc.to_url
11
+ class ScatterChart < Base
12
+
13
+ # Initializes the Venn Diagram with a +chart_size+ (in WIDTHxHEIGHT format) and a +chart_title+
14
+ def initialize(chart_size='300x200', chart_title=nil)
15
+ super(chart_size, chart_title)
16
+ self.chart_type = :s
17
+ self.show_legend = false
18
+ @point_sizes = []
19
+ end
20
+
21
+ def process_data
22
+ # Interleave X and Y co-ordinate data
23
+ encoded_data = join_encoded_data([encode_data(x_data[0],max_x_value), encode_data(y_data[0],max_y_value)])
24
+ # Add point sizes data if it exists
25
+ unless @point_sizes.empty?
26
+ encoded_data = join_encoded_data([encoded_data, encode_data(@point_sizes)])
27
+ end
28
+ return encoded_data
29
+ end
30
+
31
+ # Specify the data point sizes of the Scatter chart (optional). The data point sizes are scaled with this data set.
32
+ def point_sizes(values)
33
+ @point_sizes = values
34
+ end
35
+
36
+ end
37
+ end
@@ -16,7 +16,7 @@ module GoogleChart
16
16
  # puts vd.to_url
17
17
  class VennDiagram < Base
18
18
 
19
- # Initializes the Venn Diagram with a +chart_size+ and a +chart_title+
19
+ # Initializes the Venn Diagram with a +chart_size+ (in WIDTHxHEIGHT format) and a +chart_title+
20
20
  def initialize(chart_size='300x200', chart_title=nil)
21
21
  super(chart_size, chart_title)
22
22
  self.chart_type = :v
data/lib/google_chart.rb CHANGED
@@ -3,7 +3,8 @@
3
3
  pie_chart
4
4
  line_chart
5
5
  bar_chart
6
- venn_diagram
6
+ venn_diagram
7
+ scatter_chart
7
8
  ).each do |filename|
8
9
  require File.dirname(__FILE__) + "/google_chart/#{filename}"
9
10
  end
data/lib/test.rb CHANGED
@@ -6,6 +6,7 @@ pc.data "Apples", 40
6
6
  pc.data "Banana", 20
7
7
  pc.data "Peach", 30
8
8
  pc.data "Orange", 60
9
+ puts "Pie Chart"
9
10
  puts pc.to_url
10
11
 
11
12
  # Line Chart
@@ -18,6 +19,7 @@ lc.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
18
19
  lc.axis :y, :range => [0,6], :color => 'ff00ff', :font_size => 16, :alignment => :center
19
20
  lc.axis :x, :range => [0,6], :color => '00ffff', :font_size => 16, :alignment => :center
20
21
  lc.grid :x_step => 100.0/6.0, :y_step => 100.0/6.0, :length_segment => 1, :length_blank => 0
22
+ puts "Line Chart"
21
23
  puts lc.to_url
22
24
 
23
25
  # Bar Chart
@@ -25,12 +27,14 @@ bc = GoogleChart::BarChart.new('800x200', "Bar Chart", :vertical, false)
25
27
  bc.data "Trend 1", [5,4,3,1,3,5], '0000ff'
26
28
  bc.data "Trend 2", [1,2,3,4,5,6], 'ff0000'
27
29
  bc.data "Trend 3", [6,5,4,4,5,6], '00ff00'
30
+ puts "Bar Chart"
28
31
  puts bc.to_url
29
32
 
30
33
  # Line XY Chart
31
34
  lcxy = GoogleChart::LineChart.new('320x200', "Line XY Chart", true)
32
35
  lcxy.data "Trend 1", [[1,1], [2,2], [3,3], [4,4]], '0000ff'
33
36
  lcxy.data "Trend 2", [[4,5], [2,2], [1,1], [3,4]], '00ff00'
37
+ puts "Line XY Chart"
34
38
  puts lcxy.to_url
35
39
 
36
40
  # Venn Diagram
@@ -45,8 +49,18 @@ vd.data "Blue", 100, '0000ff'
45
49
  vd.data "Green", 80, '00ff00'
46
50
  vd.data "Red", 60, 'ff0000'
47
51
  vd.intersections 30,30,30,10
52
+ puts "Venn Diagram"
48
53
  puts vd.to_url
49
54
 
55
+ # Scatter Chart
56
+ sc = GoogleChart::ScatterChart.new('320x200',"Scatter Chart")
57
+ sc.data "Scatter Set", [[1,1,], [2,2], [3,3], [4,4]]
58
+ sc.axis :x, :range => [0,4]
59
+ sc.axis :y, :range => [0,4]
60
+ sc.point_sizes [10,15,30,55] # Optional
61
+ puts "Scatter Chart"
62
+ puts sc.to_url
63
+
50
64
  # Solid fill
51
65
  lc.fill(:background, :solid, {:color => 'fff2cc'})
52
66
  lc.fill(:chart, :solid, {:color => 'ffcccc'})
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: gchartrb
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.4.1
6
+ version: "0.5"
7
7
  date: 2007-12-12 00:00:00 +08:00
8
8
  summary: Ruby Wrapper for the Google Chart API
9
9
  require_paths:
@@ -40,6 +40,7 @@ files:
40
40
  - lib/google_chart/base.rb
41
41
  - lib/google_chart/line_chart.rb
42
42
  - lib/google_chart/pie_chart.rb
43
+ - lib/google_chart/scatter_chart.rb
43
44
  - lib/google_chart/venn_diagram.rb
44
45
  - lib/test.rb
45
46
  test_files: []