google_visualr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,53 @@
1
+ module GoogleVisualr
2
+
3
+ # http://code.google.com/apis/visualization/documentation/gallery/columnchart.html
4
+ class ColumnChart < BaseChart
5
+
6
+ attr_accessor :element_id
7
+
8
+ # http://code.google.com/apis/visualization/documentation/gallery/columnchart.html#Configuration_Options
9
+ attr_accessor :axisColor
10
+ attr_accessor :axisBackgroundColor
11
+ attr_accessor :axisFontSize
12
+ attr_accessor :backgroundColor
13
+ attr_accessor :borderColor
14
+ attr_accessor :colors
15
+ attr_accessor :enableTooltip
16
+ attr_accessor :focusBorderColor
17
+ attr_accessor :height
18
+ attr_accessor :is3D
19
+ attr_accessor :isStacked
20
+ attr_accessor :legend
21
+ attr_accessor :legendBackgroundColor
22
+ attr_accessor :legendFontSize
23
+ attr_accessor :legendTextColor
24
+ attr_accessor :logScale
25
+ attr_accessor :max
26
+ attr_accessor :min
27
+ attr_accessor :reverseAxis
28
+ attr_accessor :showCategories
29
+ attr_accessor :title
30
+ attr_accessor :titleX
31
+ attr_accessor :titleY
32
+ attr_accessor :titleColor
33
+ attr_accessor :titleFontSize
34
+ attr_accessor :tooltipFontSize
35
+ attr_accessor :tooltipHeight
36
+ attr_accessor :tooltipWidth
37
+ attr_accessor :width
38
+
39
+ def render (element_id)
40
+
41
+ options = Hash.new
42
+
43
+ options[:package] = self.class.to_s.split('::').last
44
+ options[:element_id] = element_id
45
+ options[:chart_style] = collect_parameters
46
+
47
+ super(options)
48
+
49
+ end
50
+
51
+ end
52
+
53
+ end
data/lib/formatters.rb ADDED
@@ -0,0 +1,184 @@
1
+ module GoogleVisualr
2
+
3
+ # http://code.google.com/apis/visualization/documentation/reference.html#formatters
4
+ class Formatter
5
+
6
+ attr_accessor :columns
7
+
8
+ def initialize(options={})
9
+
10
+ options.each_pair do | key, value |
11
+ self.send "#{key}=", value
12
+ end
13
+
14
+ end
15
+
16
+ def columns(*columns)
17
+ @columns = columns.flatten
18
+ end
19
+
20
+ def script(options)
21
+
22
+ script = "var formatter = new google.visualization.#{options[:formatter]}("
23
+ script << options[:formatter_options]
24
+ script << ");"
25
+
26
+ @columns.each do |column|
27
+ script << "formatter.format(chart_data, #{column});"
28
+ end
29
+
30
+ return script
31
+
32
+ end
33
+
34
+ def collect_parameters
35
+
36
+ attributes = Array.new
37
+ instance_variable_names.each do |instance_variable|
38
+ next if instance_variable == "@columns"
39
+ key = instance_variable.gsub("@", "")
40
+ value = instance_variable_get(instance_variable)
41
+ attribute = key + ":" + (value.is_a?(String) ? "'" + value + "'" : value.to_s)
42
+ attributes << attribute
43
+ end
44
+
45
+ return "{" + attributes.join(",") + "}"
46
+
47
+ end
48
+
49
+ end
50
+
51
+ class ArrowFormat < Formatter
52
+
53
+ attr_accessor :base
54
+
55
+ def script
56
+
57
+ options = Hash.new
58
+ options[:formatter] = self.class.to_s.split('::').last
59
+ options[:formatter_options] = collect_parameters
60
+
61
+ super(options)
62
+
63
+ end
64
+
65
+ end
66
+
67
+ class BarFormat < Formatter
68
+
69
+ attr_accessor :base
70
+ attr_accessor :colorNegative
71
+ attr_accessor :colorPositive
72
+ attr_accessor :drawZeroLine
73
+ attr_accessor :max
74
+ attr_accessor :min
75
+ attr_accessor :showValue
76
+ attr_accessor :width
77
+
78
+ def script
79
+
80
+ options = Hash.new
81
+ options[:formatter] = self.class.to_s.split('::').last
82
+ options[:formatter_options] = collect_parameters
83
+
84
+ super(options)
85
+
86
+ end
87
+
88
+ end
89
+
90
+ class ColorFormat < Formatter
91
+
92
+ attr_accessor :ranges
93
+ attr_accessor :gradient_ranges
94
+
95
+ def initialize
96
+ @ranges = Array.new
97
+ @gradient_ranges = Array.new
98
+ end
99
+
100
+ def add_range(from, to, color, bgcolor)
101
+
102
+ options = { :from => from, :to => to, :color => color, :bgcolor => bgcolor }
103
+ [:from, :to].each do |attr|
104
+ options[attr] ||= 'null'
105
+ end
106
+
107
+ @ranges << options
108
+
109
+ end
110
+
111
+ def add_gradient_range(from, to, color, fromBgColor, toBgColor)
112
+
113
+ options = { :from => from, :to => to, :color => color, :fromBgColor => fromBgColor, :toBgColor => toBgColor }
114
+ [:from, :to].each do |attr|
115
+ options[attr] ||= 'null'
116
+ end
117
+
118
+ @gradient_ranges << options
119
+
120
+ end
121
+
122
+ def script
123
+
124
+ script = "var formatter = new google.visualization.ColorFormat();"
125
+
126
+ @ranges.each do |r|
127
+ script << "formatter.addRange( #{r[:from]}, #{r[:to]}, '#{r[:color]}', '#{r[:bgcolor]}' );"
128
+ end
129
+
130
+ @gradient_ranges.each do |r|
131
+ script << "formatter.addGradientRange( #{r[:from]}, #{r[:to]}, '#{r[:color]}', '#{r[:fromBgColor]}', '#{r[:toBgColor]}' );"
132
+ end
133
+
134
+ @columns.each do |column|
135
+ script << "formatter.format(chart_data, #{column});"
136
+ end
137
+
138
+ return script
139
+
140
+ end
141
+
142
+ end
143
+
144
+ class DateFormat < Formatter
145
+
146
+ attr_accessor :formatType
147
+ attr_accessor :pattern
148
+ attr_accessor :timeZone
149
+
150
+ def script
151
+
152
+ options = Hash.new
153
+ options[:formatter] = self.class.to_s.split('::').last
154
+ options[:formatter_options] = collect_parameters
155
+
156
+ super(options)
157
+
158
+ end
159
+
160
+ end
161
+
162
+ class NumberFormat < Formatter
163
+
164
+ attr_accessor :decimalSymbol
165
+ attr_accessor :fractionDigits
166
+ attr_accessor :groupingSymbol
167
+ attr_accessor :negativeColor
168
+ attr_accessor :negativeParens
169
+ attr_accessor :prefix
170
+ attr_accessor :suffix
171
+
172
+ def script
173
+
174
+ options = Hash.new
175
+ options[:formatter] = self.class.to_s.split('::').last
176
+ options[:formatter_options] = collect_parameters
177
+
178
+ super(options)
179
+
180
+ end
181
+
182
+ end
183
+
184
+ end
data/lib/gauge.rb ADDED
@@ -0,0 +1,36 @@
1
+ module GoogleVisualr
2
+
3
+ # http://code.google.com/apis/visualization/documentation/gallery/gauge.html
4
+ class Gauge < BaseChart
5
+
6
+ attr_accessor :element_id
7
+
8
+ # http://code.google.com/apis/visualization/documentation/gallery/gauge.html#Configuration_Options
9
+ attr_accessor :greenFrom
10
+ attr_accessor :greenTo
11
+ attr_accessor :height
12
+ attr_accessor :majorTicks
13
+ attr_accessor :max
14
+ attr_accessor :min
15
+ attr_accessor :minorTicks
16
+ attr_accessor :redFrom
17
+ attr_accessor :redTo
18
+ attr_accessor :width
19
+ attr_accessor :yellowFrom
20
+ attr_accessor :yellowTo
21
+
22
+ def render (element_id)
23
+
24
+ options = Hash.new
25
+
26
+ options[:package] = self.class.to_s.split('::').last
27
+ options[:element_id] = element_id
28
+ options[:chart_style] = collect_parameters
29
+
30
+ super(options)
31
+
32
+ end
33
+
34
+ end
35
+
36
+ end
data/lib/geo_map.rb ADDED
@@ -0,0 +1,32 @@
1
+ module GoogleVisualr
2
+
3
+ # http://code.google.com/apis/visualization/documentation/gallery/geomap.html
4
+ class GeoMap < BaseChart
5
+
6
+ attr_accessor :element_id
7
+
8
+ # http://code.google.com/apis/visualization/documentation/gallery/geomap.html#Configuration_Options
9
+ attr_accessor :region
10
+ attr_accessor :dataMode
11
+ attr_accessor :width
12
+ attr_accessor :height
13
+ attr_accessor :colors
14
+ attr_accessor :showLegend
15
+ attr_accessor :showZoomOut
16
+ attr_accessor :zoomOutLabel
17
+
18
+ def render (element_id)
19
+
20
+ options = Hash.new
21
+
22
+ options[:package] = self.class.to_s.split('::').last
23
+ options[:element_id] = element_id
24
+ options[:chart_style] = collect_parameters
25
+
26
+ super(options)
27
+
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,36 @@
1
+ module GoogleVisualr
2
+
3
+ # http://code.google.com/apis/visualization/documentation/gallery/imagesparkline.html
4
+ class ImageSparkLine < BaseChart
5
+
6
+ attr_accessor :element_id
7
+
8
+ # http://code.google.com/apis/visualization/documentation/gallery/imagesparkline.html#Configuration_Options
9
+ attr_accessor :color
10
+ attr_accessor :colors
11
+ attr_accessor :fill
12
+ attr_accessor :height
13
+ attr_accessor :labelPosition
14
+ attr_accessor :max
15
+ attr_accessor :min
16
+ attr_accessor :showAxisLines
17
+ attr_accessor :showValueLabels
18
+ attr_accessor :title
19
+ attr_accessor :width
20
+ attr_accessor :layout
21
+
22
+ def render (element_id)
23
+
24
+ options = Hash.new
25
+
26
+ options[:package] = self.class.to_s.split('::').last
27
+ options[:element_id] = element_id
28
+ options[:chart_style] = collect_parameters
29
+
30
+ super(options)
31
+
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,29 @@
1
+ module GoogleVisualr
2
+
3
+ # http://code.google.com/apis/visualization/documentation/gallery/intensitymap.html
4
+ class IntensityMap < BaseChart
5
+
6
+ attr_accessor :element_id
7
+
8
+ # http://code.google.com/apis/visualization/documentation/gallery/intensitymap.html#Configuration_Options
9
+ attr_accessor :colors
10
+ attr_accessor :height
11
+ attr_accessor :region
12
+ attr_accessor :showOneTab
13
+ attr_accessor :width
14
+
15
+ def render (element_id)
16
+
17
+ options = Hash.new
18
+
19
+ options[:package] = self.class.to_s.split('::').last
20
+ options[:element_id] = element_id
21
+ options[:chart_style] = collect_parameters
22
+
23
+ super(options)
24
+
25
+ end
26
+
27
+ end
28
+
29
+ end
data/lib/line_chart.rb ADDED
@@ -0,0 +1,54 @@
1
+ module GoogleVisualr
2
+
3
+ # http://code.google.com/apis/visualization/documentation/gallery/linechart.html
4
+ class LineChart < BaseChart
5
+
6
+ attr_accessor :element_id
7
+
8
+ # http://code.google.com/apis/visualization/documentation/gallery/linechart.html#Configuration_Options
9
+ attr_accessor :axisColor
10
+ attr_accessor :axisBackgroundColor
11
+ attr_accessor :axisFontSize
12
+ attr_accessor :backgroundColor
13
+ attr_accessor :borderColor
14
+ attr_accessor :colors
15
+ attr_accessor :enableTooltip
16
+ attr_accessor :focusBorderColor
17
+ attr_accessor :height
18
+ attr_accessor :legend
19
+ attr_accessor :legendBackgroundColor
20
+ attr_accessor :legendFontSize
21
+ attr_accessor :legendTextColor
22
+ attr_accessor :lineSize
23
+ attr_accessor :logScale
24
+ attr_accessor :max
25
+ attr_accessor :min
26
+ attr_accessor :pointSize
27
+ attr_accessor :reverseAxis
28
+ attr_accessor :showCategories
29
+ attr_accessor :smoothLine
30
+ attr_accessor :title
31
+ attr_accessor :titleX
32
+ attr_accessor :titleY
33
+ attr_accessor :titleColor
34
+ attr_accessor :titleFontSize
35
+ attr_accessor :tooltipFontSize
36
+ attr_accessor :tooltipHeight
37
+ attr_accessor :tooltipWidth
38
+ attr_accessor :width
39
+
40
+ def render (element_id)
41
+
42
+ options = Hash.new
43
+
44
+ options[:package] = self.class.to_s.split('::').last
45
+ options[:element_id] = element_id
46
+ options[:chart_style] = collect_parameters
47
+
48
+ super(options)
49
+
50
+ end
51
+
52
+ end
53
+
54
+ end
data/lib/map.rb ADDED
@@ -0,0 +1,31 @@
1
+ module GoogleVisualr
2
+
3
+ # http://code.google.com/apis/visualization/documentation/gallery/map.html
4
+ class Map < BaseChart
5
+
6
+ attr_accessor :element_id
7
+
8
+ # http://code.google.com/apis/visualization/documentation/gallery/map.html#Configuration_Options
9
+ attr_accessor :enableScrollWheel
10
+ attr_accessor :showTip
11
+ attr_accessor :showLine
12
+ attr_accessor :lineColor
13
+ attr_accessor :lineWidth
14
+ attr_accessor :mapType
15
+ attr_accessor :zoomLevel
16
+
17
+ def render (element_id)
18
+
19
+ options = Hash.new
20
+
21
+ options[:package] = self.class.to_s.split('::').last
22
+ options[:element_id] = element_id
23
+ options[:chart_style] = collect_parameters
24
+
25
+ super(options)
26
+
27
+ end
28
+
29
+ end
30
+
31
+ end