rgviz-rails 0.74 → 0.75
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +6 -2
- data/lib/rgviz_rails/view_helper.rb +69 -46
- metadata +51 -58
data/README.markdown
CHANGED
@@ -44,7 +44,7 @@ To make a method in your controller be a visualization api endpoint:
|
|
44
44
|
|
45
45
|
So for example if <ttPperson</tt> has <tt>name</tt> and <tt>age</tt>, pointing your browser to:
|
46
46
|
|
47
|
-
http://localhost:3000/viz/person?select name where age > 20 limit 5
|
47
|
+
http://localhost:3000/viz/person?tq=select name where age > 20 limit 5
|
48
48
|
|
49
49
|
would render the necessary javascript code that implements the google visualization api wire protocol.
|
50
50
|
|
@@ -89,6 +89,10 @@ or also:
|
|
89
89
|
|
90
90
|
render :rgviz => Person, :conditions => 'age > 20'
|
91
91
|
|
92
|
+
or (Rails 3 only):
|
93
|
+
|
94
|
+
render :rgviz => Person.where('age > ?', 20)
|
95
|
+
|
92
96
|
Preprocessing
|
93
97
|
-------------
|
94
98
|
|
@@ -132,7 +136,7 @@ For example, in your controller you put:
|
|
132
136
|
|
133
137
|
render :rgviz => Person, :virtual_columns => {
|
134
138
|
'age_range' => {
|
135
|
-
:sql => "case when age < 20 then 'young' else 'old' end",
|
139
|
+
:sql => "case when age < 20 then 'young' else 'old' end",
|
136
140
|
:type => :string
|
137
141
|
}
|
138
142
|
}
|
@@ -1,16 +1,6 @@
|
|
1
1
|
module Rgviz
|
2
2
|
module ViewHelper
|
3
3
|
def rgviz(options = {})
|
4
|
-
def get_package(name)
|
5
|
-
down = name.downcase
|
6
|
-
case down
|
7
|
-
when 'areachart', 'barchart', 'bubblechart', 'candlestickchart',
|
8
|
-
'columnchart', 'combochart', 'linechart', 'piechart',
|
9
|
-
'scatterchart', 'steppedareachart' then 'corechart'
|
10
|
-
else down
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
4
|
options = options.with_indifferent_access
|
15
5
|
|
16
6
|
id = options[:id]
|
@@ -47,40 +37,12 @@ module Rgviz
|
|
47
37
|
opts[:height] = 480 unless opts[:height]
|
48
38
|
|
49
39
|
params = []
|
50
|
-
uses_rgviz_get_value = false
|
51
|
-
uses_rgviz_append = false
|
40
|
+
uses_rgviz_get_value = [false]
|
41
|
+
uses_rgviz_append = [false]
|
52
42
|
|
53
43
|
visitor = MagicNamesVisitor.new(html_prefix, js_prefix, param_prefix)
|
54
44
|
|
55
|
-
|
56
|
-
next unless value.kind_of?(String)
|
57
|
-
|
58
|
-
source = visitor.get_source(value, false)
|
59
|
-
next unless source[:source]
|
60
|
-
|
61
|
-
case source[:source]
|
62
|
-
when :html
|
63
|
-
s = "rgviz_get_value('#{source[:id]}')"
|
64
|
-
def s.encode_json(options = {})
|
65
|
-
self
|
66
|
-
end
|
67
|
-
opts[key] = s
|
68
|
-
uses_rgviz_get_value = true
|
69
|
-
when :js
|
70
|
-
s = "#{source[:id]}()"
|
71
|
-
def s.encode_json(options = {})
|
72
|
-
self
|
73
|
-
end
|
74
|
-
opts[key] = s
|
75
|
-
when :param
|
76
|
-
s = "param_#{source[:id]}"
|
77
|
-
def s.encode_json(options = {})
|
78
|
-
self
|
79
|
-
end
|
80
|
-
opts[key] = s
|
81
|
-
params << source[:id].to_i unless params.include?(source[:id])
|
82
|
-
end
|
83
|
-
end
|
45
|
+
Rgviz::ViewHelper.process_options opts, params, visitor, uses_rgviz_get_value, uses_rgviz_append
|
84
46
|
|
85
47
|
opts = opts.to_json
|
86
48
|
|
@@ -99,8 +61,8 @@ module Rgviz
|
|
99
61
|
query_builder = visitor.query_builder
|
100
62
|
query_builder_var = visitor.query_builder_var
|
101
63
|
|
102
|
-
uses_rgviz_get_value |= visitor.uses_rgviz_get_value?
|
103
|
-
uses_rgviz_append |= visitor.uses_rgviz_append?
|
64
|
+
uses_rgviz_get_value[0] |= visitor.uses_rgviz_get_value?
|
65
|
+
uses_rgviz_append[0] |= visitor.uses_rgviz_append?
|
104
66
|
|
105
67
|
visitor.params.each{|p| params << p unless params.include?(p)}
|
106
68
|
params = params.sort!.map{|i| "param_#{i}"}
|
@@ -127,7 +89,7 @@ module Rgviz
|
|
127
89
|
out << "<script type=\"text/javascript\">\n"
|
128
90
|
|
129
91
|
# Define a function to get the value of an html element
|
130
|
-
if uses_rgviz_get_value && !@defined_rgviz_get_value
|
92
|
+
if uses_rgviz_get_value[0] && !@defined_rgviz_get_value
|
131
93
|
out << "function rgviz_get_value(id) {\n"
|
132
94
|
out << "var e = document.getElementById(id);\n"
|
133
95
|
out << "var n = e.tagName.toLowerCase();\n"
|
@@ -148,7 +110,7 @@ module Rgviz
|
|
148
110
|
end
|
149
111
|
|
150
112
|
# Define a function to append the value of a magic something
|
151
|
-
if uses_rgviz_append && !@defined_rgviz_append
|
113
|
+
if uses_rgviz_append[0] && !@defined_rgviz_append
|
152
114
|
out << "function rgviz_append(s, b, a) {\n"
|
153
115
|
out << "var q = '';\n"
|
154
116
|
out << "if (s.length == 0) {\n"
|
@@ -218,7 +180,7 @@ module Rgviz
|
|
218
180
|
|
219
181
|
if load != :auto && load_package
|
220
182
|
# Load visualizations and the package, if not already loaded
|
221
|
-
package ||= get_package(kind)
|
183
|
+
package ||= Rgviz::ViewHelper.get_package(kind)
|
222
184
|
|
223
185
|
@packages ||= []
|
224
186
|
unless @packages.include?(package)
|
@@ -261,6 +223,67 @@ module Rgviz
|
|
261
223
|
end
|
262
224
|
|
263
225
|
module_function :rgviz
|
226
|
+
|
227
|
+
def self.get_package(name)
|
228
|
+
down = name.downcase
|
229
|
+
case down
|
230
|
+
when 'areachart', 'barchart', 'bubblechart', 'candlestickchart',
|
231
|
+
'columnchart', 'combochart', 'linechart', 'piechart',
|
232
|
+
'scatterchart', 'steppedareachart' then 'corechart'
|
233
|
+
else down
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def self.process_options(opts, params, visitor, uses_rgviz_get_value, uses_rgviz_append)
|
238
|
+
if opts.is_a?(Array)
|
239
|
+
i = 0
|
240
|
+
opts.each do |value|
|
241
|
+
opts[i] = process_option(value, params, visitor, uses_rgviz_get_value, uses_rgviz_append)
|
242
|
+
i += 1
|
243
|
+
end
|
244
|
+
elsif opts.is_a?(Hash)
|
245
|
+
opts.each do |key, value|
|
246
|
+
opts[key] = process_option(value, params, visitor, uses_rgviz_get_value, uses_rgviz_append)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
opts
|
250
|
+
end
|
251
|
+
|
252
|
+
def self.process_option(value, params, visitor, uses_rgviz_get_value, uses_rgviz_append)
|
253
|
+
if value.is_a?(Hash) || value.is_a?(Array)
|
254
|
+
return process_options value, params, visitor, uses_rgviz_get_value, uses_rgviz_append
|
255
|
+
end
|
256
|
+
|
257
|
+
return value unless value.kind_of?(String)
|
258
|
+
|
259
|
+
source = visitor.get_source(value, false)
|
260
|
+
return value unless source[:source]
|
261
|
+
|
262
|
+
case source[:source]
|
263
|
+
when :html
|
264
|
+
s = "rgviz_get_value('#{source[:id]}')"
|
265
|
+
def s.encode_json(options = {})
|
266
|
+
self
|
267
|
+
end
|
268
|
+
uses_rgviz_get_value[0] = true
|
269
|
+
return s
|
270
|
+
when :js
|
271
|
+
s = "#{source[:id]}()"
|
272
|
+
def s.encode_json(options = {})
|
273
|
+
self
|
274
|
+
end
|
275
|
+
return s
|
276
|
+
when :param
|
277
|
+
s = "param_#{source[:id]}"
|
278
|
+
def s.encode_json(options = {})
|
279
|
+
self
|
280
|
+
end
|
281
|
+
params << source[:id].to_i unless params.include?(source[:id])
|
282
|
+
return s
|
283
|
+
end
|
284
|
+
|
285
|
+
return value
|
286
|
+
end
|
264
287
|
end
|
265
288
|
|
266
289
|
class MagicNamesVisitor < Visitor
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgviz-rails
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 74
|
8
|
-
version: "0.74"
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.75'
|
5
|
+
prerelease:
|
9
6
|
platform: ruby
|
10
|
-
authors:
|
7
|
+
authors:
|
11
8
|
- Ary Borenszweig
|
12
9
|
autorequire:
|
13
10
|
bindir: bin
|
14
11
|
cert_chain: []
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
dependencies:
|
19
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-10-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
20
15
|
name: rgviz
|
21
|
-
|
22
|
-
|
23
|
-
requirements:
|
24
|
-
- -
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
|
27
|
-
- 0
|
28
|
-
- 46
|
29
|
-
version: "0.46"
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.46'
|
30
22
|
type: :runtime
|
31
|
-
version_requirements: *id001
|
32
|
-
- !ruby/object:Gem::Dependency
|
33
|
-
name: rails
|
34
23
|
prerelease: false
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.46'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rails
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
42
38
|
type: :runtime
|
43
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
44
46
|
description:
|
45
47
|
email: aborenszweig@manas.com.ar
|
46
48
|
executables: []
|
47
|
-
|
48
49
|
extensions: []
|
49
|
-
|
50
|
-
extra_rdoc_files:
|
50
|
+
extra_rdoc_files:
|
51
51
|
- README.markdown
|
52
|
-
files:
|
52
|
+
files:
|
53
53
|
- lib/rgviz_rails.rb
|
54
54
|
- lib/rgviz_rails/executor.rb
|
55
55
|
- lib/rgviz_rails/js_renderer.rb
|
@@ -62,35 +62,28 @@ files:
|
|
62
62
|
- lib/rgviz_rails/init.rb
|
63
63
|
- rails/init.rb
|
64
64
|
- README.markdown
|
65
|
-
has_rdoc: false
|
66
65
|
homepage: http://github.com/asterite/rgviz-rails
|
67
66
|
licenses: []
|
68
|
-
|
69
67
|
post_install_message:
|
70
68
|
rdoc_options: []
|
71
|
-
|
72
|
-
require_paths:
|
69
|
+
require_paths:
|
73
70
|
- lib
|
74
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
requirements:
|
83
|
-
- -
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
|
86
|
-
- 0
|
87
|
-
version: "0"
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
88
83
|
requirements: []
|
89
|
-
|
90
84
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.
|
85
|
+
rubygems_version: 1.8.23
|
92
86
|
signing_key:
|
93
87
|
specification_version: 3
|
94
88
|
summary: rgviz for rails
|
95
89
|
test_files: []
|
96
|
-
|