gchart 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,55 @@
1
+ === 1.0.0 / 2009-08-11
2
+
3
+ * Moving to GitHub, since apparently people use this thing.
4
+ * Switching to modern Hoe.
5
+ * Modification which will remove data points from the chart if
6
+ the generated URL exceeds the maximum URL length which
7
+ Google allows. [supplanter]
8
+ * GChart::Axis#range_markers was incorrectly initialized to a
9
+ hash, but the supporting documentation is correct. [supplanter]
10
+
11
+ == 0.5.0 / 2008-05-11
12
+
13
+ * Support for Map charts [Mark Thomas]
14
+ * Support for Sparkline charts [Mark Thomas]
15
+ * Initial support for Google-o-meter [Mark Thomas]
16
+ * Implemented both background solid fill and chart area solid fill.
17
+ * Added color aliasing: 3-character colors and a COLORS table.
18
+ * Full support for axis labels.
19
+ * Implemented horizontal/vertical range markers.
20
+ * New committer, Jim Ludwig.
21
+ * Freeze GChart::VERSION.
22
+
23
+ == 0.4.2 / 2008-01-09
24
+
25
+ * Encoding a flatlined chart doesn't asplode [Jack Danger Canty]
26
+
27
+ == 0.4.1 / 2008-01-02
28
+
29
+ * (bug #16756 fixed) Example in the README is incorrect
30
+
31
+ == 0.4.0 / 2007-12-28
32
+
33
+ * New committer, Abhay Kumar
34
+ * Implement all three encodings. Fix extended encoding calculation.
35
+ * Support bar thickness/spacing for bar charts
36
+ * (bug #16565 fixed) GChart now tells you when your chart is too big.
37
+ * Pushed some bar chart params logic down where it belongs
38
+ * Enforce pie chart spec: pie charts only take one set of data
39
+
40
+ == 0.3.0 / 2007-12-24
41
+
42
+ * Breaking change: labels --> legend
43
+ * Switched to RSpec, added skeletal specs for all types
44
+ * Extensive refactoring, pulled chart types into GChart::Base subclasses
45
+ * (bug) Errors in the static helpers should report a reasonable file and line
46
+
47
+ == 0.2.0 / 2007-12-12
48
+
49
+ * Support for basic :labels
50
+ * Support for pie3d
51
+ * Minor doc cleanups
52
+
53
+ == 0.1.0 (2007-12-10)
54
+
55
+ * Birthday!
@@ -1,6 +1,6 @@
1
- CHANGELOG.txt
1
+ CHANGELOG.rdoc
2
2
  Manifest.txt
3
- README.txt
3
+ README.rdoc
4
4
  Rakefile
5
5
  lib/gchart.rb
6
6
  lib/gchart/axis.rb
@@ -22,7 +22,6 @@ lib/gchart/scatter.rb
22
22
  lib/gchart/sparkline.rb
23
23
  lib/gchart/venn.rb
24
24
  lib/gchart/xy_line.rb
25
- lib/version.rb
26
25
  spec/gchart/axis/bottom_axis_spec.rb
27
26
  spec/gchart/axis/left_axis_spec.rb
28
27
  spec/gchart/axis/right_axis_spec.rb
@@ -0,0 +1,173 @@
1
+ = GChart
2
+
3
+ * http://github.com/jbarnette/gchart
4
+
5
+ == Description
6
+
7
+ GChart exposes the Google Chart API via a friendly Ruby interface. It
8
+ can generate the URL for a given chart (for webpage use), or download
9
+ the generated PNG (for offline use).
10
+
11
+ == Simple Examples
12
+
13
+ # line chart
14
+ g = GChart.line :data => [0, 10, 100]
15
+
16
+ # bar chart
17
+ g = GChart.bar :data => [100, 1000, 10000]
18
+
19
+ # pie chart (pie3d for a fancier look)
20
+ g = GChart.pie :data => [33, 33, 34]
21
+
22
+ # venn diagram (asize, bsize, csize, ab%, bc%, ca%, abc%)
23
+ g = GChart.venn :data => [100, 80, 60, 30, 30, 30, 10]
24
+
25
+ # scatter plot (x coords, y coords [, sizes])
26
+ g = GChart.scatter(
27
+ :data => [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 2, 3, 4, 5]])
28
+
29
+ # map chart
30
+ g = GChart.map :area => 'usa', :data => { 'NY' => 1, 'VA' => 3, 'CA' => 2 }
31
+
32
+ # meter
33
+ g = GChart.meter :data => 70, :label => "70%"
34
+
35
+ # chart title
36
+ g = GChart.line :title => "Awesomeness over Time", :data => [0, 10, 100]
37
+
38
+ # data set legend
39
+ g = GChart.line :data => [[1, 2], [3, 4]],
40
+ :legend => ["Monkeys", "Ferrets"]
41
+
42
+ # data set colors
43
+ g = GChart.line :data => [[0, 10, 100], [100, 10, 0]],
44
+ :colors => ["ff0000", "0000ff"]
45
+
46
+ g.to_url # generate the chart's URL, or
47
+ g.fetch # get the bytes, or
48
+ g.write "foo.png" # write to a file (defaults to "chart.png")
49
+ g.write stream # write to anything that quacks like IO
50
+
51
+ == Detailed Examples
52
+
53
+ === Simple Line Chart with 2 data sets
54
+
55
+ chart = GChart.line do |g|
56
+ g.data = [[0, 1, 2, 3, 4, 5, 6], [3, 2, 4, 1, 5, 0, 6]]
57
+ g.colors = [:red, :yellow]
58
+ g.legend = ["Line", "Wonkiness"]
59
+
60
+ g.width = 600
61
+ g.height = 150
62
+ g.entire_background = "f4f4f4"
63
+
64
+ g.axis(:left) { |a| a.range = 0..6 }
65
+
66
+ g.axis :bottom do |a|
67
+ a.labels = ["Mon", "Tue", "Thu", "Sun"]
68
+ a.label_positions = [0, 16.67, 50, 100]
69
+ a.text_color = :black
70
+ end
71
+
72
+ g.axis :bottom do |a|
73
+ a.labels = ["Week 42"]
74
+ a.label_positions = [50]
75
+ end
76
+ end
77
+
78
+ === Complex Line Chart with multiple axes
79
+
80
+ chart = GChart.line do |g|
81
+ g.data = [data_array1, data_array2, data_array3]
82
+ g.colors = [:red, :green, :blue]
83
+ g.legend = ["Set 1", "Set 2", "Set 3"]
84
+
85
+ g.width = 950
86
+ g.height = 315
87
+
88
+ g.entire_background = "434"
89
+ g.chart_background = "aba"
90
+
91
+ g.axis(:left) do |a|
92
+ a.range = 0..100
93
+ a.text_color = :red
94
+ a.font_size = 9
95
+ end
96
+
97
+ g.axis(:right) do |a|
98
+ a.font_size = 8
99
+ a.label_positions = [250, 500, 750]
100
+ a.labels = %w(250 500 750)
101
+ a.range = 0..1000
102
+ a.text_alignment = :right
103
+ a.text_color = :green
104
+ end
105
+
106
+ g.axis(:top) do |a|
107
+ a.labels = %w(2008)
108
+ a.positions = [50]
109
+ end
110
+
111
+ bottom1 = g.axis :bottom
112
+ bottom1.labels = dates_array
113
+
114
+ bottom1.range_markers = [
115
+ [0..33.33, 'ff000044'],
116
+ [33.33..66.67, '00ff0044'],
117
+ [66.67..100, '0000ff44']
118
+ ]
119
+
120
+ # We "manually" create our 2nd bottom axis...
121
+
122
+ bottom2 = GChart::Axis.create :bottom
123
+ bottom2.labels = %w(Dates)
124
+ bottom2.label_positions = [50]
125
+
126
+ # ...and therefore need to also add it to our axes "manually".
127
+ g.axes << bottom2
128
+ end
129
+
130
+ url = chart.to_url
131
+
132
+ == Axis Labeling
133
+
134
+ Charts which support an axis concept can be labeled. Supported types
135
+ are line charts, bar charts, radar charts and scatter plots. See
136
+ GChart::Axis for more information.
137
+
138
+ == TODO
139
+
140
+ * Add grid lines, linear stripes, shape markers, gradient fills
141
+ * Make venn data specification friendlier
142
+ * Make documentation more digestible
143
+
144
+ There are lots of missing features. Until they're implemented, you can
145
+ directly specify query parameters using the :extras key, e.g.,
146
+
147
+ # provides a legend for each data set
148
+ g = GChart.line :data => [[1, 2], [3, 4]],
149
+ :extras => { "chdl" => "First|Second" }
150
+
151
+ == License
152
+
153
+ Copyright 2007-2009 John Barnette (jbarnette@rubyforge.org), Jim
154
+ Ludwig (supplanter@rubyforge.org)
155
+
156
+ Permission is hereby granted, free of charge, to any person obtaining
157
+ a copy of this software and associated documentation files (the
158
+ 'Software'), to deal in the Software without restriction, including
159
+ without limitation the rights to use, copy, modify, merge, publish,
160
+ distribute, sublicense, and/or sell copies of the Software, and to
161
+ permit persons to whom the Software is furnished to do so, subject to
162
+ the following conditions:
163
+
164
+ The above copyright notice and this permission notice shall be
165
+ included in all copies or substantial portions of the Software.
166
+
167
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
168
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
169
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
170
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
171
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
172
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
173
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,31 +1,14 @@
1
1
  require "rubygems"
2
2
  require "hoe"
3
- require "spec/rake/spectask"
4
3
 
5
- require "./lib/version.rb"
4
+ Hoe.plugin :doofus, :git
6
5
 
7
- hoe = Hoe.new("gchart", GChart::VERSION) do |p|
8
- p.rubyforge_name = "gchart"
9
- p.author = "John Barnette"
10
- p.email = "jbarnette@rubyforge.org"
11
- p.summary = "GChart uses the Google Chart API to create pretty pictures."
12
- p.description = p.paragraphs_of("README.txt", 2..5).join("\n\n")
13
- p.url = "http://gchart.rubyforge.org"
14
- p.changes = p.paragraphs_of("CHANGELOG.txt", 0..1).join("\n\n")
15
- end
16
-
17
- desc "Run all specs"
18
- Spec::Rake::SpecTask.new do |t|
19
- t.spec_files = FileList["spec/**/*_spec.rb"]
20
- t.spec_opts = ["--options", "spec/spec.opts"]
21
- end
6
+ Hoe.spec "gchart" do
7
+ developer "John Barnette", "jbarnette@rubyforge.org"
8
+ developer "Jim Ludwig", "supplanter@rubyforge.org"
22
9
 
23
- desc "Run all specs and get coverage statistics"
24
- Spec::Rake::SpecTask.new('spec:rcov') do |t|
25
- t.spec_files = FileList["spec/**/*_spec.rb"]
26
- t.rcov = true
27
- t.spec_opts = ["--options", "spec/spec.opts"]
10
+ self.extra_rdoc_files = FileList["*.rdoc"]
11
+ self.history_file = "CHANGELOG.rdoc"
12
+ self.readme_file = "README.rdoc"
13
+ self.testlib = :rspec
28
14
  end
29
-
30
- Rake::Task[:default].prerequisites.clear
31
- task :default => :spec
@@ -1,4 +1,3 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/version")
2
1
  require File.expand_path(File.dirname(__FILE__) + "/gchart/colors")
3
2
  require File.expand_path(File.dirname(__FILE__) + "/gchart/axis")
4
3
 
@@ -11,10 +10,13 @@ end
11
10
  end
12
11
 
13
12
  module GChart
13
+ VERSION = "1.0.0"
14
+
14
15
  URL = "http://chart.apis.google.com/chart"
15
16
  SIMPLE_CHARS = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
16
17
  EXTENDED_CHARS = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a + %w[- .]
17
18
  EXTENDED_PAIRS = EXTENDED_CHARS.collect { |first| EXTENDED_CHARS.collect { |second| first + second } }.flatten
19
+ URL_MAXIMUM_LENGTH = 2074 # Google does not document this -- obtained by trial and error
18
20
 
19
21
  class << self
20
22
  # Convenience constructor for GChart::Line.
@@ -59,7 +59,7 @@ module GChart
59
59
  def initialize
60
60
  @labels = []
61
61
  @label_positions = []
62
- @range_markers = {}
62
+ @range_markers = []
63
63
  end
64
64
 
65
65
  # Returns a one-character label of the axis according to its type.
@@ -87,8 +87,8 @@ module GChart
87
87
 
88
88
  # Returns the chart's URL.
89
89
  def to_url
90
- query = query_params.collect { |k, v| "#{k}=#{URI.escape(v)}" }.join("&")
91
- "#{GChart::URL}?#{query}"
90
+ pluck_out_data_points! if url_to_try.length > GChart::URL_MAXIMUM_LENGTH
91
+ url_to_try
92
92
  end
93
93
 
94
94
  # Returns the chart's generated PNG as a blob.
@@ -113,6 +113,11 @@ module GChart
113
113
 
114
114
  protected
115
115
 
116
+ def url_to_try
117
+ query = query_params.collect { |k, v| "#{k}=#{URI.escape(v)}" }.join("&")
118
+ "#{GChart::URL}?#{query}"
119
+ end
120
+
116
121
  def query_params(raw_params={}) #:nodoc:
117
122
  params = raw_params.merge("cht" => render_chart_type, "chs" => size)
118
123
 
@@ -260,5 +265,80 @@ module GChart
260
265
  params["chm"] = chmr.join('|')
261
266
  end
262
267
  end
268
+
269
+ # If the length of an initially-generated URL exceeds the maximum
270
+ # length which Google allows for chart URLs, then we need to trim
271
+ # off some data. Here we make the (rather sane) assumption that
272
+ # each data set is the same size as every other data set (or a
273
+ # size of 1, which we ignore here). Then we remove the same
274
+ # number of points from each data set, in an as evenly-distributed
275
+ # approach as we can muster, until the length of our generated URL
276
+ # is less than the maximum length.
277
+ def pluck_out_data_points!
278
+ original_data_sets = data_clone(data)
279
+
280
+ divisor_upper = data.collect{ |set| set.length }.max
281
+ divisor_lower = 0
282
+ divisor = 0
283
+
284
+ while divisor_upper - divisor_lower > 1 || url_to_try.length > GChart::URL_MAXIMUM_LENGTH
285
+ self.data = data_clone(original_data_sets)
286
+
287
+ if divisor_upper - divisor_lower > 1
288
+ divisor = (divisor_lower + divisor_upper) / 2
289
+ else
290
+ divisor += 1
291
+ end
292
+
293
+ data.each do |set|
294
+ next if set.size == 1
295
+ indexes_for_plucking(set.size, divisor).each do |deletion_index|
296
+ set.delete_at(deletion_index)
297
+ end
298
+ end
299
+
300
+ if divisor_upper - divisor_lower > 1
301
+ if url_to_try.length > GChart::URL_MAXIMUM_LENGTH
302
+ divisor_lower = divisor
303
+ else
304
+ divisor_upper = divisor
305
+ end
306
+ end
307
+ end
308
+ end
309
+
310
+ def indexes_for_plucking(array_length, divisor) #:nodoc:
311
+ indexes = []
312
+
313
+ last_index = array_length - 1
314
+ num_points_to_remove = divisor - 1
315
+ num_points_after_removal = array_length - num_points_to_remove
316
+ num_points_in_chunk = num_points_after_removal / divisor.to_f
317
+
318
+ subtraction_point = array_length.to_f
319
+
320
+ 1.upto(num_points_to_remove) do |point_number|
321
+ subtraction_point -= num_points_in_chunk
322
+ indexes.push( (subtraction_point - point_number).round )
323
+ end
324
+
325
+ indexes
326
+ end
327
+
328
+ def data_clone(original_array_of_arrays) #:nodoc:
329
+ cloned_array_of_arrays = Array.new
330
+
331
+ original_array_of_arrays.each do |original_array|
332
+ cloned_array = Array.new
333
+
334
+ original_array.each do |datum|
335
+ cloned_array << datum
336
+ end
337
+
338
+ cloned_array_of_arrays << cloned_array
339
+ end
340
+
341
+ cloned_array_of_arrays
342
+ end
263
343
  end
264
344
  end
@@ -261,3 +261,15 @@ describe GChart::Base, "#render_backgrounds" do
261
261
  @chart.to_url.should =~ /chf=bg,s,ffff00/
262
262
  end
263
263
  end
264
+
265
+ describe GChart::Base, "#to_url" do
266
+ it "plucks out data points for large sets of data so as not to exceed Google maximum url length" do
267
+ data = [0, 1, 2, 3, 4, 5, 4, 3, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 5, 3, 1] * 40
268
+ chart = GChart.line(:data => [data] * 4)
269
+
270
+ chart.data.collect{ |set| set.length }.should == [840] * 4
271
+
272
+ chart.to_url.length.should < GChart::URL_MAXIMUM_LENGTH
273
+ chart.data.collect{ |set| set.length }.should == [251] * 4
274
+ end
275
+ end
metadata CHANGED
@@ -1,41 +1,47 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gchart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Barnette
8
+ - Jim Ludwig
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2008-05-11 00:00:00 -07:00
13
+ date: 2009-08-11 00:00:00 -07:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: hoe
17
- type: :runtime
18
+ type: :development
18
19
  version_requirement:
19
20
  version_requirements: !ruby/object:Gem::Requirement
20
21
  requirements:
21
22
  - - ">="
22
23
  - !ruby/object:Gem::Version
23
- version: 1.5.1
24
+ version: 2.3.2
24
25
  version:
25
- description: "== PROBLEMS/TODO * Add grid lines, linear stripes, shape markers, gradient fills * Make venn data specification friendlier * Make documentation more digestible There are lots of missing features. Until they're implemented, you can directly specify query parameters using the :extras key, e.g., # provides a legend for each data set g = GChart.line(:data => [[1, 2], [3, 4]], :extras => { \"chdl\" => \"First|Second\"})"
26
- email: jbarnette@rubyforge.org
26
+ description: |-
27
+ GChart exposes the Google Chart API via a friendly Ruby interface. It
28
+ can generate the URL for a given chart (for webpage use), or download
29
+ the generated PNG (for offline use).
30
+ email:
31
+ - jbarnette@rubyforge.org
32
+ - supplanter@rubyforge.org
27
33
  executables: []
28
34
 
29
35
  extensions: []
30
36
 
31
37
  extra_rdoc_files:
32
- - CHANGELOG.txt
33
38
  - Manifest.txt
34
- - README.txt
39
+ - CHANGELOG.rdoc
40
+ - README.rdoc
35
41
  files:
36
- - CHANGELOG.txt
42
+ - CHANGELOG.rdoc
37
43
  - Manifest.txt
38
- - README.txt
44
+ - README.rdoc
39
45
  - Rakefile
40
46
  - lib/gchart.rb
41
47
  - lib/gchart/axis.rb
@@ -57,7 +63,6 @@ files:
57
63
  - lib/gchart/sparkline.rb
58
64
  - lib/gchart/venn.rb
59
65
  - lib/gchart/xy_line.rb
60
- - lib/version.rb
61
66
  - spec/gchart/axis/bottom_axis_spec.rb
62
67
  - spec/gchart/axis/left_axis_spec.rb
63
68
  - spec/gchart/axis/right_axis_spec.rb
@@ -79,11 +84,13 @@ files:
79
84
  - spec/helper.rb
80
85
  - spec/spec.opts
81
86
  has_rdoc: true
82
- homepage: http://gchart.rubyforge.org
87
+ homepage: http://github.com/jbarnette/gchart
88
+ licenses: []
89
+
83
90
  post_install_message:
84
91
  rdoc_options:
85
92
  - --main
86
- - README.txt
93
+ - README.rdoc
87
94
  require_paths:
88
95
  - lib
89
96
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -101,9 +108,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
108
  requirements: []
102
109
 
103
110
  rubyforge_project: gchart
104
- rubygems_version: 1.1.1
111
+ rubygems_version: 1.3.5
105
112
  signing_key:
106
- specification_version: 2
107
- summary: GChart uses the Google Chart API to create pretty pictures.
113
+ specification_version: 3
114
+ summary: GChart exposes the Google Chart API via a friendly Ruby interface
108
115
  test_files: []
109
116
 
@@ -1,45 +0,0 @@
1
- == 0.5.0 (2008-05-11)
2
-
3
- * Support for Map charts [Mark Thomas]
4
- * Support for Sparkline charts [Mark Thomas]
5
- * Initial support for Google-o-meter [Mark Thomas]
6
- * Implemented both background solid fill and chart area solid fill.
7
- * Added color aliasing: 3-character colors and a COLORS table.
8
- * Full support for axis labels.
9
- * Implemented horizontal/vertical range markers.
10
- * New committer, Jim Ludwig.
11
- * Freeze GChart::VERSION.
12
-
13
- == 0.4.2 (2008-01-09)
14
-
15
- * Encoding a flatlined chart doesn't asplode [Jack Danger Canty]
16
-
17
- == 0.4.1 (2008-01-02)
18
-
19
- * (bug #16756 fixed) Example in the README is incorrect
20
-
21
- == 0.4.0 (2007-12-28)
22
-
23
- * New committer, Abhay Kumar
24
- * Implement all three encodings. Fix extended encoding calculation.
25
- * Support bar thickness/spacing for bar charts
26
- * (bug #16565 fixed) GChart now tells you when your chart is too big.
27
- * Pushed some bar chart params logic down where it belongs
28
- * Enforce pie chart spec: pie charts only take one set of data
29
-
30
- == 0.3.0 (2007-12-24)
31
-
32
- * Breaking change: labels --> legend
33
- * Switched to RSpec, added skeletal specs for all types
34
- * Extensive refactoring, pulled chart types into GChart::Base subclasses
35
- * (bug) Errors in the static helpers should report a reasonable file and line
36
-
37
- == 0.2.0 (2007-12-12)
38
-
39
- * Support for basic :labels
40
- * Support for pie3d
41
- * Minor doc cleanups
42
-
43
- == 0.1.0 (2007-12-10)
44
-
45
- * Birthday!
data/README.txt DELETED
@@ -1,168 +0,0 @@
1
- = GChart
2
-
3
- == DESCRIPTION
4
-
5
- GChart exposes the Google Chart API (http://code.google.com/apis/chart) via
6
- a friendly Ruby interface. It can generate the URL for a given chart
7
- (for webpage use), or download the generated PNG (for offline use).
8
-
9
- == PROBLEMS/TODO
10
-
11
- * Add grid lines, linear stripes, shape markers, gradient fills
12
- * Make venn data specification friendlier
13
- * Make documentation more digestible
14
-
15
- There are lots of missing features. Until they're implemented, you can directly specify
16
- query parameters using the :extras key, e.g.,
17
-
18
- # provides a legend for each data set
19
- g = GChart.line(:data => [[1, 2], [3, 4]], :extras => { "chdl" => "First|Second"})
20
-
21
- == SYNOPSIS
22
-
23
- # line chart
24
- g = GChart.line(:data => [0, 10, 100])
25
-
26
- # bar chart
27
- g = GChart.bar(:data => [100, 1000, 10000])
28
-
29
- # pie chart (pie3d for a fancier look)
30
- g = GChart.pie(:data => [33, 33, 34])
31
-
32
- # venn diagram (asize, bsize, csize, ab%, bc%, ca%, abc%)
33
- g = GChart.venn(:data => [100, 80, 60, 30, 30, 30, 10])
34
-
35
- # scatter plot (x coords, y coords [, sizes])
36
- g = GChart.scatter(:data => [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 2, 3, 4, 5]])
37
-
38
- # map chart
39
- g = GChart.map(:area => 'usa', :data => {'NY'=>1,'VA'=>3,'CA'=>2})
40
-
41
- # meter
42
- g = GChart.meter(:data => 70, :label => "70%")
43
-
44
- # chart title
45
- g = GChart.line(:title => "Awesomeness over Time", :data => [0, 10, 100])
46
-
47
- # data set legend
48
- g = GChart.line(:data => [[1, 2], [3, 4]], :legend => ["Monkeys", "Ferrets"])
49
-
50
- # data set colors
51
- g = GChart.line(:data => [[0, 10, 100], [100, 10, 0]], :colors => ["ff0000", "0000ff"])
52
-
53
- g.to_url # generate the chart's URL, or
54
- g.fetch # get the bytes, or
55
- g.write("foo.png") # write to a file (defaults to "chart.png")
56
- g.write(stream) # write to anything that quacks like IO
57
-
58
- == AXIS LABELING
59
-
60
- Charts which support an axis concept can be labeled. Supported types
61
- are line charts, bar charts, radar charts and scatter plots. See
62
- +GChart::Axis+ for more information.
63
-
64
- == EXAMPLES
65
-
66
- === Simple Line Chart with 2 data sets
67
-
68
- require 'gchart'
69
- chart = GChart.line do |g|
70
- g.data = [[0, 1, 2, 3, 4, 5, 6], [3, 2, 4, 1, 5, 0, 6]]
71
- g.colors = [:red, :yellow]
72
- g.legend = ["Line", "Wonkiness"]
73
-
74
- g.width = 600
75
- g.height = 150
76
-
77
- g.entire_background = "f4f4f4"
78
-
79
- g.axis(:left) { |a| a.range = 0..6 }
80
-
81
- g.axis(:bottom) do |a|
82
- a.labels = ["Mon", "Tue", "Thu", "Sun"]
83
- a.label_positions = [0, 16.67, 50, 100]
84
- a.text_color = :black
85
- end
86
-
87
- g.axis(:bottom) do |a|
88
- a.labels = ["Week 42"]
89
- a.label_positions = [50]
90
- end
91
- end
92
-
93
- === Complex Line Chart with multiple axes
94
-
95
- require 'gchart'
96
- chart = GChart.line do |g|
97
- g.data = [data_array1, data_array2, data_array3]
98
- g.colors = [:red, :green, :blue]
99
- g.legend = ["Set 1", "Set 2", "Set 3"]
100
-
101
- g.width = 950
102
- g.height = 315
103
-
104
- g.entire_background = "434"
105
- g.chart_background = "aba"
106
-
107
- g.axis(:left) do |a|
108
- a.range = 0..100
109
- a.text_color = :red
110
- a.font_size = 9
111
- end
112
-
113
- g.axis(:right) do |a|
114
- a.range = 0..1000
115
- a.labels = %w(250 500 750)
116
- a.label_positions = [250, 500, 750]
117
-
118
- a.text_color = :green
119
- a.font_size = 8
120
- a.text_alignment = :right
121
- end
122
-
123
- g.axis(:top) do |a|
124
- a.labels = %w(2008)
125
- a.positions = [50]
126
- end
127
-
128
- bottom1 = g.axis(:bottom)
129
- bottom1.labels = dates_array
130
- bottom1.range_markers = [
131
- [0..33.33, 'ff000044'], [33.33..66.67, '00ff0044'], [66.67..100, '0000ff44']
132
- ]
133
-
134
- # We "manually" create our 2nd bottom axis...
135
- bottom2 = GChart::Axis.create(:bottom)
136
- bottom2.labels = %w(Dates)
137
- bottom2.label_positions = [50]
138
-
139
- # ...and therefore need to also add it to our axes "manually".
140
- g.axes << bottom2
141
- end
142
-
143
- url = chart.to_url
144
-
145
- == LICENSE
146
-
147
- (The MIT License)
148
-
149
- Copyright 2007-2008 John Barnette (jbarnette@rubyforge.org), Jim Ludwig (supplanter@rubyforge.org)
150
-
151
- Permission is hereby granted, free of charge, to any person obtaining
152
- a copy of this software and associated documentation files (the
153
- 'Software'), to deal in the Software without restriction, including
154
- without limitation the rights to use, copy, modify, merge, publish,
155
- distribute, sublicense, and/or sell copies of the Software, and to
156
- permit persons to whom the Software is furnished to do so, subject to
157
- the following conditions:
158
-
159
- The above copyright notice and this permission notice shall be
160
- included in all copies or substantial portions of the Software.
161
-
162
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
163
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
164
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
165
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
166
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
167
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
168
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,3 +0,0 @@
1
- module GChart
2
- VERSION = "0.5.0".freeze
3
- end