gchartrb 0.3.0 → 0.4.0
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/CREDITS +2 -1
- data/History.txt +9 -0
- data/Rakefile +1 -1
- data/TODO +5 -4
- data/lib/google_chart/base.rb +21 -6
- data/lib/google_chart/line_chart.rb +58 -69
- data/lib/test.rb +8 -0
- metadata +2 -2
data/CREDITS
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
Will Fitzgerald - http://www.entish.org/willwhim
|
1
|
+
Will Fitzgerald - http://www.entish.org/willwhim
|
2
|
+
Bryan Donovan
|
data/History.txt
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
== 0.4
|
2
|
+
|
3
|
+
* Fixed issue when all data points are 0 in Line XY Chart (Thanks Cedric)
|
4
|
+
* Proper calculation of max values for Line XY chart (Thanks Bryan Donovan)
|
5
|
+
|
6
|
+
== 0.3 / 2007-12-11
|
7
|
+
|
8
|
+
* Google changed Pie chart implementation to disable legends. Fixed in API.
|
9
|
+
|
1
10
|
== 0.2 / 2007-12-11
|
2
11
|
|
3
12
|
* Removed hoe dependency
|
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.4.0") 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
@@ -1,13 +1,13 @@
|
|
1
1
|
TODO List (Features)
|
2
2
|
====================
|
3
|
-
* Axis labels
|
4
|
-
* Grid lines
|
5
3
|
* Markers
|
6
4
|
* Line Styles
|
7
5
|
* Fill Area
|
8
6
|
* Handle Missing Values (?)
|
9
7
|
* Other charts (Scatter)
|
10
8
|
* Download image
|
9
|
+
* Friendly color values
|
10
|
+
* Helper methods for standard chart types like Sparklines etc.
|
11
11
|
|
12
12
|
TODO List (Other)
|
13
13
|
=================
|
@@ -15,9 +15,10 @@ TODO List (Other)
|
|
15
15
|
|
16
16
|
Code Level Improvements
|
17
17
|
=======================
|
18
|
+
* Automate upload to google code
|
18
19
|
* Write tests that render different kinds of graphs
|
19
|
-
* Remove the need for core_ext.rb file (stupid idea I was trying out earlier)
|
20
20
|
* Use splats instead of attribute accessors to provide a neater API (?)
|
21
|
+
* Clean up encoding, especially the handling of 'missing' values
|
21
22
|
* Improved error handling and reporting for things
|
22
|
-
* Number of labels and number of postions in axis must be the same
|
23
|
+
* Number of labels and number of postions in axis must be the same (?)
|
23
24
|
* Axis styles need to be specified in a certain way
|
data/lib/google_chart/base.rb
CHANGED
@@ -276,11 +276,11 @@ module GoogleChart
|
|
276
276
|
def encode_data(values, max_value=nil)
|
277
277
|
case data_encoding
|
278
278
|
when :simple
|
279
|
-
simple_encode(values)
|
279
|
+
simple_encode(values, max_value)
|
280
280
|
when :text
|
281
|
-
text_encode(values)
|
281
|
+
text_encode(values, max_value)
|
282
282
|
when :extended
|
283
|
-
extended_encode(values)
|
283
|
+
extended_encode(values, max_value)
|
284
284
|
else
|
285
285
|
raise "Illegal Encoding Specified"
|
286
286
|
end
|
@@ -291,8 +291,13 @@ module GoogleChart
|
|
291
291
|
max_value = values.max unless max_value
|
292
292
|
|
293
293
|
chart_data = values.collect do |val|
|
294
|
-
if val.to_i >=0
|
294
|
+
if val.to_i >=0
|
295
|
+
puts max_value
|
296
|
+
if max_value == 0
|
297
|
+
SIMPLE_ENCODING[0]
|
298
|
+
else
|
295
299
|
SIMPLE_ENCODING[(alphabet_length * val / max_value).to_i]
|
300
|
+
end
|
296
301
|
else
|
297
302
|
"_"
|
298
303
|
end
|
@@ -304,13 +309,23 @@ module GoogleChart
|
|
304
309
|
def text_encode(values, max_value=nil)
|
305
310
|
max_value = values.max unless max_value
|
306
311
|
values.inject("") { |sum, v|
|
307
|
-
|
312
|
+
if max_value == 0
|
313
|
+
sum += "0,"
|
314
|
+
else
|
315
|
+
sum += ( "%.1f" % (v*100/max_value) ) + ","
|
316
|
+
end
|
308
317
|
}.chomp(",")
|
309
318
|
end
|
310
319
|
|
311
320
|
def extended_encode(values, max_value)
|
312
321
|
max_value = values.max unless max_value
|
313
|
-
values.collect { |v|
|
322
|
+
values.collect { |v|
|
323
|
+
if max_value == 0
|
324
|
+
@@complex_encoding[0]
|
325
|
+
else
|
326
|
+
@@complex_encoding[(v * 4095/max_value).to_i]
|
327
|
+
end
|
328
|
+
}.join('')
|
314
329
|
end
|
315
330
|
|
316
331
|
def join_encoded_data(encoded_data)
|
@@ -1,73 +1,62 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/base'
|
2
2
|
module GoogleChart
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
encoded_data = []
|
57
|
-
@data.size.times { |i|
|
58
|
-
# Interleave X and Y co-ordinate data
|
59
|
-
encoded_data << join_encoded_data([encode_data(x_data[i],max_value), encode_data(y_data[i],max_value)])
|
60
|
-
}
|
61
|
-
join_encoded_data(encoded_data)
|
62
|
-
else # Line graph multiple data series
|
63
|
-
max_value = @data.flatten.max
|
64
|
-
join_encoded_data(@data.collect { |series|
|
65
|
-
encode_data(series, max_value)
|
66
|
-
})
|
67
|
-
end
|
68
|
-
else
|
69
|
-
encode_data(@data.flatten)
|
70
|
-
end
|
3
|
+
class LineChart < Base
|
4
|
+
attr_accessor :is_xy
|
5
|
+
|
6
|
+
def initialize(chart_size='300x200', chart_title=nil, is_xy=false)
|
7
|
+
super(chart_size, chart_title)
|
8
|
+
self.is_xy = is_xy
|
9
|
+
end
|
10
|
+
|
11
|
+
def is_xy=(value)
|
12
|
+
@is_xy = value
|
13
|
+
if value
|
14
|
+
self.chart_type = :lxy
|
15
|
+
else
|
16
|
+
self.chart_type = :lc
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def max_x_value
|
21
|
+
puts "Max x value is #{x_data.flatten.max}"
|
22
|
+
x_data.flatten.max
|
23
|
+
end
|
24
|
+
|
25
|
+
def max_y_value
|
26
|
+
puts "Max y value is #{y_data.flatten.max}"
|
27
|
+
y_data.flatten.max
|
28
|
+
end
|
29
|
+
|
30
|
+
def x_data
|
31
|
+
@data.collect do |series|
|
32
|
+
series.collect { |val| val.first }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def y_data
|
37
|
+
@data.collect do |series|
|
38
|
+
series.collect { |val| val.last }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def process_data
|
43
|
+
if self.is_xy or @data.size > 1
|
44
|
+
if self.is_xy # XY Line graph data series
|
45
|
+
encoded_data = []
|
46
|
+
@data.size.times { |i|
|
47
|
+
# Interleave X and Y co-ordinate data
|
48
|
+
encoded_data << join_encoded_data([encode_data(x_data[i],max_x_value), encode_data(y_data[i],max_y_value)])
|
49
|
+
}
|
50
|
+
join_encoded_data(encoded_data)
|
51
|
+
else # Line graph multiple data series
|
52
|
+
max_value = @data.flatten.max
|
53
|
+
join_encoded_data(@data.collect { |series|
|
54
|
+
encode_data(series, max_value)
|
55
|
+
})
|
71
56
|
end
|
57
|
+
else
|
58
|
+
encode_data(@data.flatten)
|
59
|
+
end
|
72
60
|
end
|
73
|
-
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/test.rb
CHANGED
@@ -70,3 +70,11 @@ lc.data "Trend 2", [1,2,3,4,5,6], '00ff00'
|
|
70
70
|
lc.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
|
71
71
|
puts lc.to_url({:chm => "r,000000,0,0.1,0.5"}) # Single black line as a horizontal marker
|
72
72
|
|
73
|
+
# Bryan Error condition
|
74
|
+
lcxy = GoogleChart::LineChart.new('320x200', "Line XY Chart", true)
|
75
|
+
lcxy.data 'A', [[0, 32], [1, 15], [2, 23], [3, 18], [4, 41], [5, 53]],'0000ff'
|
76
|
+
lcxy.data 'B', [[0, 73], [1, 0], [2, 28], [3, 0], [4, 333], [5, 0]], '00ff00'
|
77
|
+
lcxy.data 'C', [[0, 22], [1, 26], [2, 14], [3, 33], [4, 17], [5, 7]], 'ff0000'
|
78
|
+
lcxy.data 'D', [[0, 4], [1, 39], [2, 0], [3, 5], [4, 11], [5, 14]], 'cc00ff'
|
79
|
+
puts lcxy.to_url
|
80
|
+
|
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.
|
7
|
-
date: 2007-12-
|
6
|
+
version: 0.4.0
|
7
|
+
date: 2007-12-12 00:00:00 +08:00
|
8
8
|
summary: Ruby Wrapper for the Google Chart API
|
9
9
|
require_paths:
|
10
10
|
- lib
|