btucker-google_visualization 0.5.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.
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ doc/
3
+ pkg/
4
+ config/
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Miguel Fonseca
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ = Description
2
+
3
+ A Ruby interface to manipulate and populate data for {Google Interactive Charts}[http://code.google.com/apis/visualization/interactive_charts.html].
4
+
5
+ = Example
6
+
7
+ require 'erb'
8
+ require 'rubygems'
9
+ require 'google_visualization'
10
+
11
+ include Google::Visualization
12
+
13
+ data_table = DataTable.new
14
+ data_table.add_column DataColumn.new(DataType::STRING, 'Task')
15
+ data_table.add_column DataColumn.new(DataType::NUMBER, 'Hours per Day')
16
+ data_table.add_row ['Work', 11]
17
+ data_table.add_row ['Eat', 2]
18
+ data_table.add_row ['Commute', 2]
19
+ data_table.add_row ['Watch TV', 2]
20
+ data_table.add_row ['Sleep', 7]
21
+
22
+ page = <<HTML
23
+ <html>
24
+ <head>
25
+ <!--Load the AJAX API-->
26
+ <script type="text/javascript" src="http://www.google.com/jsapi"></script>
27
+ <script type="text/javascript">
28
+
29
+ // Load the Visualization API and the piechart package.
30
+ google.load('visualization', '1', {'packages':['piechart']});
31
+
32
+ // Set a callback to run when the Google Visualization API is loaded.
33
+ google.setOnLoadCallback(drawChart);
34
+
35
+ // Callback that creates and populates a data table,
36
+ // instantiates the pie chart, passes in the data and
37
+ // draws it.
38
+ function drawChart() {
39
+ // Create our data table.
40
+ var data = new google.visualization.DataTable(<%= data_table.to_json %>);
41
+
42
+ // Instantiate and draw our chart, passing in some options.
43
+ var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
44
+ chart.draw(data, {width: 400, height: 240, is3D: true, title: 'My Daily Activities'});
45
+ }
46
+ </script>
47
+ </head>
48
+
49
+ <body>
50
+ <!--Div that will hold the pie chart-->
51
+ <div id="chart_div"></div>
52
+ </body>
53
+ </html>
54
+ HTML
55
+
56
+ template = ERB.new(page)
57
+ print template.result
58
+
59
+ = Copyright
60
+
61
+ Copyright (c) 2010 Miguel Fonseca. See LICENSE for details.
@@ -0,0 +1,25 @@
1
+ require 'rake'
2
+ require 'rake/clean'
3
+
4
+ require File.dirname(__FILE__) + "/lib/google_visualization.rb"
5
+
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "btucker-google_visualization"
10
+ gem.version = Google::Visualization::VERSION
11
+ gem.summary = "A Ruby interface to manipulate and populate data for Google Interactive Charts."
12
+ gem.description = "Differs from original in that it uses the JSON gem to provide valid JSON."
13
+ gem.email = "ben@btucker.net"
14
+ gem.homepage = "http://github.com/btucker/google_visualization"
15
+ gem.authors = ["Ben Tucker", "Miguel Fonseca"]
16
+ gem.add_dependency 'json'
17
+ end
18
+ CLEAN.include("pkg")
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ Dir["tasks/*.rake"].each { |ext| load ext }
24
+
25
+ task :default => 'test:unit'
@@ -0,0 +1,86 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{btucker-google_visualization}
8
+ s.version = "0.5.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ben Tucker", "Miguel Fonseca"]
12
+ s.date = %q{2010-05-10}
13
+ s.description = %q{Differs from original in that it uses the JSON gem to provide valid JSON.}
14
+ s.email = %q{ben@btucker.net}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "btucker-google_visualization.gemspec",
25
+ "lib/google_visualization.rb",
26
+ "lib/google_visualization/data_cell.rb",
27
+ "lib/google_visualization/data_column.rb",
28
+ "lib/google_visualization/data_element.rb",
29
+ "lib/google_visualization/data_row.rb",
30
+ "lib/google_visualization/data_table.rb",
31
+ "lib/google_visualization/data_type.rb",
32
+ "lib/google_visualization/formatter.rb",
33
+ "lib/google_visualization/formatter/csv.rb",
34
+ "lib/google_visualization/formatter/json.rb",
35
+ "tasks/ftp.rake",
36
+ "tasks/rdoc.rake",
37
+ "tasks/test.rake",
38
+ "test/data/table1.json",
39
+ "test/data/table1.rb",
40
+ "test/data/table2.json",
41
+ "test/data/table2.rb",
42
+ "test/data/table3.json",
43
+ "test/data/table3.rb",
44
+ "test/data/table4.json",
45
+ "test/data/table4.rb",
46
+ "test/helper.rb",
47
+ "test/tc_data_cell.rb",
48
+ "test/tc_data_column.rb",
49
+ "test/tc_data_element.rb",
50
+ "test/tc_data_row.rb",
51
+ "test/tc_data_table.rb",
52
+ "test/tc_data_type.rb"
53
+ ]
54
+ s.homepage = %q{http://github.com/btucker/google_visualization}
55
+ s.rdoc_options = ["--charset=UTF-8"]
56
+ s.require_paths = ["lib"]
57
+ s.rubygems_version = %q{1.3.6}
58
+ s.summary = %q{A Ruby interface to manipulate and populate data for Google Interactive Charts.}
59
+ s.test_files = [
60
+ "test/data/table1.rb",
61
+ "test/data/table2.rb",
62
+ "test/data/table3.rb",
63
+ "test/data/table4.rb",
64
+ "test/helper.rb",
65
+ "test/tc_data_cell.rb",
66
+ "test/tc_data_column.rb",
67
+ "test/tc_data_element.rb",
68
+ "test/tc_data_row.rb",
69
+ "test/tc_data_table.rb",
70
+ "test/tc_data_type.rb"
71
+ ]
72
+
73
+ if s.respond_to? :specification_version then
74
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
75
+ s.specification_version = 3
76
+
77
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
78
+ s.add_runtime_dependency(%q<json>, [">= 0"])
79
+ else
80
+ s.add_dependency(%q<json>, [">= 0"])
81
+ end
82
+ else
83
+ s.add_dependency(%q<json>, [">= 0"])
84
+ end
85
+ end
86
+
@@ -0,0 +1,33 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+
3
+ require 'enumerator'
4
+ require 'google_visualization/data_type'
5
+ require 'google_visualization/data_element'
6
+ require 'google_visualization/data_cell'
7
+ require 'google_visualization/data_row'
8
+ require 'google_visualization/data_column'
9
+ require 'google_visualization/data_table'
10
+ require 'google_visualization/formatter/json'
11
+ require 'google_visualization/formatter/csv'
12
+
13
+ ##
14
+ # = Google
15
+ #
16
+ # == Description
17
+ #
18
+ # Contains the Visualization module.
19
+ #
20
+ module Google
21
+
22
+ ##
23
+ # = Visualization
24
+ #
25
+ # == Description
26
+ #
27
+ # The Google::Visualization module contains classes and modules to interact with the {Google Visualization API}[http://code.google.com/apis/visualization/interactive_charts.html].
28
+ #
29
+ module Visualization
30
+ VERSION = "0.5.3"
31
+ end
32
+
33
+ end
@@ -0,0 +1,53 @@
1
+ module Google
2
+ module Visualization
3
+
4
+ ##
5
+ # = DataCell
6
+ #
7
+ # == Description
8
+ #
9
+ # Represents a single cell value in a DataTable.
10
+ #
11
+ class DataCell < DataElement
12
+
13
+ ##
14
+ # Creates a new cell.
15
+ #
16
+ def initialize(value=nil, formatted_value=nil)
17
+ super()
18
+ self.value = value
19
+ self.formatted_value = formatted_value
20
+ end
21
+
22
+ ##
23
+ # Returns the value.
24
+ #
25
+ def value
26
+ @value
27
+ end
28
+
29
+ ##
30
+ # Sets a value.
31
+ #
32
+ def value=(obj)
33
+ @value = obj
34
+ end
35
+
36
+ ##
37
+ # Returns the formatted value.
38
+ #
39
+ def formatted_value
40
+ @formatted_value
41
+ end
42
+
43
+ ##
44
+ # Sets a formatted value.
45
+ #
46
+ def formatted_value=(obj)
47
+ @formatted_value = obj
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,100 @@
1
+ module Google
2
+ module Visualization
3
+
4
+ ##
5
+ # = DataColumn
6
+ #
7
+ # == Description
8
+ #
9
+ # Represents the schema of a column in a DataTable.
10
+ #
11
+ class DataColumn < DataElement
12
+
13
+ ##
14
+ # Creates a new column.
15
+ #
16
+ def initialize(type=nil, label=nil, id=nil)
17
+ super()
18
+ @closed = false
19
+ self.id = id
20
+ self.type = type || DataType::STRING
21
+ self.label = label
22
+ self.pattern = ""
23
+ end
24
+
25
+ ##
26
+ # Returns the id.
27
+ #
28
+ def id
29
+ @id
30
+ end
31
+
32
+ ##
33
+ # Sets a id.
34
+ #
35
+ def id=(obj)
36
+ @id = obj
37
+ end
38
+
39
+ ##
40
+ # Returns the type.
41
+ #
42
+ def type
43
+ @type
44
+ end
45
+
46
+ ##
47
+ # Sets a type.
48
+ #
49
+ def type=(obj)
50
+ raise(StandardError, "can't modify closed column") if @closed
51
+ raise(TypeError, "wrong argument type #{obj.class}, should be DataType") unless obj.is_a?(DataType)
52
+ @type = obj
53
+ end
54
+
55
+ ##
56
+ # Returns the label.
57
+ #
58
+ def label
59
+ @label
60
+ end
61
+
62
+ ##
63
+ # Sets a type.
64
+ #
65
+ def label=(obj)
66
+ @label = obj
67
+ end
68
+
69
+ ##
70
+ # Returns the pattern.
71
+ #
72
+ def pattern
73
+ @pattern
74
+ end
75
+
76
+ ##
77
+ # Sets a pattern.
78
+ #
79
+ def pattern=(obj)
80
+ @pattern = obj
81
+ end
82
+
83
+ ##
84
+ # Prevents the type from being altered.
85
+ #
86
+ def close
87
+ @closed = true
88
+ end
89
+
90
+ ##
91
+ # Returns true if closed.
92
+ #
93
+ def closed?
94
+ @closed
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,59 @@
1
+ module Google
2
+ module Visualization
3
+
4
+ ##
5
+ # = DataElement
6
+ #
7
+ # == Description
8
+ #
9
+ # Represents a element that holds a set of custom properties (name/value pairs).
10
+ #
11
+ class DataElement
12
+
13
+ ##
14
+ # Creates a new data element.
15
+ #
16
+ def initialize
17
+ @custom_properties = {}
18
+ end
19
+
20
+ ##
21
+ # Returns the number of custom properties.
22
+ #
23
+ def custom_properties_count
24
+ @custom_properties.size
25
+ end
26
+
27
+ ##
28
+ # Returns the value of a named property, or nil if no such property is
29
+ # set.
30
+ #
31
+ def custom_property(name)
32
+ @custom_properties[name]
33
+ end
34
+
35
+ ##
36
+ # Returns a enumerable of all properties.
37
+ #
38
+ def custom_properties
39
+ @custom_properties.to_enum
40
+ end
41
+
42
+ ##
43
+ # Sets a single property.
44
+ #
45
+ def store_custom_property(name, value)
46
+ @custom_properties[name] = value
47
+ end
48
+
49
+ ##
50
+ # Sets multiple properties.
51
+ #
52
+ def store_custom_properties(hash)
53
+ @custom_properties.merge!(hash)
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+ end