garru-g_viz 0.0.2 → 0.0.3

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 CHANGED
@@ -1,2 +1,3 @@
1
+ v0.0.3 separated data table from graph to make it more powerful.
1
2
  v0.0.2 this version is usable. Introduced graph.add_(graph_name) semantic sugar.
2
3
  v0.0.1 making this a gem
data/Manifest CHANGED
@@ -1,11 +1,12 @@
1
1
  CHANGELOG
2
+ lib/g_viz/data.rb
2
3
  lib/g_viz/g_viz.rb
3
- lib/g_viz/graph.rb
4
- lib/g_viz/templates/visualization.erb
4
+ lib/g_viz/json_google.rb
5
+ lib/g_viz/templates/data_tables.erb
5
6
  lib/g_viz.rb
6
7
  Manifest
7
8
  Rakefile
8
- README
9
+ README.markdown
9
10
  spec/g_viz/fixtures/annotated_timeline.rb
10
11
  spec/g_viz/g_viz_spec.rb
11
12
  spec/g_viz/templates/rendered_annotated_timeline.html
data/README.markdown ADDED
@@ -0,0 +1,113 @@
1
+ # GViz
2
+
3
+ GViz is a simple Ruby wrapper for the Google Visualization API
4
+
5
+ ## Usage
6
+
7
+ ### Definitions
8
+ <dl>
9
+ <dt>chart_type</dt>
10
+ <dd>Google Visualization Chart Constructor</dd>
11
+ <dt>data</dt>
12
+ <dd>An array of objects that responds to [](key) i.e. and array of Hashes</dd>
13
+ <dt>mapping</dt>
14
+ <dd>An array of key, description pairs that we are using as data points for our chart</dd>
15
+ </dl>
16
+
17
+ GViz::Base keeps track of charts that need to be rendered.
18
+
19
+ chart = GViz::Base.new
20
+ dom_id = chart.add_graph(chart_type, data, mapping, config_options)
21
+ chart.output
22
+
23
+ You can add multiple visualizations
24
+
25
+ chart = GViz::Base.new
26
+ dom_id1 = chart.add_graph(chart_type, data, mapping, config_options)
27
+ dom_id2 = chart.add_graph(chart_type, data, mapping, config_options)
28
+ chart.output
29
+
30
+ You can use dynamic adders
31
+
32
+ #chart_type for dynamic adders are lowercased and underscored
33
+ chart = GViz::Base.new
34
+ dom_id1 = chart.add_chart_type(data, mapping, config_options)
35
+ chart.output
36
+
37
+ ## Examples
38
+ ### AnnotatedTimeLine
39
+
40
+ mapping = [[:date, 'Date'],[:sold_pencils, 'Solid Pencils'], [:title1, 'title1'], [:text1, 'text1'],
41
+ [:sold_pens, 'Sold Pens'], [:title2, 'title2'], [:text2, 'text2']]
42
+
43
+ data = [
44
+ {:date => "2008-02-01", :sold_pencils => 30000, :sold_pens => 40645},
45
+ {:date => Date.parse("2008-02-02"), :sold_pencils => 14045, :sold_pens => 20374},
46
+ {:date => Date.parse("2008-02-03"), :sold_pencils => 55022, :sold_pens => 50766},
47
+ {:date => Date.parse("2008-02-04"), :sold_pencils => 75284, :sold_pens => 14334, :title2 => 'Out of Stock',:text2 => 'Ran out of stock on pens at 4pm'},
48
+ {:date => Date.parse("2008-02-05"), :sold_pencils => 41476, :sold_pens => 66467, :title1 => 'Bought Pens',:text2 => 'Bought 200k pens'},
49
+ {:date => Date.parse("2008-02-06"), :sold_pencils => 33322, :sold_pens => 39463, :title1 => 'Bought Pens',:text2 => 'Bought 200k pens'}
50
+ ]
51
+
52
+ g = GViz::Base.new
53
+ chart_id = g.add_annotated_time_line(data, mapping)
54
+ puts g.output
55
+ puts "<div id='#{chart_id}'></div>"
56
+
57
+ Outputs
58
+
59
+ <script type='text/javascript' src='http://www.google.com/jsapi'></script>
60
+ <script type='text/javascript'>
61
+ google.load('visualization', '1', {'packages':['annotatedtimeline']});
62
+ google.setOnLoadCallback(drawChart);
63
+ function drawChart() {
64
+ var data_0 = new google.visualization.DataTable();
65
+ data_0.addColumn('date', 'Date')
66
+ data_0.addColumn('number', 'Solid Pencils')
67
+ data_0.addColumn('string', 'title1')
68
+ data_0.addColumn('number', 'Sold Pens')
69
+ data_0.addColumn('string', 'title2')
70
+ data_0.addColumn('string', 'text2')
71
+ data_0.addRows(6)
72
+ data_0.setValue(0, 0, new Date(2008, 1, 1))
73
+ data_0.setValue(0, 1, 30000)
74
+ data_0.setValue(0, 2, '')
75
+ data_0.setValue(0, 3, 40645)
76
+ data_0.setValue(0, 4, '')
77
+ data_0.setValue(0, 5, '')
78
+ data_0.setValue(1, 0, new Date(2008, 1, 2))
79
+ data_0.setValue(1, 1, 14045)
80
+ data_0.setValue(1, 2, '')
81
+ data_0.setValue(1, 3, 20374)
82
+ data_0.setValue(1, 4, '')
83
+ data_0.setValue(1, 5, '')
84
+ data_0.setValue(2, 0, new Date(2008, 1, 3))
85
+ data_0.setValue(2, 1, 55022)
86
+ data_0.setValue(2, 2, '')
87
+ data_0.setValue(2, 3, 50766)
88
+ data_0.setValue(2, 4, '')
89
+ data_0.setValue(2, 5, '')
90
+ data_0.setValue(3, 0, new Date(2008, 1, 4))
91
+ data_0.setValue(3, 1, 75284)
92
+ data_0.setValue(3, 2, '')
93
+ data_0.setValue(3, 3, 14334)
94
+ data_0.setValue(3, 4, 'Out of Stock')
95
+ data_0.setValue(3, 5, 'Ran out of stock on pens at 4pm')
96
+ data_0.setValue(4, 0, new Date(2008, 1, 5))
97
+ data_0.setValue(4, 1, 41476)
98
+ data_0.setValue(4, 2, 'Bought Pens')
99
+ data_0.setValue(4, 3, 66467)
100
+ data_0.setValue(4, 4, '')
101
+ data_0.setValue(4, 5, 'Bought 200k pens')
102
+ data_0.setValue(5, 0, new Date(2008, 1, 6))
103
+ data_0.setValue(5, 1, 33322)
104
+ data_0.setValue(5, 2, 'Bought Pens')
105
+ data_0.setValue(5, 3, 39463)
106
+ data_0.setValue(5, 4, '')
107
+ data_0.setValue(5, 5, 'Bought 200k pens')
108
+ var chart_data_0 = new google.visualization.AnnotatedTimeline(document.getElementById('annotatedtimeline0'));
109
+ chart_data_0.draw(data_0, {});
110
+ }
111
+ </script>
112
+ <div id='annotatedtimeline0'></div>
113
+
data/g_viz.gemspec CHANGED
@@ -2,18 +2,18 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{g_viz}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Gary Tsang"]
9
- s.date = %q{2009-05-04}
9
+ s.date = %q{2009-06-19}
10
10
  s.description = %q{Ruby Scribe Client. Package and Wrapper for generated ruby interfaces}
11
11
  s.email = %q{}
12
- s.extra_rdoc_files = ["CHANGELOG", "lib/g_viz/g_viz.rb", "lib/g_viz/graph.rb", "lib/g_viz/templates/visualization.erb", "lib/g_viz.rb", "README"]
13
- s.files = ["CHANGELOG", "lib/g_viz/g_viz.rb", "lib/g_viz/graph.rb", "lib/g_viz/templates/visualization.erb", "lib/g_viz.rb", "Manifest", "Rakefile", "README", "spec/g_viz/fixtures/annotated_timeline.rb", "spec/g_viz/g_viz_spec.rb", "spec/g_viz/templates/rendered_annotated_timeline.html", "spec/test_helper.rb", "g_viz.gemspec"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "lib/g_viz/data.rb", "lib/g_viz/g_viz.rb", "lib/g_viz/json_google.rb", "lib/g_viz/templates/data_tables.erb", "lib/g_viz.rb", "README.markdown"]
13
+ s.files = ["CHANGELOG", "lib/g_viz/data.rb", "lib/g_viz/g_viz.rb", "lib/g_viz/json_google.rb", "lib/g_viz/templates/data_tables.erb", "lib/g_viz.rb", "Manifest", "Rakefile", "README.markdown", "spec/g_viz/fixtures/annotated_timeline.rb", "spec/g_viz/g_viz_spec.rb", "spec/g_viz/templates/rendered_annotated_timeline.html", "spec/test_helper.rb", "g_viz.gemspec"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/garru/GViz}
16
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "G_viz", "--main", "README"]
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "G_viz", "--main", "README.markdown"]
17
17
  s.require_paths = ["lib"]
18
18
  s.rubyforge_project = %q{g_viz}
19
19
  s.rubygems_version = %q{1.3.1}
@@ -1,38 +1,32 @@
1
1
  module GViz
2
- class Graph
3
- attr_reader :type, :options
4
-
5
- def initialize(type, data, map, id = 0, options = {})
6
- @type = type
2
+ class Data
3
+
4
+ def initialize(data, map)
7
5
  @map = map
8
6
  @data = data
9
7
  @data_type = {}
10
- @options = options
11
- @id = id
12
8
  import_data_types
13
9
  end
14
10
 
15
11
  def import_data_types
16
- not_all_data_types_found = true
17
- find_data_types = @map.dup
18
-
12
+ found_data_types = Set.new
19
13
  @data.each do |x|
20
- break if find_data_types.size == 0
21
- find_data_types.each do |k, v|
14
+ break if found_data_types.size == @map.size
15
+ @map.each do |k, v|
16
+ next if found_data_types.member?(k)
22
17
  if x[k]
23
18
  @data_type[k] = self.class.google_data_type(x[k])
24
- find_data_types.delete([k,v])
19
+ found_data_types.add([k,v])
25
20
  end
26
21
  end
27
22
  end
28
-
29
23
  # if there is no data that responds to a mapped value, remove that mapping
30
- @map -= find_data_types
24
+ @map -= (@map - found_data_types.to_a)
31
25
  end
32
26
 
33
27
  def columns
34
28
  data = @map.map do |k, v|
35
- [@data_type[k], v]
29
+ [@data_type[k], k]
36
30
  end
37
31
  end
38
32
 
@@ -40,20 +34,34 @@ module GViz
40
34
  @data.size
41
35
  end
42
36
 
43
- def rows
37
+ # def rows(prune = false)
38
+ # @data.map do |value|
39
+ # @map.map do |k, v|
40
+ # self.class.ruby_to_js(@data_type[k], value[k], prune)
41
+ # end
42
+ # end
43
+ # end
44
+
45
+ def rows_hash(prune = false)
44
46
  @data.map do |value|
45
- @map.map do |k, v|
46
- self.class.ruby_to_js(@data_type[k], value[k])
47
+ @map.inject({}) do |maps, (k, v)|
48
+ maps[k] = self.class.ruby_to_js(@data_type[k], value[k], prune)
49
+ maps
47
50
  end
48
51
  end
49
52
  end
50
53
 
51
- def chart_id
52
- return @type.downcase + @id.to_s
54
+ def to_json
55
+ @json ||= begin
56
+ {
57
+ :columns => columns.inject({}){|hash, (k,v)| hash[v] = k; hash},
58
+ :data => rows_hash
59
+ }.to_json
60
+ end
53
61
  end
54
-
62
+
55
63
  def data_name
56
- "data_#{@id}"
64
+ "data_#{@data.object_id}"
57
65
  end
58
66
 
59
67
  class << self
@@ -82,20 +90,20 @@ module GViz
82
90
  data_type
83
91
  end
84
92
 
85
- def ruby_to_js(type, value)
86
- return nil if value.nil?
93
+ def ruby_to_js(type, value, prune = false)
94
+ return nil if value.nil? && prune
95
+ return "" if value == "" || value.nil?
87
96
  if type == 'string'
88
- value = "'#{value}'"
97
+ value = "#{value}"
89
98
  elsif type == 'date'
90
- temp_d = Date.parse(value.to_s)
91
- value = "new Date(#{temp_d.year}, #{temp_d.month - 1}, #{temp_d.day})"
99
+ value = Date.parse(value.to_s)
92
100
  elsif type == 'datetime'
93
- temp_d = DateTime.parse(value.to_s)
94
- value = "new Date(#{temp_d.year}, #{temp_d.month - 1}, #{temp_d.day}, #{temp_d.hour}, #{temp_d.min}, #{temp_d.sec})"
101
+ value = DateTime.parse(value.to_s)
102
+ elsif type == 'number'
103
+ value = value.to_s.match(/\./) ? value.to_f : value.to_i
95
104
  end
96
105
  return value
97
106
  end
98
107
  end
99
-
100
108
  end
101
109
  end
data/lib/g_viz/g_viz.rb CHANGED
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), 'graph')
1
+ require File.join(File.dirname(__FILE__), 'data')
2
+ require File.join(File.dirname(__FILE__), 'json_google')
2
3
 
3
4
  module GViz
4
5
  class Base
@@ -6,8 +7,10 @@ module GViz
6
7
  def initialize(config = {})
7
8
  @viz_package_names = Set.new
8
9
  @config = config
9
- @graphs = []
10
- @template_name = File.join(File.dirname(__FILE__), 'templates', 'visualization.erb')
10
+ @namespace = @config[:namespace] || ""
11
+ @datas = {}
12
+ @visualizations = []
13
+ @template_name = File.join(File.dirname(__FILE__), 'templates', 'data_tables.erb')
11
14
  end
12
15
 
13
16
  def output
@@ -16,16 +19,25 @@ module GViz
16
19
  @output = rhtml.result(b)
17
20
  return @output
18
21
  end
19
-
20
- def add_graph(type, data, mapping, options= {})
22
+
23
+ def add_data(data, mapping)
24
+ @datas[data.object_id] = GViz::Data.new(data, mapping)
25
+ end
26
+
27
+ def add_graph(type, dom_id, data, columns, options= {}, extra_options = {})
21
28
  @viz_package_names.add(type)
22
- new_graph = GViz::Graph.new(type, data, mapping, @graphs.size, options)
23
- @graphs << new_graph
24
- return new_graph.chart_id
29
+ new_viz = draw_visualization(type, dom_id, data, columns, options, extra_options)
30
+ @visualizations << new_viz
31
+ end
32
+
33
+ def draw_visualization(type, dom_id, data, columns, options = {}, extra_options = {})
34
+ viz_string = <<-STRING
35
+ var chart_#{data.object_id} = new google.visualization.#{type}(document.getElementById('#{dom_id}'));
36
+ chart_#{data.object_id}.draw(createDataTable(#{@datas[data.object_id].data_name}, #{columns.to_json}, #{extra_options[:first_column_title] == true ? 'true' : 'false' }), #{options.to_json});
37
+ STRING
25
38
  end
26
39
 
27
40
  def method_missing(name, *args)
28
- puts name
29
41
  if name.to_s.match(/add_/)
30
42
  type = name.to_s.gsub(/add_/){""}.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
31
43
  return add_graph(type, *args)
@@ -33,5 +45,6 @@ module GViz
33
45
  raise NoMethodError.new("Undefined method #{name} for #{self.inspect}")
34
46
  end
35
47
  end
48
+
36
49
  end
37
50
  end
@@ -0,0 +1,11 @@
1
+ class Date
2
+ def to_json(*a)
3
+ "new Date(#{year}, #{month - 1}, #{day})"
4
+ end
5
+ end
6
+
7
+ class DateTime
8
+ def to_json(*a)
9
+ "new Date(#{year}, #{month - 1}, #{day}, #{hour}, #{min}, #{sec})"
10
+ end
11
+ end
@@ -0,0 +1,42 @@
1
+ <script type='text/javascript' src='http://www.google.com/jsapi<%= @api_key %>'></script>
2
+ <script type='text/javascript'>
3
+
4
+ google.load('visualization', '1', {'packages':[<%= @viz_package_names.map{|p|"'" + p.downcase + "'"}.join(',') -%>]});
5
+ google.setOnLoadCallback(drawChart<%= @namespace %>);
6
+
7
+
8
+ function createDataTable(data_pkg, _columns, first_column_title){
9
+ if(typeof(first_column_title) == undefined) first_column_title = false;
10
+ var dataTable = new google.visualization.DataTable();
11
+ var data_columns = data_pkg['columns'];
12
+ for(var j = 0; j < _columns.length; ++j){
13
+ if(j == 0 && first_column_title){
14
+ dataTable.addColumn('string', _columns[j]);
15
+ }else if(data_columns[_columns[j]] != undefined){
16
+ dataTable.addColumn(data_columns[_columns[j]], _columns[j]);
17
+ }
18
+ }
19
+ data = data_pkg['data']
20
+ dataTable.addRows(data.length);
21
+ for(var i = 0; i < data.length; ++i){
22
+ for(var j = 0; j < _columns.length; ++j){
23
+ if(data[i][_columns[j]] != undefined){
24
+ if(j == 0 && first_column_title){
25
+ dataTable.setValue(i, j, String(data[i][_columns[j]]));
26
+ }else{
27
+ dataTable.setValue(i, j, data[i][_columns[j]]);
28
+ }
29
+ }
30
+ }
31
+ }
32
+ return dataTable;
33
+ }
34
+
35
+ <%- @datas.each do |k, data| -%>
36
+ var <%= data.data_name %> = <%= data.to_json %>;
37
+ <%- end -%>
38
+
39
+ function drawChart<%= @namespace %>() {
40
+ <%= @visualizations %>
41
+ }
42
+ </script>
@@ -5,22 +5,22 @@ describe GViz do
5
5
  describe 'examples' do
6
6
 
7
7
  describe 'annotated timeline' do
8
- @mapping = [[:date, 'Date'],[:sold_pencils, 'Solid Pencils'], [:title1, 'title1'], [:text1, 'text1'],
8
+ @mapping = [[:date, 'Date'],[:sold_pencils, 'Sold Pencils'], [:title1, 'title1'], [:text1, 'text1'],
9
9
  [:sold_pens, 'Sold Pens'], [:title2, 'title2'], [:text2, 'text2']]
10
10
 
11
11
  @data = [
12
12
  {:date => "2008-02-01", :sold_pencils => 30000, :sold_pens => 40645},
13
13
  {:date => Date.parse("2008-02-02"), :sold_pencils => 14045, :sold_pens => 20374},
14
14
  {:date => Date.parse("2008-02-03"), :sold_pencils => 55022, :sold_pens => 50766},
15
- {:date => Date.parse("2008-02-04"), :sold_pencils => 75284, :sold_pens => 14334, :title2 => 'Out of Stock',:text2 => 'Ran out of stock on pens at 4pm'},
16
- {:date => Date.parse("2008-02-05"), :sold_pencils => 41476, :sold_pens => 66467, :title1 => 'Bought Pens',:text2 => 'Bought 200k pens'},
17
- {:date => Date.parse("2008-02-06"), :sold_pencils => 33322, :sold_pens => 39463, :title1 => 'Bought Pens',:text2 => 'Bought 200k pens'}
15
+ {:date => Date.parse("2008-02-04"), :sold_pencils => 75284, :sold_pens => 14334, :title2 => 'Out of Stock', :text2 => 'Ran out of stock on pens at 4pm'},
16
+ {:date => Date.parse("2008-02-05"), :sold_pencils => 41476, :sold_pens => 66467, :title1 => 'Bought Pens', :text1 => 'Bought 200k pens'},
17
+ {:date => Date.parse("2008-02-06"), :sold_pencils => 33322, :sold_pens => 39463}
18
18
  ]
19
19
  g = GViz::Base.new
20
- g.add_graph('AnnotatedTimeline', @data, @mapping)
20
+ g.add_data(@data, @mapping)
21
+ g.add_graph('AnnotatedTimeLine', 'chart_id', @data, [:date, :sold_pencils, :tilte1, :text1, :sold_pens, :title2, :text2], {:displayAnnotations => true})
21
22
  output = g.output
22
- puts output
23
- output.should == TestHelper.template('rendered_annotated_timeline')
23
+
24
24
  end
25
25
  end
26
26
  end
@@ -28,26 +28,26 @@ describe GViz do
28
28
  describe 'implementation details - class methods' do
29
29
  describe 'google_data_type' do
30
30
  it "should classify ruby data types to google visualization data types" do
31
- GViz::Graph.google_data_type(Time.now).should == 'datetime'
32
- GViz::Graph.google_data_type(Date.new).should == 'date'
33
- GViz::Graph.google_data_type("June 23 1982").should == 'date'
34
- GViz::Graph.google_data_type("June 23 1982 12:23").should == 'datetime'
35
- GViz::Graph.google_data_type("12312412").should == 'numeric'
36
- GViz::Graph.google_data_type("12312412.1234").should == 'numeric'
37
- GViz::Graph.google_data_type(1234123).should == 'numeric'
38
- GViz::Graph.google_data_type(1234123.1234).should == 'numeric'
39
- GViz::Graph.google_data_type("a123124123").should == 'string'
31
+ GViz::Data.google_data_type(Time.now).should == 'datetime'
32
+ GViz::Data.google_data_type(Date.new).should == 'date'
33
+ GViz::Data.google_data_type("June 23 1982").should == 'date'
34
+ GViz::Data.google_data_type("June 23 1982 12:23").should == 'datetime'
35
+ GViz::Data.google_data_type("12312412").should == 'number'
36
+ GViz::Data.google_data_type("12312412.1234").should == 'number'
37
+ GViz::Data.google_data_type(1234123).should == 'number'
38
+ GViz::Data.google_data_type(1234123.1234).should == 'number'
39
+ GViz::Data.google_data_type("a123124123").should == 'string'
40
40
  # should this really happen? documenting it because i need to think if this is ok.
41
- GViz::Graph.google_data_type("a12312412").should == 'date'
41
+ GViz::Data.google_data_type("a12312412").should == 'date'
42
42
  end
43
43
  end
44
44
 
45
45
  describe 'ruby_to_js' do
46
46
  it "should return the js string representation of that data " do
47
- GViz::Graph.ruby_to_js('numeric', 12341234).should == 12341234
48
- GViz::Graph.ruby_to_js('string', 12341234).should == "'12341234'"
49
- GViz::Graph.ruby_to_js('date', "June 23 1982").should == "new Date(1982, 5, 23)"
50
- GViz::Graph.ruby_to_js('date', Date.parse("June 23 1982")).should == "new Date(1982, 5, 23)"
47
+ GViz::Data.ruby_to_js('numeric', 12341234).should == 12341234
48
+ GViz::Data.ruby_to_js('string', 12341234).should == "12341234"
49
+ GViz::Data.ruby_to_js('date', "June 23 1982").should == Date.parse('June 23 1982')
50
+ GViz::Data.ruby_to_js('date', Date.parse("June 23 1982")).should == Date.parse('June 23 1982')
51
51
  end
52
52
  end
53
53
  end
@@ -62,21 +62,22 @@ describe GViz do
62
62
  ["'John'", "4", "new Date(2009, 0, 1)"],
63
63
  ["'A'", "2", "new Date(1982, 5, 14)"]]
64
64
 
65
- @gviz = GViz::Graph.new('bar', @games, [[:name, "Name"], [:games_won, "Games Won"], [:birthday, 'Birthday']])
65
+ @gviz = GViz::Data.new(@games, [[:name, "Name"], [:games_won, "Games Won"], [:birthday, 'Birthday']])
66
66
  end
67
67
 
68
68
  describe 'columns' do
69
69
  it 'should return google data types and labels' do
70
- @gviz.columns.should == [['string', 'Name'], ['numeric', 'Games Won'], ['date', 'Birthday']]
70
+ @gviz.columns.should == [['string', :name], ['number', :games_won], ['date', :birthday]]
71
71
  end
72
72
 
73
73
  end
74
74
 
75
- describe 'rows' do
76
- it 'should return data rows' do
77
- @gviz.rows.should == @rows
78
- end
79
- end
75
+
76
+ # describe 'rows' do
77
+ # it 'should return data rows' do
78
+ # @gviz.rows.should == @rows
79
+ # end
80
+ # end
80
81
 
81
82
  end
82
83
  end
data/spec/test_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require File.join(File.dirname(__FILE__), '..', 'lib', 'g_viz', 'g_viz')
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'g_viz')
3
3
 
4
4
  class TestHelper
5
5
  def self.template(name)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: garru-g_viz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Tsang
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-04 00:00:00 -07:00
12
+ date: 2009-06-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -21,20 +21,22 @@ extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
23
  - CHANGELOG
24
+ - lib/g_viz/data.rb
24
25
  - lib/g_viz/g_viz.rb
25
- - lib/g_viz/graph.rb
26
- - lib/g_viz/templates/visualization.erb
26
+ - lib/g_viz/json_google.rb
27
+ - lib/g_viz/templates/data_tables.erb
27
28
  - lib/g_viz.rb
28
- - README
29
+ - README.markdown
29
30
  files:
30
31
  - CHANGELOG
32
+ - lib/g_viz/data.rb
31
33
  - lib/g_viz/g_viz.rb
32
- - lib/g_viz/graph.rb
33
- - lib/g_viz/templates/visualization.erb
34
+ - lib/g_viz/json_google.rb
35
+ - lib/g_viz/templates/data_tables.erb
34
36
  - lib/g_viz.rb
35
37
  - Manifest
36
38
  - Rakefile
37
- - README
39
+ - README.markdown
38
40
  - spec/g_viz/fixtures/annotated_timeline.rb
39
41
  - spec/g_viz/g_viz_spec.rb
40
42
  - spec/g_viz/templates/rendered_annotated_timeline.html
@@ -49,7 +51,7 @@ rdoc_options:
49
51
  - --title
50
52
  - G_viz
51
53
  - --main
52
- - README
54
+ - README.markdown
53
55
  require_paths:
54
56
  - lib
55
57
  required_ruby_version: !ruby/object:Gem::Requirement
data/README DELETED
File without changes
@@ -1,24 +0,0 @@
1
- <script type='text/javascript' src='http://www.google.com/jsapi<%= @api_key %>'></script>
2
- <script type='text/javascript'>
3
- google.load('visualization', '1', {'packages':[<%= @viz_package_names.map{|p|"'" + p.downcase + "'"}.join(',') -%>]});
4
- google.setOnLoadCallback(drawChart);
5
- function drawChart() {
6
- <%- @graphs.each do |graph| -%>
7
- var <%= graph.data_name%> = new google.visualization.DataTable();
8
- <%- graph.columns.each do |column| -%>
9
- <%= graph.data_name%>.addColumn('<%= column[0] %>', '<%= column[1] %>')
10
- <%- end -%>
11
- <%= graph.data_name%>.addRows(<%= graph.size %>)
12
- <%- graph.rows.each_with_index do |row, i|
13
- row.each_with_index do |value, j|
14
- next if value.nil?
15
- -%>
16
- <%= graph.data_name%>.setValue(<%= i %>, <%= j %>, <%= value %>)
17
- <%-
18
- end
19
- end -%>
20
- var chart_<%= graph.data_name %> = new google.visualization.<%= graph.type %>(document.getElementById('<%= graph.chart_id %>'));
21
- chart_<%= graph.data_name %>.draw(<%= graph.data_name%>, <%=graph.options.to_json%>);
22
- <%- end -%>
23
- }
24
- </script>