rbgct 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,4 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
- docs/*
5
+ ignore/*
data/README.markdown CHANGED
@@ -5,7 +5,46 @@
5
5
  $ gem install rbgct
6
6
  </pre>
7
7
 
8
- ## Line Chart
8
+ ## Implemented Classes
9
+
10
+ * [LineChart](http://code.google.com/apis/chart/interactive/docs/gallery/linechart.html)
11
+ * [PieChart](http://code.google.com/apis/chart/interactive/docs/gallery/piechart.html)
12
+
13
+ ## TODO
14
+
15
+ *way too much!*
16
+
17
+ * Add Specs
18
+ * Add Documentation
19
+ * Implement More :chart_options
20
+ * Fix Known Bugs
21
+ * Implement:
22
+ * Annotated Time Line
23
+ * Area Chart
24
+ * Bar Chart
25
+ * Candlestick Chart
26
+ * Chart Editor
27
+ * Chart Wrapper
28
+ * Column Chart
29
+ * Combo Chart
30
+ * Gauge
31
+ * Geo Chart
32
+ * Geo Map
33
+ * Image Chart
34
+ * Image Area Chart
35
+ * Image Bar Chart
36
+ * Image Candlestick Chart
37
+ * Image Line Chart
38
+ * Image Pie Chart
39
+ * Intensity Map
40
+ * Motion Chart
41
+ * Org Chart
42
+ * Scatter Chart
43
+ * Sparkline
44
+ * Table
45
+ * Tree Map
46
+
47
+ ## LineChart
9
48
  <pre>
10
49
  SampleData = Struct.new(:date, :values)
11
50
  fantasy_data = (0..100).to_a.map {|i| SampleData.new((Time.now + 60*5*i).strftime("%H:%M"), rand(500)) }
@@ -24,132 +63,29 @@ Rbgct.render(fantasy_data,{
24
63
  }})
25
64
  </pre>
26
65
 
27
- ## Line Chart output in HTML
28
- <pre>
29
- <script type="text/javascript" src="http://www.google.com/jsapi"></script>
30
- <script type="text/javascript">
31
- google.load('visualization', '1', {packages: ['corechart']});
32
- </script>
33
-
34
- <script type="text/javascript">
35
- function drawVisualization() {
36
- // Create and populate the data table.
37
- var data = new google.visualization.DataTable();
38
-
39
- data.addColumn('string', 'time');
40
- data.addColumn('number', 'transactions');
41
- data.addRow(['10:58', 184]);
42
- data.addRow(['11:03', 380]);
43
- data.addRow(['11:08', 231]);
44
- data.addRow(['11:13', 133]);
45
- data.addRow(['11:18', 282]);
46
- data.addRow(['11:23', 99]);
47
- data.addRow(['11:28', 86]);
48
- data.addRow(['11:33', 50]);
49
- data.addRow(['11:38', 144]);
50
- data.addRow(['11:43', 399]);
51
- data.addRow(['11:48', 38]);
52
- data.addRow(['11:53', 466]);
53
- data.addRow(['11:58', 402]);
54
- data.addRow(['12:03', 365]);
55
- data.addRow(['12:08', 408]);
56
- data.addRow(['12:13', 436]);
57
- data.addRow(['12:18', 248]);
58
- data.addRow(['12:23', 156]);
59
- data.addRow(['12:28', 109]);
60
- data.addRow(['12:33', 272]);
61
- data.addRow(['12:38', 290]);
62
- data.addRow(['12:43', 465]);
63
- data.addRow(['12:48', 301]);
64
- data.addRow(['12:53', 171]);
65
- data.addRow(['12:58', 223]);
66
- data.addRow(['13:03', 157]);
67
- data.addRow(['13:08', 139]);
68
- data.addRow(['13:13', 115]);
69
- data.addRow(['13:18', 205]);
70
- data.addRow(['13:23', 314]);
71
- data.addRow(['13:28', 443]);
72
- data.addRow(['13:33', 428]);
73
- data.addRow(['13:38', 462]);
74
- data.addRow(['13:43', 347]);
75
- data.addRow(['13:48', 291]);
76
- data.addRow(['13:53', 69]);
77
- data.addRow(['13:58', 383]);
78
- data.addRow(['14:03', 84]);
79
- data.addRow(['14:08', 247]);
80
- data.addRow(['14:13', 73]);
81
- data.addRow(['14:18', 9]);
82
- data.addRow(['14:23', 120]);
83
- data.addRow(['14:28', 17]);
84
- data.addRow(['14:33', 441]);
85
- data.addRow(['14:38', 161]);
86
- data.addRow(['14:43', 154]);
87
- data.addRow(['14:48', 281]);
88
- data.addRow(['14:53', 498]);
89
- data.addRow(['14:58', 363]);
90
- data.addRow(['15:03', 11]);
91
- data.addRow(['15:08', 99]);
92
- data.addRow(['15:13', 84]);
93
- data.addRow(['15:18', 460]);
94
- data.addRow(['15:23', 350]);
95
- data.addRow(['15:28', 204]);
96
- data.addRow(['15:33', 177]);
97
- data.addRow(['15:38', 174]);
98
- data.addRow(['15:43', 200]);
99
- data.addRow(['15:48', 111]);
100
- data.addRow(['15:53', 293]);
101
- data.addRow(['15:58', 112]);
102
- data.addRow(['16:03', 274]);
103
- data.addRow(['16:08', 43]);
104
- data.addRow(['16:13', 324]);
105
- data.addRow(['16:18', 190]);
106
- data.addRow(['16:23', 371]);
107
- data.addRow(['16:28', 455]);
108
- data.addRow(['16:33', 63]);
109
- data.addRow(['16:38', 432]);
110
- data.addRow(['16:43', 63]);
111
- data.addRow(['16:48', 17]);
112
- data.addRow(['16:53', 377]);
113
- data.addRow(['16:58', 176]);
114
- data.addRow(['17:03', 211]);
115
- data.addRow(['17:08', 105]);
116
- data.addRow(['17:13', 18]);
117
- data.addRow(['17:18', 46]);
118
- data.addRow(['17:23', 368]);
119
- data.addRow(['17:28', 171]);
120
- data.addRow(['17:33', 404]);
121
- data.addRow(['17:38', 82]);
122
- data.addRow(['17:43', 417]);
123
- data.addRow(['17:48', 13]);
124
- data.addRow(['17:53', 189]);
125
- data.addRow(['17:58', 216]);
126
- data.addRow(['18:03', 259]);
127
- data.addRow(['18:08', 4]);
128
- data.addRow(['18:13', 4]);
129
- data.addRow(['18:18', 339]);
130
- data.addRow(['18:23', 5]);
131
- data.addRow(['18:28', 194]);
132
- data.addRow(['18:33', 127]);
133
- data.addRow(['18:38', 247]);
134
- data.addRow(['18:43', 42]);
135
- data.addRow(['18:48', 29]);
136
- data.addRow(['18:53', 357]);
137
- data.addRow(['18:58', 65]);
138
- data.addRow(['19:03', 300]);
139
- data.addRow(['19:08', 355]);
140
- data.addRow(['19:13', 58]);
141
- data.addRow(['19:18', 58]);
142
-
143
- // Create and draw the visualization.
144
- new google.visualization.LineChart(document.getElementById('transactions_linechart')).
145
- draw(data, {width: 1600, height: 600 , vAxis: {maxValue: 498}, curveType: "function"});
146
- }
66
+ ## LineChart in Google Beauty
67
+ ![LineChart RbGTC](http://mekdigital.com/files/rbgct_linechart_example.png "LineChart")
147
68
 
148
- google.setOnLoadCallback(drawVisualization);
149
- </script>
150
- <div id="transactions_linechart" style="width: 1600px; height: 600px;"></div>
69
+ ## PieChart
70
+ <pre>
71
+ SampleDataPieChart = Struct.new(:label, :value)
72
+ fantasy_data = ['OSX', 'WIN', 'LINUX'].map{ |os| SampleDataPieChart.new(os,rand(99999999))}
151
73
 
74
+ Rbgct.render(fantasy_data, {
75
+ :type => :pie_chart,
76
+ :name => :label,
77
+ :value => :value,
78
+ :name_label => 'Type',
79
+ :value_label => 'Installations',
80
+ :chart_options =>{
81
+ :width => 600,
82
+ :height => 600,
83
+ :dom_id => 'graph',
84
+ :is_3d => true,
85
+ :title => "Operating Systems Installations (2012)"
86
+ }
87
+ })
152
88
  </pre>
153
89
 
154
- ## Line Chart in Google Beauty
155
- ![Line Graph](http://mekdigital.com/files/rbgct_example.png "Title")
90
+ ## PieChart in Google Beauty
91
+ ![PieChart RbGTC](http://mekdigital.com/files/rbgct_piechart_example.png "PieChart")
data/THANKYOU.markdown ADDED
@@ -0,0 +1,4 @@
1
+ # Special Thanks
2
+ ## This library was inspired by [SEER](https://github.com/Bantik/seer)..
3
+ ### .. so thanks to the original author Corey Ehmke.
4
+ ## Ideas, suggestions, bug-fix (and more) by Christopher Hill
@@ -5,6 +5,8 @@ module Rbgct
5
5
  case type
6
6
  when :line_chart
7
7
  Charts::LineChart
8
+ when :pie_chart
9
+ Charts::PieChart
8
10
  else
9
11
  raise NotImplementedError, "No ChartFactory class for type #{type || 'NULL'}"
10
12
  end
@@ -5,9 +5,20 @@ module Rbgct::Charts
5
5
  DEFAULT_WIDTH = 600
6
6
  DEFAULT_HEIGHT = 400
7
7
 
8
- attr_accessor :data, :type
8
+ attr_accessor :data, :type, :class_name
9
9
  attr_accessor :width, :height, :dom_id, :title, :h_title, :v_title, :top, :left, :legend, :x_strftime, :y_strftime, :time_offset
10
-
10
+
11
+
12
+ def render
13
+ <<-EOL
14
+ #{jsapi}
15
+ #{draw_visualization_start}
16
+ #{data_columns}
17
+ #{data_rows}
18
+ #{draw_visualization_end}
19
+ EOL
20
+ end
21
+
11
22
  def jsapi
12
23
  <<-EOL
13
24
  <script type="text/javascript" src="http://www.google.com/jsapi"></script>
@@ -30,7 +41,7 @@ module Rbgct::Charts
30
41
  <<-EOL
31
42
 
32
43
  // Create and draw the visualization.
33
- new google.visualization.LineChart(document.getElementById('#{dom_id}')).
44
+ new google.visualization.#{class_name}(document.getElementById('#{dom_id}')).
34
45
  draw(data, {width: #{width}, height: #{height}, title: "#{title}", chartArea: {top: #{top}, left: #{left}} #{options_for_chart}});
35
46
  }
36
47
 
@@ -44,15 +55,18 @@ module Rbgct::Charts
44
55
  case type
45
56
  when :line_chart
46
57
  'corechart'
58
+ when :pie_chart
59
+ 'corechart'
47
60
  end
48
61
  end
49
62
 
50
63
  def set_default_values
51
- @dom_id ||= 'visualization'
52
- @width ||= DEFAULT_WIDTH
53
- @height ||= DEFAULT_HEIGHT
54
- @top ||= 'auto'
55
- @left ||= 'auto'
64
+ @dom_id ||= 'visualization'
65
+ @width ||= DEFAULT_WIDTH
66
+ @height ||= DEFAULT_HEIGHT
67
+ @top ||= 100
68
+ @left ||= 100
69
+ @class_name ||= self.class.name.sub('Rbgct::Charts::','')
56
70
  end
57
71
 
58
72
  end
@@ -23,16 +23,6 @@ module Rbgct::Charts
23
23
  set_default_values_line_chart
24
24
  end
25
25
 
26
- def render
27
- <<-EOL
28
- #{jsapi}
29
- #{draw_visualization_start}
30
- #{data_columns}
31
- #{data_rows}
32
- #{draw_visualization_end}
33
- EOL
34
- end
35
-
36
26
  def data_columns
37
27
  "data.addColumn('string', '#{x_label}');\n" +
38
28
  Array(y_label).map{|lbl| %(data.addColumn('number', '#{lbl}');)}.join("\n")
@@ -0,0 +1,44 @@
1
+ module Rbgct::Charts
2
+
3
+ class PieChart
4
+
5
+ include Chart
6
+
7
+ attr_accessor :name, :value, :name_label, :value_label, :is3D
8
+
9
+ def initialize(data, opts)
10
+ raise ArgumentError.new('name or value are not defined') unless opts[:name] && opts[:value]
11
+
12
+ @data = data
13
+
14
+ opts.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method)}
15
+
16
+ opts[:chart_options] ||= {}
17
+ opts[:chart_options].each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method)}
18
+
19
+ set_default_values # in Chart
20
+ set_default_values_pie_chart
21
+ end
22
+
23
+ def data_columns
24
+ "data.addColumn('string', '#{name_label}');
25
+ data.addColumn('number', '#{value_label}');"
26
+ end
27
+
28
+ def data_rows
29
+ data.inject([]) do |ary, el|
30
+ ary << " data.setValue(#{ary.size}, 0, '#{el.send(name)}');\n data.setValue(#{ary.size}, 1, #{el.send(value)});"
31
+ end.unshift("data.addRows(#{data.size});").join("\n")
32
+ end
33
+
34
+ def options_for_chart
35
+ %(, is3D: "#{is3D}")
36
+ end
37
+
38
+ def set_default_values_pie_chart
39
+ @is3D ||= true
40
+ end
41
+
42
+ end
43
+
44
+ end
data/lib/rbgct/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rbgct
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/rbgct.rb CHANGED
@@ -3,6 +3,7 @@ module Rbgct
3
3
  require 'rbgct/chart_factory'
4
4
  require 'rbgct/charts/chart'
5
5
  require 'rbgct/charts/line_chart'
6
+ require 'rbgct/charts/pie_chart'
6
7
 
7
8
  class NotImplementedError < StandardError; end
8
9
 
metadata CHANGED
@@ -1,8 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbgct
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.7
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 8
9
+ version: 0.0.8
6
10
  platform: ruby
7
11
  authors:
8
12
  - Emanuele Tozzato
@@ -10,7 +14,8 @@ autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
16
 
13
- date: 2011-06-29 00:00:00 Z
17
+ date: 2011-06-30 00:00:00 -07:00
18
+ default_executable:
14
19
  dependencies: []
15
20
 
16
21
  description: "Google Chart Tools provide a perfect way to visualize data on your website: now on Ruby"
@@ -24,18 +29,20 @@ extra_rdoc_files: []
24
29
 
25
30
  files:
26
31
  - .gitignore
27
- - CONTRIBUTORS
28
32
  - Gemfile
29
33
  - LICENSE
30
34
  - README.markdown
31
35
  - Rakefile
36
+ - THANKYOU.markdown
32
37
  - init.rb
33
38
  - lib/rbgct.rb
34
39
  - lib/rbgct/chart_factory.rb
35
40
  - lib/rbgct/charts/chart.rb
36
41
  - lib/rbgct/charts/line_chart.rb
42
+ - lib/rbgct/charts/pie_chart.rb
37
43
  - lib/rbgct/version.rb
38
44
  - rbgct.gemspec
45
+ has_rdoc: true
39
46
  homepage: http://www.mekdigital.com
40
47
  licenses: []
41
48
 
@@ -49,17 +56,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
56
  requirements:
50
57
  - - ">="
51
58
  - !ruby/object:Gem::Version
59
+ segments:
60
+ - 0
52
61
  version: "0"
53
62
  required_rubygems_version: !ruby/object:Gem::Requirement
54
63
  none: false
55
64
  requirements:
56
65
  - - ">="
57
66
  - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
58
69
  version: "0"
59
70
  requirements: []
60
71
 
61
72
  rubyforge_project: rbgct
62
- rubygems_version: 1.7.2
73
+ rubygems_version: 1.3.7
63
74
  signing_key:
64
75
  specification_version: 3
65
76
  summary: Ruby Google Chart Tools
data/CONTRIBUTORS DELETED
@@ -1,3 +0,0 @@
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.
3
- AND Christopher Hill!!!