gchartrb 0.4.1 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +1 -0
- data/README.txt +9 -1
- data/Rakefile +1 -1
- data/TODO +0 -1
- data/lib/google_chart/base.rb +23 -1
- data/lib/google_chart/line_chart.rb +25 -20
- data/lib/google_chart/scatter_chart.rb +37 -0
- data/lib/google_chart/venn_diagram.rb +1 -1
- data/lib/google_chart.rb +2 -1
- data/lib/test.rb +14 -0
- metadata +2 -1
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
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.
|
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
data/lib/google_chart/base.rb
CHANGED
@@ -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 (
|
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
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.
|
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: []
|