rgviz-rails 0.72 → 0.73
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/README.markdown +31 -3
- data/lib/rgviz_rails/view_helper.rb +44 -26
- metadata +6 -6
data/README.markdown
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
rgviz-rails
|
2
2
|
===========
|
3
3
|
|
4
|
+
[](http://travis-ci.org/asterite/rgviz-rails)
|
5
|
+
|
4
6
|
This library makes it easy to implement a visualization data source so that you can easily chart or visualize your data from [ActiveRecord](http://ar.rubyonrails.org/) models or from in-memory arrays. the library implements the [Google Visualization API wire protocol](http://code.google.com/apis/visualization/documentation/dev/implementing_data_source.html).
|
5
7
|
|
6
8
|
It also allows you to [render the visualizations in a view template](https://github.com/asterite/rgviz-rails/wiki/showing-a-visualization-in-a-view) in a very simple but powerful way.
|
@@ -18,7 +20,7 @@ Rails 3
|
|
18
20
|
In your gemfile
|
19
21
|
|
20
22
|
gem 'rgviz'
|
21
|
-
gem 'rgviz-rails'
|
23
|
+
gem 'rgviz-rails', :require => 'rgviz_rails'
|
22
24
|
|
23
25
|
Rails 2.x
|
24
26
|
---------
|
@@ -26,7 +28,7 @@ Rails 2.x
|
|
26
28
|
In your environment.rb
|
27
29
|
|
28
30
|
config.gem "rgviz"
|
29
|
-
config.gem "rgviz-rails"
|
31
|
+
config.gem "rgviz-rails", :require => 'rgviz_rails'
|
30
32
|
|
31
33
|
Usage
|
32
34
|
-----
|
@@ -119,10 +121,36 @@ You can also apply a query over an array of arrays that contains your "records"
|
|
119
121
|
|
120
122
|
This is very useful if you need to present visualizations against data coming from a csv file.
|
121
123
|
|
124
|
+
Virtual columns
|
125
|
+
---------------
|
126
|
+
|
127
|
+
GQL is nice but it's not very powerful (except for the cute pivot clause).
|
128
|
+
|
129
|
+
If you need to select columns using complex SQL, you might be able to do it with virtual columns.
|
130
|
+
|
131
|
+
For example, in your controller you put:
|
132
|
+
|
133
|
+
render :rgviz => Person, :virtual_columns => {
|
134
|
+
'age_range' => {
|
135
|
+
:sql => "case when age < 20 then 'young' else 'old' end",
|
136
|
+
:type => :string
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
Then in a query you can do:
|
141
|
+
|
142
|
+
select age_range ...
|
143
|
+
|
144
|
+
Note that the keys of the virtual_columns hash must be strings. The value can be a hash with :sql and :type key-value pairs (since GQL needs the type of every column), or can be just a string if you want the column to be replaced by another GQL expression. For example:
|
145
|
+
|
146
|
+
render :rgviz => Person, :virtual_columns => {
|
147
|
+
'age_plus_two' => 'age + 2'
|
148
|
+
}
|
149
|
+
|
122
150
|
Current limitations
|
123
151
|
-------------------
|
124
152
|
|
125
|
-
* the *format* clause works, but formatting is as in ruby (like "%.2f" for numbers, "foo %s bar" for strings, and "%y-%m-%d" for dates, as specified by
|
153
|
+
* the *format* clause works, but formatting is as in ruby (like "%.2f" for numbers, "foo %s bar" for strings, and "%y-%m-%d" for dates, as specified by [Time#strftime](http://www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime))
|
126
154
|
* only supports mysql, postgresql and sqlite adapters
|
127
155
|
* these scalar functions are not supported for sqlite: *millisecond*, *quarter*
|
128
156
|
* these scalar functions are not supported for mysql: *millisecond*
|
@@ -23,6 +23,7 @@ module Rgviz
|
|
23
23
|
conditions = options[:conditions]
|
24
24
|
virtual_columns = options[:virtual_columns]
|
25
25
|
package = options[:package]
|
26
|
+
load = options[:load]
|
26
27
|
|
27
28
|
rgviz_events, google_events = events.partition{|x| x[0].to_s.start_with? 'rgviz'}
|
28
29
|
rgviz_events = rgviz_events.inject(Hash.new){|h, y| h[y[0]] = y[1]; h}
|
@@ -104,13 +105,24 @@ module Rgviz
|
|
104
105
|
visitor.params.each{|p| params << p unless params.include?(p)}
|
105
106
|
params = params.sort!.map{|i| "param_#{i}"}
|
106
107
|
|
108
|
+
callback = "rgviz_draw_#{id}"
|
109
|
+
|
107
110
|
out = ''
|
108
111
|
|
112
|
+
# Write the div
|
113
|
+
out << "<div id=\"#{id}\""
|
114
|
+
html.each do |key, value|
|
115
|
+
out << " #{key}=\"#{h value}\""
|
116
|
+
end
|
117
|
+
out << "></div>\n"
|
118
|
+
|
109
119
|
# Output the google jsapi tag the first time
|
110
120
|
@first_time ||= 1
|
111
|
-
|
121
|
+
|
122
|
+
if load != :auto && load_google && @first_time == 1
|
112
123
|
out << "<script type=\"text/javascript\" src=\"http://www.google.com/jsapi\"></script>\n"
|
113
124
|
end
|
125
|
+
|
114
126
|
# Now the real script
|
115
127
|
out << "<script type=\"text/javascript\">\n"
|
116
128
|
|
@@ -156,25 +168,6 @@ module Rgviz
|
|
156
168
|
@defined_rgviz_append = true
|
157
169
|
end
|
158
170
|
|
159
|
-
if load_package
|
160
|
-
# Load visualizations and the package, if not already loaded
|
161
|
-
package ||= get_package(kind)
|
162
|
-
|
163
|
-
@packages ||= []
|
164
|
-
unless @packages.include?(package)
|
165
|
-
out << "google.load(\"visualization\", \"1\", {'packages':['#{package}']});\n"
|
166
|
-
@packages << package
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
callback = "rgviz_draw_#{id}"
|
171
|
-
|
172
|
-
# Set the callback if the function doesn't have params and if the
|
173
|
-
# user didn't request to hide the visualization
|
174
|
-
if !ajax && !hidden && params.empty?
|
175
|
-
out << "google.setOnLoadCallback(#{callback});\n"
|
176
|
-
end
|
177
|
-
|
178
171
|
# Define the visualization var and data
|
179
172
|
out << "var rgviz_#{id} = null;\n"
|
180
173
|
out << "var rgviz_#{id}_data = null;\n"
|
@@ -222,19 +215,44 @@ module Rgviz
|
|
222
215
|
out << "});\n"
|
223
216
|
end
|
224
217
|
out << "}\n"
|
218
|
+
|
219
|
+
if load != :auto && load_package
|
220
|
+
# Load visualizations and the package, if not already loaded
|
221
|
+
package ||= get_package(kind)
|
222
|
+
|
223
|
+
@packages ||= []
|
224
|
+
unless @packages.include?(package)
|
225
|
+
out << "google.load(\"visualization\", \"1\", {'packages':['#{package}']"
|
226
|
+
|
227
|
+
if load == :dynamic && !ajax && !hidden && params.empty?
|
228
|
+
out << ", 'callback': #{callback}"
|
229
|
+
end
|
230
|
+
|
231
|
+
out << "});\n"
|
232
|
+
@packages << package
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
# Set the callback if the function doesn't have params and if the
|
237
|
+
# user didn't request to hide the visualization
|
238
|
+
if !load && !ajax && !hidden && params.empty?
|
239
|
+
out << "google.setOnLoadCallback(#{callback});\n"
|
240
|
+
end
|
241
|
+
|
225
242
|
out << "#{callback}()" if ajax
|
243
|
+
|
226
244
|
out << "</script>\n"
|
227
245
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
246
|
+
if load == :auto && !ajax && !hidden && params.empty?
|
247
|
+
require 'cgi'
|
248
|
+
|
249
|
+
package ||= get_package(kind)
|
250
|
+
autoload = {'modules' => [{'name' => 'visualization', 'version' => '1', 'packages' => ["#{package}"], 'callback' => callback}]}
|
251
|
+
out << "<script type=\"text/javascript\" src=\"http://www.google.com/jsapi?autoload=#{CGI.escape autoload.to_json}\"></script>\n"
|
232
252
|
end
|
233
|
-
out << "></div>\n"
|
234
253
|
|
235
254
|
@first_time = 0
|
236
255
|
|
237
|
-
|
238
256
|
if Rails::VERSION::MAJOR == 2
|
239
257
|
out
|
240
258
|
else
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgviz-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.73'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rgviz
|
16
|
-
requirement: &
|
16
|
+
requirement: &70257227777720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0.46'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70257227777720
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &70257227776920 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70257227776920
|
36
36
|
description:
|
37
37
|
email: aborenszweig@manas.com.ar
|
38
38
|
executables: []
|