gchart 0.1.0 → 0.2.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/CHANGELOG.txt CHANGED
@@ -1,3 +1,9 @@
1
- == 0.1.0
1
+ == 0.2.0 (2007-12-12)
2
+
3
+ * Support for basic :labels
4
+ * Support for pie3d
5
+ * Minor doc cleanups
6
+
7
+ == 0.1.0 (2007-12-10)
2
8
 
3
9
  * Birthday!
data/README.txt CHANGED
@@ -26,7 +26,7 @@ query parameters using the :extras key, e.g.,
26
26
  # bar chart
27
27
  g = GChart.bar(:data => [100, 1000, 10000])
28
28
 
29
- # pie chart
29
+ # pie chart (pie3d for a fancier look)
30
30
  g = GChart.pie(:data => [33, 33, 34])
31
31
 
32
32
  # venn diagram (asize, bsize, csize, ab%, bc%, ca%, abc%)
@@ -38,6 +38,9 @@ query parameters using the :extras key, e.g.,
38
38
  # chart title
39
39
  g = GChart.line(:title => "Awesomeness over Time", :data => [0, 10, 100])
40
40
 
41
+ # data set labels
42
+ g = GChart.line(:data => [[1, 2], [3, 4]], :labels => ["Monkeys", "Ferrets"])
43
+
41
44
  # data set colors
42
45
  g = GChart.line(:data => [[0, 10, 100], [100, 10, 0]], :colors => ["ff0000", "0000ff"])
43
46
 
data/lib/gchart.rb CHANGED
@@ -5,7 +5,7 @@ require "uri"
5
5
 
6
6
  class GChart
7
7
  URL = "http://chart.apis.google.com/chart"
8
- TYPES = %w(line linexy bar pie venn scatter).collect { |t| t.to_sym }
8
+ TYPES = %w(line linexy bar pie pie3d venn scatter).collect { |t| t.to_sym }
9
9
  CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.".split("")
10
10
  PAIRS = CHARS.collect { |first| CHARS.collect { |second| first + second } }.flatten
11
11
 
@@ -48,6 +48,11 @@ class GChart
48
48
  # Array of RRGGBB colors, one per data set
49
49
  attr_accessor :colors
50
50
 
51
+ # Array of data set labels
52
+ attr_accessor :labels
53
+
54
+ attr_accessor :max
55
+
51
56
  # The chart type
52
57
  attr_reader :type
53
58
 
@@ -81,7 +86,7 @@ class GChart
81
86
  "#{width}x#{height}"
82
87
  end
83
88
 
84
- # Allows the chart's size to be set as "WIDTHxHEIGHT".
89
+ # Sets the chart's size as "WIDTHxHEIGHT".
85
90
  def size=(size)
86
91
  self.width, self.height = size.split("x").collect { |n| Integer(n) }
87
92
  end
@@ -97,9 +102,8 @@ class GChart
97
102
  open(to_url) { |data| data.read }
98
103
  end
99
104
 
100
- # Writes the chart's generated PNG. If +io_or_file+ quacks like an IO,
101
- # +write+ will be called. Otherwise, write to disk. +io_or_file+ defaults
102
- # to "chart.png".
105
+ # Writes the chart's generated PNG to a file. If +io_or_file+ quacks like an IO,
106
+ # +write+ will be called on it instead.
103
107
  def write(io_or_file="chart.png")
104
108
  return io_or_file.write(fetch) if io_or_file.respond_to?(:write)
105
109
  open(io_or_file, "w+") { |f| f.write(fetch) }
@@ -111,6 +115,12 @@ class GChart
111
115
  params = { "cht" => google_chart_type, "chd" => google_data, "chs" => size }
112
116
  params["chtt"] = title.tr("\n", "|").gsub(/\s+/, "+") if title
113
117
  params["chco"] = colors.join(",") if colors
118
+
119
+ if labels
120
+ param = (type == :pie || type == :pie3d) ? "chl" : "chdl"
121
+ params[param] = labels.join("|")
122
+ end
123
+
114
124
  params.merge(extras)
115
125
  end
116
126
 
@@ -124,6 +134,8 @@ class GChart
124
134
  "b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s")
125
135
  when :pie
126
136
  "p"
137
+ when :pie3d
138
+ "p3"
127
139
  when :venn
128
140
  "v"
129
141
  when :scatter
@@ -132,9 +144,11 @@ class GChart
132
144
  end
133
145
 
134
146
  def google_data
135
- # we'll just always use the extended encoding for now
136
- sets = (Array === data.first ? data : [data]).collect do |set|
137
- max = set.max
147
+ raw = data && data.first.is_a?(Array) ? data : [data]
148
+ max = self.max || raw.collect { |s| s.max }.max
149
+
150
+ sets = raw.collect do |set|
151
+ # we'll just always use the extended encoding for now
138
152
  set.collect { |n| GChart.encode_extended(n * (PAIRS.size - 1) / max) }.join
139
153
  end
140
154
 
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class GChart
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gchart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ""
6
6
  authors:
7
7
  - John Barnette
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2007-12-10 00:00:00 -08:00
12
+ date: 2007-12-12 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency