rbgct 0.0.2

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/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ docs/*
data/CONTRIBUTORS ADDED
@@ -0,0 +1,2 @@
1
+ This library is inspired by SEER.
2
+ Thanks to the author Corey Ehmke and to the contributors Alexey Kuleshov, Harold Giménez, Henry Poydar
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rbgct.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Emanuele Tozzato / mekdigital.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,149 @@
1
+ # RbGCT - Ruby Google Chart Tools
2
+ ### because charting should be a pleasure!
3
+
4
+ <pre>
5
+ $ gem install rbgct
6
+ </pre>
7
+
8
+ ## Line Chart
9
+ <pre>
10
+ SampleData = Struct.new(:date, :values)
11
+ fantasy_data = (0..100).to_a.map {|i| SampleData.new((Time.now + 60*5*i).strftime("%H:%M"), rand(500)) }
12
+
13
+ Rbgct.render(fantasy_data,{ :type => :line_chart,
14
+ :x_method => :date,
15
+ :y_method => :values,
16
+ :x_label => :time,
17
+ :y_label => :transactions})
18
+ </pre>
19
+
20
+ ## Line Chart output in HTML
21
+ <pre>
22
+ <script type="text/javascript" src="http://www.google.com/jsapi"></script>
23
+ <script type="text/javascript">
24
+ google.load('visualization', '1', {packages: ['corechart']});
25
+ </script>
26
+
27
+ <script type="text/javascript">
28
+ function drawVisualization() {
29
+ // Create and populate the data table.
30
+ var data = new google.visualization.DataTable();
31
+ data.addColumn('string', 'time');
32
+ data.addColumn('number', 'transactions');
33
+ data.addRow(['01:00', 7]);
34
+ data.addRow(['01:05', 314]);
35
+ data.addRow(['01:10', 267]);
36
+ data.addRow(['01:15', 39]);
37
+ data.addRow(['01:20', 240]);
38
+ data.addRow(['01:25', 461]);
39
+ data.addRow(['01:30', 86]);
40
+ data.addRow(['01:35', 336]);
41
+ data.addRow(['01:40', 486]);
42
+ data.addRow(['01:45', 170]);
43
+ data.addRow(['01:50', 191]);
44
+ data.addRow(['01:55', 252]);
45
+ data.addRow(['02:00', 375]);
46
+ data.addRow(['02:05', 432]);
47
+ data.addRow(['02:10', 106]);
48
+ data.addRow(['02:15', 495]);
49
+ data.addRow(['02:20', 226]);
50
+ data.addRow(['02:25', 255]);
51
+ data.addRow(['02:30', 20]);
52
+ data.addRow(['02:35', 335]);
53
+ data.addRow(['02:40', 116]);
54
+ data.addRow(['02:45', 125]);
55
+ data.addRow(['02:50', 53]);
56
+ data.addRow(['02:55', 341]);
57
+ data.addRow(['03:00', 189]);
58
+ data.addRow(['03:05', 303]);
59
+ data.addRow(['03:10', 156]);
60
+ data.addRow(['03:15', 388]);
61
+ data.addRow(['03:20', 228]);
62
+ data.addRow(['03:25', 291]);
63
+ data.addRow(['03:30', 173]);
64
+ data.addRow(['03:35', 456]);
65
+ data.addRow(['03:40', 203]);
66
+ data.addRow(['03:45', 186]);
67
+ data.addRow(['03:50', 7]);
68
+ data.addRow(['03:55', 49]);
69
+ data.addRow(['04:00', 444]);
70
+ data.addRow(['04:05', 12]);
71
+ data.addRow(['04:10', 37]);
72
+ data.addRow(['04:15', 490]);
73
+ data.addRow(['04:20', 2]);
74
+ data.addRow(['04:25', 155]);
75
+ data.addRow(['04:30', 50]);
76
+ data.addRow(['04:35', 235]);
77
+ data.addRow(['04:40', 412]);
78
+ data.addRow(['04:45', 167]);
79
+ data.addRow(['04:50', 89]);
80
+ data.addRow(['04:55', 488]);
81
+ data.addRow(['05:00', 74]);
82
+ data.addRow(['05:05', 353]);
83
+ data.addRow(['05:10', 262]);
84
+ data.addRow(['05:15', 89]);
85
+ data.addRow(['05:20', 374]);
86
+ data.addRow(['05:25', 296]);
87
+ data.addRow(['05:30', 275]);
88
+ data.addRow(['05:35', 105]);
89
+ data.addRow(['05:40', 70]);
90
+ data.addRow(['05:45', 409]);
91
+ data.addRow(['05:50', 429]);
92
+ data.addRow(['05:55', 445]);
93
+ data.addRow(['06:00', 38]);
94
+ data.addRow(['06:05', 125]);
95
+ data.addRow(['06:10', 340]);
96
+ data.addRow(['06:15', 425]);
97
+ data.addRow(['06:20', 189]);
98
+ data.addRow(['06:25', 357]);
99
+ data.addRow(['06:30', 220]);
100
+ data.addRow(['06:35', 69]);
101
+ data.addRow(['06:40', 344]);
102
+ data.addRow(['06:45', 292]);
103
+ data.addRow(['06:50', 243]);
104
+ data.addRow(['06:55', 287]);
105
+ data.addRow(['07:00', 162]);
106
+ data.addRow(['07:05', 116]);
107
+ data.addRow(['07:10', 174]);
108
+ data.addRow(['07:15', 187]);
109
+ data.addRow(['07:20', 227]);
110
+ data.addRow(['07:25', 425]);
111
+ data.addRow(['07:30', 376]);
112
+ data.addRow(['07:35', 387]);
113
+ data.addRow(['07:40', 210]);
114
+ data.addRow(['07:45', 136]);
115
+ data.addRow(['07:50', 202]);
116
+ data.addRow(['07:55', 471]);
117
+ data.addRow(['08:00', 313]);
118
+ data.addRow(['08:05', 63]);
119
+ data.addRow(['08:10', 326]);
120
+ data.addRow(['08:15', 482]);
121
+ data.addRow(['08:20', 190]);
122
+ data.addRow(['08:25', 183]);
123
+ data.addRow(['08:30', 434]);
124
+ data.addRow(['08:35', 242]);
125
+ data.addRow(['08:40', 257]);
126
+ data.addRow(['08:45', 42]);
127
+ data.addRow(['08:50', 279]);
128
+ data.addRow(['08:55', 223]);
129
+ data.addRow(['09:00', 103]);
130
+ data.addRow(['09:05', 447]);
131
+ data.addRow(['09:10', 41]);
132
+ data.addRow(['09:15', 325]);
133
+ data.addRow(['09:20', 327]);
134
+
135
+ // Create and draw the visualization.
136
+ new google.visualization.LineChart(document.getElementById('visualization')).
137
+ draw(data, {curveType: "function",
138
+ width: 1000, height: 400,
139
+ vAxis: {maxValue: 495}}
140
+ );
141
+ }
142
+
143
+ google.setOnLoadCallback(drawVisualization);
144
+ </script>
145
+ <div id="visualization" style="width: 1000px; height: 400px;"></div>
146
+ </pre>
147
+
148
+ ## Line Chart in Google Beauty
149
+ ![Line Graph](http://mekdigital.com/files/rbgct_example.png "Title")
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '.', 'lib'))
2
+ require 'rbgct'
@@ -0,0 +1,14 @@
1
+ module Rbgct
2
+
3
+ class ChartFactory
4
+ def self.[](type)
5
+ case type
6
+ when :line_chart
7
+ Charts::LineChart
8
+ else
9
+ raise NotImplementedError, "No ChartFactory class for type #{type || 'NULL'}"
10
+ end
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,64 @@
1
+ module Rbgct::Charts
2
+
3
+ module Chart
4
+
5
+ DEFAULT_WIDTH = 600
6
+ DEFAULT_HEIGHT = 400
7
+
8
+ attr_accessor :data, :type
9
+ attr_accessor :width, :height
10
+
11
+ def jsapi
12
+ <<-EOL
13
+ <script type="text/javascript" src="http://www.google.com/jsapi"></script>
14
+ <script type="text/javascript">
15
+ google.load('visualization', '1', {packages: ['#{package}']});
16
+ </script>
17
+ EOL
18
+ end
19
+
20
+ def draw_visualization_start
21
+ <<-EOL
22
+ <script type="text/javascript">
23
+ function drawVisualization() {
24
+ // Create and populate the data table.
25
+ var data = new google.visualization.DataTable();
26
+ EOL
27
+ end
28
+
29
+ def draw_visualization_end
30
+ <<-EOL
31
+
32
+ // Create and draw the visualization.
33
+ new google.visualization.LineChart(document.getElementById('visualization')).
34
+ draw(data, {curveType: "function",
35
+ width: #{width}, height: #{height},
36
+ vAxis: {maxValue: #{max_value}}}
37
+ );
38
+ }
39
+
40
+ google.setOnLoadCallback(drawVisualization);
41
+ </script>
42
+ <div id="visualization" style="width: #{width}px; height: #{height}px;"></div>
43
+ EOL
44
+ end
45
+
46
+ def package
47
+ case type
48
+ when :line_chart
49
+ 'corechart'
50
+ end
51
+ end
52
+
53
+ def max_value
54
+ @max_value ||= data.map(&:"#{y_method}").flatten.max
55
+ end
56
+
57
+ def set_default_values
58
+ @width ||= DEFAULT_WIDTH
59
+ @height ||= DEFAULT_HEIGHT
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -0,0 +1,38 @@
1
+ module Rbgct::Charts
2
+
3
+ class LineChart
4
+
5
+ include Chart
6
+
7
+ attr_accessor :x_label, :x_method, :y_label, :y_method
8
+ attr_accessor :max_value
9
+
10
+ def initialize(data, opts)
11
+ @data = data
12
+ opts.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method)}
13
+ opts[:chart_options].each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method)}
14
+ set_default_values # in Chart
15
+ end
16
+
17
+ def render
18
+ <<-EOL
19
+ #{jsapi}
20
+ #{draw_visualization_start}
21
+ #{data_columns}
22
+ #{data_rows}
23
+ #{draw_visualization_end}
24
+ EOL
25
+ end
26
+
27
+ def data_columns
28
+ "data.addColumn('string', '#{x_label}');\n" +
29
+ Array(y_label).map{|lbl| %(data.addColumn('number', '#{lbl}');)}.join("\n")
30
+ end
31
+
32
+ def data_rows
33
+ data.map do |row|
34
+ %(data.addRow(['#{row.send(x_method)}', #{Array(row.send(y_method)).join(",")}]);)
35
+ end.join("\n")
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Rbgct
2
+ VERSION = "0.0.2"
3
+ end
data/lib/rbgct.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Rbgct
2
+
3
+ require 'rbgct/chart_factory'
4
+ require 'rbgct/charts/chart'
5
+ require 'rbgct/charts/line_chart'
6
+
7
+ class NotImplementedError < StandardError; end
8
+
9
+ def self.render(data, opts={})
10
+ chart = ChartFactory[opts[:type]].new(data,opts)
11
+ chart.render
12
+ end
13
+
14
+ end
data/rbgct.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rbgct/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rbgct"
7
+ s.version = Rbgct::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Emanuele Tozzato"]
10
+ s.email = ["etozzato@gmail.com"]
11
+ s.homepage = "http://www.mekdigital.com"
12
+ s.summary = %q{Ruby Google Chart Tools}
13
+ s.description = %q{Google Chart Tools provide a perfect way to visualize data on your website: now on Ruby}
14
+
15
+ s.rubyforge_project = "rbgct"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbgct
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - Emanuele Tozzato
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-24 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description: "Google Chart Tools provide a perfect way to visualize data on your website: now on Ruby"
17
+ email:
18
+ - etozzato@gmail.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - .gitignore
27
+ - CONTRIBUTORS
28
+ - Gemfile
29
+ - LICENSE
30
+ - README.markdown
31
+ - Rakefile
32
+ - init.rb
33
+ - lib/rbgct.rb
34
+ - lib/rbgct/chart_factory.rb
35
+ - lib/rbgct/charts/chart.rb
36
+ - lib/rbgct/charts/line_chart.rb
37
+ - lib/rbgct/version.rb
38
+ - rbgct.gemspec
39
+ homepage: http://www.mekdigital.com
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ requirements: []
60
+
61
+ rubyforge_project: rbgct
62
+ rubygems_version: 1.7.2
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Ruby Google Chart Tools
66
+ test_files: []
67
+