gregoryfoster-gchartrb 0.9
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 +6 -0
- data/History.txt +69 -0
- data/Manifest.txt +47 -0
- data/README.txt +64 -0
- data/Rakefile +61 -0
- data/TODO +10 -0
- data/gchartrb.gemspec +18 -0
- data/lib/core_ext.rb +32 -0
- data/lib/example.rb +75 -0
- data/lib/gchartrb.rb +1 -0
- data/lib/google_chart.rb +39 -0
- data/lib/google_chart/bar_chart.rb +83 -0
- data/lib/google_chart/base.rb +148 -0
- data/lib/google_chart/line_chart.rb +19 -0
- data/lib/google_chart/linexy_chart.rb +20 -0
- data/lib/google_chart/map_chart.rb +74 -0
- data/lib/google_chart/modules/axis.rb +62 -0
- data/lib/google_chart/modules/color.rb +15 -0
- data/lib/google_chart/modules/data_array.rb +57 -0
- data/lib/google_chart/modules/fills.rb +102 -0
- data/lib/google_chart/modules/grid.rb +27 -0
- data/lib/google_chart/modules/label.rb +27 -0
- data/lib/google_chart/modules/legend.rb +24 -0
- data/lib/google_chart/modules/markers.rb +88 -0
- data/lib/google_chart/pie_chart.rb +44 -0
- data/lib/google_chart/radar_chart.rb +33 -0
- data/lib/google_chart/scatter_plot.rb +34 -0
- data/lib/google_chart/sparkline_chart.rb +19 -0
- data/lib/google_chart/venn_diagram.rb +41 -0
- data/lib/test.rb +252 -0
- data/scripts/iso3166_en_code_lists.txt +250 -0
- data/scripts/process_country_codes.rb +27 -0
- data/spec/gchartrb/axis_spec.rb +125 -0
- data/spec/gchartrb/bar_chart_spec.rb +128 -0
- data/spec/gchartrb/fills_spec.rb +124 -0
- data/spec/gchartrb/grid_spec.rb +59 -0
- data/spec/gchartrb/line_chart_spec.rb +78 -0
- data/spec/gchartrb/linexy_chart_spec.rb +31 -0
- data/spec/gchartrb/markers_spec.rb +160 -0
- data/spec/gchartrb/pie_chart_spec.rb +36 -0
- data/spec/gchartrb/radar_chart_spec.rb +40 -0
- data/spec/gchartrb/scatter_plot_spec.rb +37 -0
- data/spec/gchartrb/sparkline_chart_spec.rb +16 -0
- data/spec/gchartrb/venn_diagram_spec.rb +57 -0
- data/spec/gchartrb_spec.rb +117 -0
- data/spec/helper.rb +15 -0
- data/spec/spec.opts +7 -0
- metadata +102 -0
data/CREDITS
ADDED
data/History.txt
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
== 0.8 / 2008-03-20
|
|
2
|
+
|
|
3
|
+
* Fixed Rakefile to process URL correctly (Thanks Aaron Blohowiak)
|
|
4
|
+
* Fixed Axis error due to typo in base.rb (Thanks Jack Nutting)
|
|
5
|
+
|
|
6
|
+
== 0.7 / 2008-02-04
|
|
7
|
+
|
|
8
|
+
* Added fill area feature
|
|
9
|
+
* Added to_escaped_url method for encoding the URLs properly
|
|
10
|
+
* Fixed bug where wrong variable name was being used in method
|
|
11
|
+
|
|
12
|
+
== 0.6 / 2008-01-27
|
|
13
|
+
|
|
14
|
+
* Added experimental support for undocumented Financial Line Chart (lfi)
|
|
15
|
+
* Added line style support (thanks diomedes)
|
|
16
|
+
* Added support for customisable width and spacing in bar charts
|
|
17
|
+
|
|
18
|
+
== 0.5.5 / 2008-01-23
|
|
19
|
+
|
|
20
|
+
* Fixed a bug related to multiple datasets using extended encoding
|
|
21
|
+
|
|
22
|
+
== 0.5.4 / 2008-01-07
|
|
23
|
+
|
|
24
|
+
* Fixed a bug related to data encoding in Stacked Charts
|
|
25
|
+
* Fixed a bug in which title font and title font size values were being ignored
|
|
26
|
+
* Fixed a bug where shape markers and range markers were overriding each other
|
|
27
|
+
|
|
28
|
+
== 0.5.3 / 2007-12-19
|
|
29
|
+
|
|
30
|
+
* Added support for shape markers
|
|
31
|
+
* Added support for block based idiomatic ruby syntax
|
|
32
|
+
|
|
33
|
+
== 0.5.2 / 2007-12-14
|
|
34
|
+
|
|
35
|
+
* Added support for title color via title_color attribute
|
|
36
|
+
* Added support for vertical and horizontal range markers using the range_marker method
|
|
37
|
+
* Removed show_labels from base.rb and added it only for pie charts
|
|
38
|
+
|
|
39
|
+
== 0.5.1 / 2007-12-12
|
|
40
|
+
|
|
41
|
+
* Added support for max_value method to specify maximum values to plot against
|
|
42
|
+
|
|
43
|
+
== 0.5 / 2007-12-12
|
|
44
|
+
|
|
45
|
+
* Added Scatter Chart Support
|
|
46
|
+
* Documentation Updates
|
|
47
|
+
|
|
48
|
+
== 0.4.1 / 2007-12-12
|
|
49
|
+
|
|
50
|
+
* Removed some spurious debug statements
|
|
51
|
+
|
|
52
|
+
== 0.4 / 2007-12-12
|
|
53
|
+
|
|
54
|
+
* Fixed issue when all data points are 0 in Line XY Chart (Thanks Cedric)
|
|
55
|
+
* Proper calculation of max values for Line XY chart (Thanks Bryan Donovan)
|
|
56
|
+
|
|
57
|
+
== 0.3 / 2007-12-11
|
|
58
|
+
|
|
59
|
+
* Google changed Pie chart implementation to disable legends. Fixed in API.
|
|
60
|
+
|
|
61
|
+
== 0.2 / 2007-12-11
|
|
62
|
+
|
|
63
|
+
* Removed hoe dependency
|
|
64
|
+
* Doc fixes
|
|
65
|
+
|
|
66
|
+
== 0.1 / 2007-12-11
|
|
67
|
+
|
|
68
|
+
* Initial Release
|
|
69
|
+
* RDoc documentation
|
data/Manifest.txt
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
CREDITS
|
|
2
|
+
History.txt
|
|
3
|
+
Manifest.txt
|
|
4
|
+
README.txt
|
|
5
|
+
Rakefile
|
|
6
|
+
TODO
|
|
7
|
+
gchartrb.gemspec
|
|
8
|
+
lib/core_ext.rb
|
|
9
|
+
lib/example.rb
|
|
10
|
+
lib/gchartrb.rb
|
|
11
|
+
lib/google_chart.rb
|
|
12
|
+
lib/google_chart/bar_chart.rb
|
|
13
|
+
lib/google_chart/base.rb
|
|
14
|
+
lib/google_chart/line_chart.rb
|
|
15
|
+
lib/google_chart/linexy_chart.rb
|
|
16
|
+
lib/google_chart/map_chart.rb
|
|
17
|
+
lib/google_chart/modules/axis.rb
|
|
18
|
+
lib/google_chart/modules/color.rb
|
|
19
|
+
lib/google_chart/modules/data_array.rb
|
|
20
|
+
lib/google_chart/modules/fills.rb
|
|
21
|
+
lib/google_chart/modules/grid.rb
|
|
22
|
+
lib/google_chart/modules/label.rb
|
|
23
|
+
lib/google_chart/modules/legend.rb
|
|
24
|
+
lib/google_chart/modules/markers.rb
|
|
25
|
+
lib/google_chart/pie_chart.rb
|
|
26
|
+
lib/google_chart/radar_chart.rb
|
|
27
|
+
lib/google_chart/scatter_plot.rb
|
|
28
|
+
lib/google_chart/sparkline_chart.rb
|
|
29
|
+
lib/google_chart/venn_diagram.rb
|
|
30
|
+
lib/test.rb
|
|
31
|
+
scripts/iso3166_en_code_lists.txt
|
|
32
|
+
scripts/process_country_codes.rb
|
|
33
|
+
spec/gchartrb/axis_spec.rb
|
|
34
|
+
spec/gchartrb/bar_chart_spec.rb
|
|
35
|
+
spec/gchartrb/fills_spec.rb
|
|
36
|
+
spec/gchartrb/grid_spec.rb
|
|
37
|
+
spec/gchartrb/line_chart_spec.rb
|
|
38
|
+
spec/gchartrb/linexy_chart_spec.rb
|
|
39
|
+
spec/gchartrb/markers_spec.rb
|
|
40
|
+
spec/gchartrb/pie_chart_spec.rb
|
|
41
|
+
spec/gchartrb/radar_chart_spec.rb
|
|
42
|
+
spec/gchartrb/scatter_plot_spec.rb
|
|
43
|
+
spec/gchartrb/sparkline_chart_spec.rb
|
|
44
|
+
spec/gchartrb/venn_diagram_spec.rb
|
|
45
|
+
spec/gchartrb_spec.rb
|
|
46
|
+
spec/helper.rb
|
|
47
|
+
spec/spec.opts
|
data/README.txt
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
= gchartrb
|
|
2
|
+
http://code.google.com/p/gchartrb
|
|
3
|
+
|
|
4
|
+
== DESCRIPTION:
|
|
5
|
+
|
|
6
|
+
gchartrb is a Ruby wrapper around the Google Chart API, located at http://code.google.com/apis/chart/
|
|
7
|
+
|
|
8
|
+
Visit http://code.google.com/p/gchartrb to track development regarding gchartrb.
|
|
9
|
+
|
|
10
|
+
== FEATURES:
|
|
11
|
+
|
|
12
|
+
* Provides an object oriented interface in Ruby to create Google Chart URLs for charts.
|
|
13
|
+
|
|
14
|
+
== INSTALL:
|
|
15
|
+
|
|
16
|
+
=== Ruby Gem:
|
|
17
|
+
|
|
18
|
+
sudo gem install gchartrb
|
|
19
|
+
|
|
20
|
+
=== Manual Download:
|
|
21
|
+
|
|
22
|
+
Download the latest release from http://code.google.com/p/gchartrb/downloads/list
|
|
23
|
+
|
|
24
|
+
=== Git:
|
|
25
|
+
You can checkout the git repository at http://github.com/deepakjois/gchartrb
|
|
26
|
+
|
|
27
|
+
== TODO:
|
|
28
|
+
The following features are pending :
|
|
29
|
+
|
|
30
|
+
* Line Styles and Fill Areas
|
|
31
|
+
* Googleometer and Map Charts
|
|
32
|
+
* Data Scaling for Text Encoding
|
|
33
|
+
* Download Image
|
|
34
|
+
* Friendly Color Values
|
|
35
|
+
* Easy Calculations for Stuff
|
|
36
|
+
* Cleanup and DRY Validations
|
|
37
|
+
|
|
38
|
+
== SYNOPSIS:
|
|
39
|
+
TODO: write new
|
|
40
|
+
|
|
41
|
+
== LICENSE:
|
|
42
|
+
|
|
43
|
+
(The MIT License)
|
|
44
|
+
|
|
45
|
+
Copyright (c) 2007 Deepak Jois
|
|
46
|
+
|
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
48
|
+
a copy of this software and associated documentation files (the
|
|
49
|
+
'Software'), to deal in the Software without restriction, including
|
|
50
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
51
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
52
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
53
|
+
the following conditions:
|
|
54
|
+
|
|
55
|
+
The above copyright notice and this permission notice shall be
|
|
56
|
+
included in all copies or substantial portions of the Software.
|
|
57
|
+
|
|
58
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
59
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
60
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
61
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
62
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
63
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
64
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# -*- ruby -*-
|
|
2
|
+
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'hoe'
|
|
5
|
+
require "spec/rake/spectask"
|
|
6
|
+
require './lib/gchartrb'
|
|
7
|
+
|
|
8
|
+
class Hoe
|
|
9
|
+
def extra_deps; @extra_deps.reject { |x| Array(x).first == "hoe" } end
|
|
10
|
+
end # copied from the Rakefile of the sup project
|
|
11
|
+
|
|
12
|
+
Hoe.new('gchartrb', "0.9") do |p|
|
|
13
|
+
p.rubyforge_name = 'gchartrb'
|
|
14
|
+
p.author = 'Deepak Jois'
|
|
15
|
+
p.email = 'deepak.jois@gmail.com'
|
|
16
|
+
p.summary = 'Ruby Wrapper for the Google Chart API'
|
|
17
|
+
p.description = p.paragraphs_of('README.txt', 2..3).join("\n\n")
|
|
18
|
+
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
|
19
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
|
20
|
+
p.remote_rdoc_dir = ''
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
RDOC_OPTS = [
|
|
25
|
+
'--quiet',
|
|
26
|
+
'--title', 'gchartrb API',
|
|
27
|
+
'--main', 'README.txt',
|
|
28
|
+
'--charset', 'utf-8',
|
|
29
|
+
'--inline-source',
|
|
30
|
+
'--tab-width', '2',
|
|
31
|
+
'--line-numbers',
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
Rake::RDocTask.new do |rdoc|
|
|
35
|
+
rdoc.rdoc_dir = 'doc/'
|
|
36
|
+
rdoc.options = RDOC_OPTS
|
|
37
|
+
rdoc.main = "README.txt"
|
|
38
|
+
rdoc.rdoc_files.add [
|
|
39
|
+
'README.txt',
|
|
40
|
+
'History.txt',
|
|
41
|
+
'lib/**/*.rb'
|
|
42
|
+
]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
desc "Run all specs"
|
|
46
|
+
Spec::Rake::SpecTask.new do |t|
|
|
47
|
+
t.spec_files = FileList["spec/**/*_spec.rb"]
|
|
48
|
+
t.spec_opts = ["--options", "spec/spec.opts"]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
desc "Run all specs and get coverage statistics"
|
|
52
|
+
Spec::Rake::SpecTask.new('spec:rcov') do |t|
|
|
53
|
+
t.spec_files = FileList["spec/**/*_spec.rb"]
|
|
54
|
+
t.rcov = true
|
|
55
|
+
t.spec_opts = ["--options", "spec/spec.opts"]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
Rake::Task[:default].prerequisites.clear
|
|
59
|
+
task :default => :spec
|
|
60
|
+
|
|
61
|
+
# vim: syntax=Ruby
|
data/TODO
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
TODO List
|
|
2
|
+
====================
|
|
3
|
+
* Documentation!
|
|
4
|
+
* Line Styles and Fill Areas
|
|
5
|
+
* Googleometer and Map Charts
|
|
6
|
+
* Data Scaling for text encoding
|
|
7
|
+
* Download Image
|
|
8
|
+
* Friendly Color Values
|
|
9
|
+
* Easy calculations for Stuff that is needed
|
|
10
|
+
* Cleanup and DRY validations
|
data/gchartrb.gemspec
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = "gchartrb"
|
|
3
|
+
s.version = "0.9"
|
|
4
|
+
s.authors = ["Deepak Jois"]
|
|
5
|
+
s.email = "deepak.jois@gmail.com"
|
|
6
|
+
s.date = "2008-06-16"
|
|
7
|
+
s.homepage = "http://code.google.com/p/gchartrb"
|
|
8
|
+
s.summary = "Ruby Wrapper for the Google Chart API"
|
|
9
|
+
s.description = "gchartrb is a Ruby wrapper around the Google Chart API, located at http://code.google.com/apis/chart/. Visit http://code.google.com/p/gchartrb to track development regarding gchartrb."
|
|
10
|
+
|
|
11
|
+
s.has_rdoc = true
|
|
12
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
|
13
|
+
s.rdoc_options = ["--main", "README.txt"]
|
|
14
|
+
s.files = ["CREDITS", "History.txt", "Manifest.txt", "README.txt", "Rakefile", "TODO", "gchartrb.gemspec", "lib/core_ext.rb", "lib/example.rb", "lib/gchartrb.rb", "lib/google_chart.rb", "lib/google_chart/bar_chart.rb", "lib/google_chart/base.rb", "lib/google_chart/line_chart.rb", "lib/google_chart/linexy_chart.rb", "lib/google_chart/map_chart.rb", "lib/google_chart/modules/axis.rb", "lib/google_chart/modules/color.rb", "lib/google_chart/modules/data_array.rb", "lib/google_chart/modules/fills.rb", "lib/google_chart/modules/grid.rb", "lib/google_chart/modules/label.rb", "lib/google_chart/modules/legend.rb", "lib/google_chart/modules/markers.rb", "lib/google_chart/pie_chart.rb", "lib/google_chart/radar_chart.rb", "lib/google_chart/scatter_plot.rb", "lib/google_chart/sparkline_chart.rb", "lib/google_chart/venn_diagram.rb", "lib/test.rb", "scripts/iso3166_en_code_lists.txt", "scripts/process_country_codes.rb", "spec/gchartrb/axis_spec.rb", "spec/gchartrb/bar_chart_spec.rb", "spec/gchartrb/fills_spec.rb", "spec/gchartrb/grid_spec.rb", "spec/gchartrb/line_chart_spec.rb", "spec/gchartrb/linexy_chart_spec.rb", "spec/gchartrb/markers_spec.rb", "spec/gchartrb/pie_chart_spec.rb", "spec/gchartrb/radar_chart_spec.rb", "spec/gchartrb/scatter_plot_spec.rb", "spec/gchartrb/sparkline_chart_spec.rb", "spec/gchartrb/venn_diagram_spec.rb", "spec/gchartrb_spec.rb", "spec/helper.rb", "spec/spec.opts" ]
|
|
15
|
+
s.require_paths = ["lib"]
|
|
16
|
+
s.rubyforge_project = "gchartrb"
|
|
17
|
+
s.rubygems_version = "1.1.1"
|
|
18
|
+
end
|
data/lib/core_ext.rb
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
class Array
|
|
2
|
+
# Returns true if all elements are numeric
|
|
3
|
+
def is_numeric_array?
|
|
4
|
+
self.all? {|data| data.is_a?(Numeric) }
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
# Returns true if all elements are numeric in form [X,Y]
|
|
8
|
+
def is_numeric_2d_array?
|
|
9
|
+
self.all? do |data|
|
|
10
|
+
data.is_a?(Array) &&
|
|
11
|
+
data.size == 2 &&
|
|
12
|
+
data.is_numeric_array?
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Returns all the X values of an array containing elements of the form [X,Y]
|
|
17
|
+
def x_values
|
|
18
|
+
raise ArgumentError.new("#{self.inspect} is not a 2D numeric array") unless is_numeric_2d_array?
|
|
19
|
+
self.collect { |item| item.first }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Returns all the Y values of an array containing elements of the form [X,Y]
|
|
23
|
+
def y_values
|
|
24
|
+
raise ArgumentError.new("#{self.inspect} is not a 2D numeric array") unless is_numeric_2d_array?
|
|
25
|
+
self.collect { |item| item.last }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
class Numeric
|
|
31
|
+
def is_numeric? ; true ; end
|
|
32
|
+
end
|
data/lib/example.rb
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require 'gchartrb'
|
|
2
|
+
|
|
3
|
+
# Some examples from http://24ways.org/2007/tracking-christmas-cheer-with-google-charts
|
|
4
|
+
|
|
5
|
+
# Pie Chart
|
|
6
|
+
pc = GoogleChart::PieChart.new
|
|
7
|
+
pc.width = 600
|
|
8
|
+
pc.height = 300
|
|
9
|
+
pc.title = "Food and Drinks Consumed Christmas 2007"
|
|
10
|
+
|
|
11
|
+
pc.data "Egg nog", 10, '00AF33'
|
|
12
|
+
pc.data "Christmas Ham", 20, '4BB74C'
|
|
13
|
+
pc.data "Milk (not including egg nog)", 8, 'EE2C2C'
|
|
14
|
+
pc.data "Cookies", 25, 'CC3232'
|
|
15
|
+
pc.data "Roasted Chestnuts", 5, '33FF33'
|
|
16
|
+
pc.data "Chocolate", 3, '66FF66'
|
|
17
|
+
pc.data "Various Other Beverages", 15, '9AFF9A'
|
|
18
|
+
pc.data "Various Other Foods", 9, 'C1FFC1'
|
|
19
|
+
pc.data "Snacks", 5, 'CCFFCC'
|
|
20
|
+
puts pc.to_url
|
|
21
|
+
|
|
22
|
+
# Line Chart
|
|
23
|
+
x_axis_labels = (1..31).to_a.collect do |v|
|
|
24
|
+
if [1,6,25,26,31].member?(v)
|
|
25
|
+
if v == 1
|
|
26
|
+
"Dec 1st"
|
|
27
|
+
elsif v == 31
|
|
28
|
+
"Dec 31st"
|
|
29
|
+
elsif v
|
|
30
|
+
"#{v}th"
|
|
31
|
+
end
|
|
32
|
+
else
|
|
33
|
+
nil
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
y_axis_labels = (0..10).to_a.collect do |v|
|
|
38
|
+
val = 10 * v
|
|
39
|
+
if val ==50 or val == 100
|
|
40
|
+
val.to_s
|
|
41
|
+
else
|
|
42
|
+
nil
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
series_1_y = [30,45,20,50,15,80,60,70,40,55,80]
|
|
47
|
+
series_2_y = [50,10,30,55,60]
|
|
48
|
+
|
|
49
|
+
series_1_x = [1,6,8,10,18,23,25,26,28,29,31]
|
|
50
|
+
series_2_x = [1,4,6,9,11]
|
|
51
|
+
|
|
52
|
+
series_1_xy = series_1_x.zip(series_1_y)
|
|
53
|
+
series_2_xy = series_2_x.zip(series_2_y)
|
|
54
|
+
|
|
55
|
+
lcxy = GoogleChart::LineXYChart.new
|
|
56
|
+
lcxy.width = 800
|
|
57
|
+
lcxy.height = 300
|
|
58
|
+
lcxy.title = "Projected Christmas Cheer for 2007"
|
|
59
|
+
lcxy.data "2006", series_1_xy, '458B00'
|
|
60
|
+
lcxy.data "2007", series_2_xy, 'CD2626'
|
|
61
|
+
lcxy.max_x = 30
|
|
62
|
+
lcxy.max_y = 100
|
|
63
|
+
lcxy.encoding = :text
|
|
64
|
+
lcxy.axis :bottom, :labels => x_axis_labels
|
|
65
|
+
lcxy.axis :left, :labels => y_axis_labels
|
|
66
|
+
lcxy.grid :x_step => 3.333, :y_step => 10, :line_segment => 1, :blank_segment => 3
|
|
67
|
+
puts lcxy.to_url
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# Plotting a sparklines chart
|
|
71
|
+
sparklines = GoogleChart::SparklineChart.new :width => 100, :height => 40
|
|
72
|
+
sparklines.data "Test", [4,3,2,4,6,8,10]
|
|
73
|
+
puts sparklines.to_url
|
|
74
|
+
|
|
75
|
+
|
data/lib/gchartrb.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'google_chart'
|
data/lib/google_chart.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + "/core_ext"
|
|
2
|
+
%w(legend color data_array fills axis grid markers label).each do |mod|
|
|
3
|
+
require File.dirname(__FILE__) + "/google_chart/modules/#{mod}"
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
%w(base line_chart linexy_chart sparkline_chart scatter_plot bar_chart radar_chart venn_diagram pie_chart map_chart).each do |type|
|
|
7
|
+
require File.dirname(__FILE__) + "/google_chart/#{type}"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
module GoogleChart
|
|
11
|
+
# Blatantly copied from GChart (http://gchart.rubyforge.org)
|
|
12
|
+
URL = "http://chart.apis.google.com/chart"
|
|
13
|
+
|
|
14
|
+
SIMPLE_CHARS = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
|
|
15
|
+
EXTENDED_CHARS = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a + %w[- .]
|
|
16
|
+
EXTENDED_PAIRS = EXTENDED_CHARS.collect { |first| EXTENDED_CHARS.collect { |second| first + second } }.flatten
|
|
17
|
+
ENCODINGS = [:simple, :text, :extended]
|
|
18
|
+
|
|
19
|
+
class <<self
|
|
20
|
+
|
|
21
|
+
# Encode +n+ as a string. +n+ is normalized based on +max+.
|
|
22
|
+
# Blatantly copied from GChart (http://gchart.rubyforge.org)
|
|
23
|
+
def encode(encoding, n, max)
|
|
24
|
+
case encoding
|
|
25
|
+
when :simple
|
|
26
|
+
return "_" if n.nil?
|
|
27
|
+
SIMPLE_CHARS[((n/max.to_f) * (SIMPLE_CHARS.size - 1)).round]
|
|
28
|
+
when :text
|
|
29
|
+
return "-1" if n.nil?
|
|
30
|
+
((((n/max.to_f) * 1000.0).round)/10.0).to_s
|
|
31
|
+
when :extended
|
|
32
|
+
return "__" if n.nil?
|
|
33
|
+
EXTENDED_PAIRS[max.zero? ? 0 : ((n/max.to_f) * (EXTENDED_PAIRS.size - 1)).round]
|
|
34
|
+
else
|
|
35
|
+
raise ArgumentError, "unsupported encoding: #{encoding.inspect}"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module GoogleChart
|
|
2
|
+
class BarChart < Base
|
|
3
|
+
include Legend
|
|
4
|
+
include Color
|
|
5
|
+
include DataArray
|
|
6
|
+
include Fills
|
|
7
|
+
include Axis
|
|
8
|
+
include Grid
|
|
9
|
+
include Markers
|
|
10
|
+
|
|
11
|
+
data_type :numeric_array
|
|
12
|
+
|
|
13
|
+
attr_accessor :orientation, :grouping, :bar_width, :bar_spacing, :group_spacing
|
|
14
|
+
|
|
15
|
+
ORIENTATIONS = [:horizontal, :vertical]
|
|
16
|
+
GROUPINGS = [:grouped, :stacked]
|
|
17
|
+
|
|
18
|
+
def initialize(options={}) #:nodoc:
|
|
19
|
+
@orientation = :vertical
|
|
20
|
+
@grouping = :grouped
|
|
21
|
+
set_chart_type
|
|
22
|
+
@show_legend = true
|
|
23
|
+
super(options)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def orientation=(o)
|
|
28
|
+
raise ArgumentError.new("Orientation can only be :vertical or :horizontal") unless ORIENTATIONS.include?(o)
|
|
29
|
+
@orientation = o
|
|
30
|
+
set_chart_type
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def grouping=(g)
|
|
34
|
+
raise ArgumentError.new("Grouping can only be :grouped or :stacked") unless GROUPINGS.include?(g)
|
|
35
|
+
@grouping = g
|
|
36
|
+
set_chart_type
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def set_chart_type
|
|
40
|
+
@chart_type = (
|
|
41
|
+
if @orientation == :horizontal and @grouping == :grouped then "bhg"
|
|
42
|
+
elsif @orientation == :horizontal and @grouping == :stacked then "bhs"
|
|
43
|
+
elsif @orientation == :vertical and @grouping == :grouped then "bvg"
|
|
44
|
+
elsif @orientation == :vertical and @grouping == :stacked then "bvs"
|
|
45
|
+
end
|
|
46
|
+
)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def bar_width=(width)
|
|
50
|
+
raise ArgumentError.new("bar width should be in integer") unless width.is_a?(Integer)
|
|
51
|
+
@bar_width = width
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def bar_spacing=(spacing)
|
|
55
|
+
raise ArgumentError.new("bar spacing should be in integer") unless spacing.is_a?(Integer)
|
|
56
|
+
raise ArgumentError.new("cannot specify bar spacing without specifying bar width first") unless @bar_width
|
|
57
|
+
@bar_spacing = spacing
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def group_spacing=(spacing)
|
|
61
|
+
raise ArgumentError.new("bar spacing should be in integer") unless spacing.is_a?(Integer)
|
|
62
|
+
raise ArgumentError.new("cannot specify group spacing without specifying bar width first") unless @bar_width
|
|
63
|
+
raise ArgumentError.new("cannot specify group spacing without specifying bar spacing first") unless @bar_spacing
|
|
64
|
+
@group_spacing = spacing
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def add_bar_width_and_spacing
|
|
68
|
+
str = "#{@bar_width}" if @bar_width
|
|
69
|
+
str+= ",#{@bar_spacing}" if @bar_spacing
|
|
70
|
+
str+= ",#{@group_spacing}" if @group_spacing
|
|
71
|
+
@params[:chbh] = str if str
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def encode_data
|
|
75
|
+
# override encode_data to set custom max value for stacked charts (unless max is already set)
|
|
76
|
+
if grouping == :stacked and not self.max
|
|
77
|
+
# set max value to the max value of sums
|
|
78
|
+
self.max = @data.inject(Array.new(@data.first.size,0)) { |sum_series, series| sum_series.zip(series).collect { |d| d.first + d.last } }.max
|
|
79
|
+
end
|
|
80
|
+
super
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|