rgviz-rails 0.71 → 0.72
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +43 -43
- data/lib/rgviz_rails/executor.rb +1 -1
- metadata +36 -62
data/README.markdown
CHANGED
@@ -1,125 +1,125 @@
|
|
1
1
|
rgviz-rails
|
2
2
|
===========
|
3
3
|
|
4
|
-
This library makes it easy to implement a visualization data source so that you can easily chart or visualize your data from [
|
4
|
+
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
5
|
|
6
|
-
|
6
|
+
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.
|
7
7
|
|
8
|
-
|
8
|
+
This library is built on top of [rgviz](https://github.com/asterite/rgviz).
|
9
9
|
|
10
|
-
|
10
|
+
Installation
|
11
11
|
------------
|
12
12
|
|
13
13
|
gem install rgviz-rails
|
14
14
|
|
15
|
-
|
15
|
+
Rails 3
|
16
16
|
-------
|
17
17
|
|
18
|
-
|
18
|
+
In your gemfile
|
19
19
|
|
20
20
|
gem 'rgviz'
|
21
|
-
gem 'rgviz-rails'
|
21
|
+
gem 'rgviz-rails'
|
22
22
|
|
23
|
-
|
23
|
+
Rails 2.x
|
24
24
|
---------
|
25
25
|
|
26
|
-
|
26
|
+
In your environment.rb
|
27
27
|
|
28
28
|
config.gem "rgviz"
|
29
|
-
config.gem "rgviz-rails"
|
29
|
+
config.gem "rgviz-rails"
|
30
30
|
|
31
|
-
|
31
|
+
Usage
|
32
32
|
-----
|
33
33
|
|
34
|
-
|
34
|
+
To make a method in your controller be a visualization api endpoint:
|
35
35
|
|
36
|
-
class
|
36
|
+
class VizController < ApplicationController
|
37
37
|
def person
|
38
|
-
#
|
39
|
-
render :rgviz =>
|
38
|
+
# Person is an ActiveRecord::Base class
|
39
|
+
render :rgviz => Person
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
So for example if <ttPperson</tt> has <tt>name</tt> and <tt>age</tt>, pointing your browser to:
|
44
44
|
|
45
45
|
http://localhost:3000/viz/person?select name where age > 20 limit 5
|
46
46
|
|
47
47
|
would render the necessary javascript code that implements the google visualization api wire protocol.
|
48
48
|
|
49
|
-
|
49
|
+
Associations
|
50
50
|
------------
|
51
51
|
|
52
|
-
|
52
|
+
If you want to filter, order by or group by columns that are in a model's association you can use underscores. this is better understood with an example:
|
53
53
|
|
54
|
-
class
|
54
|
+
class Person < ActiveRecord::Base
|
55
55
|
belongs_to :city
|
56
56
|
end
|
57
57
|
|
58
|
-
class
|
58
|
+
class City < ActiveRecord::Base
|
59
59
|
belongs_to :country
|
60
60
|
end
|
61
61
|
|
62
|
-
class
|
62
|
+
class Country < ActiveRecord::base
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
To select the name of the city each person belongs to:
|
66
66
|
|
67
67
|
select city_name
|
68
68
|
|
69
|
-
|
69
|
+
To select the name of the country of the city each person belongs to:
|
70
70
|
|
71
71
|
select city_country_name
|
72
72
|
|
73
|
-
|
73
|
+
A slightly more complex example:
|
74
74
|
|
75
75
|
select avg(age) where city_country_name = 'argentina' group by city_name
|
76
76
|
|
77
|
-
|
77
|
+
The library will make it in just one query, writing all the sql joins for you.
|
78
78
|
|
79
|
-
|
79
|
+
Extra conditions
|
80
80
|
----------------
|
81
81
|
|
82
|
-
|
82
|
+
Sometimes you want to limit your results the query will work with. You can do it like this:
|
83
83
|
|
84
|
-
render :rgviz =>
|
84
|
+
render :rgviz => Person, :conditions => ['age > ?', 20]
|
85
85
|
|
86
86
|
or also:
|
87
87
|
|
88
|
-
render :rgviz =>
|
88
|
+
render :rgviz => Person, :conditions => 'age > 20'
|
89
89
|
|
90
|
-
|
90
|
+
Preprocessing
|
91
91
|
-------------
|
92
92
|
|
93
|
-
|
93
|
+
If you need to tweak a result before returning it, just include a block:
|
94
94
|
|
95
|
-
render :rgviz =>
|
96
|
-
# modify the
|
95
|
+
render :rgviz => Person do |table|
|
96
|
+
# modify the Rgviz::Table object
|
97
97
|
end
|
98
98
|
|
99
|
-
|
99
|
+
Showing a visualization in a view
|
100
100
|
---------------------------------
|
101
101
|
|
102
|
-
|
102
|
+
You can invoke the rgviz method in your views. [read more about this](https://github.com/asterite/rgviz-rails/wiki/showing-a-visualization-in-a-view).
|
103
103
|
|
104
|
-
|
104
|
+
You can always do it the [old way](https://developers.google.com/chart/interactive/docs/examples#full_html_page_example).
|
105
105
|
|
106
|
-
|
106
|
+
Executing queries over in-memory arrays
|
107
107
|
---------------------------------------
|
108
108
|
|
109
|
-
|
109
|
+
You can also apply a query over an array of arrays that contains your "records" to be queried.
|
110
110
|
|
111
111
|
types = [[:id, :number], [:name, :string], [:age, :number]]
|
112
112
|
records = [
|
113
113
|
[1, 'john', 23],
|
114
114
|
[2, 'pete', 36]
|
115
115
|
]
|
116
|
-
executor =
|
116
|
+
executor = Rgviz::MemoryExecutor.new records, types
|
117
117
|
|
118
118
|
render :rgviz => executor
|
119
119
|
|
120
|
-
|
120
|
+
This is very useful if you need to present visualizations against data coming from a csv file.
|
121
121
|
|
122
|
-
|
122
|
+
Current limitations
|
123
123
|
-------------------
|
124
124
|
|
125
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 time#strftime)
|
@@ -129,7 +129,7 @@ current limitations
|
|
129
129
|
* the function *toDate* doesn't accept a number as its argument
|
130
130
|
* the *tsv* output format is not supported
|
131
131
|
|
132
|
-
|
132
|
+
Contributors
|
133
133
|
------------
|
134
134
|
|
135
|
-
* [
|
135
|
+
* [Brad Seefeld](https://github.com/bradseefeld)
|
data/lib/rgviz_rails/executor.rb
CHANGED
metadata
CHANGED
@@ -1,60 +1,45 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgviz-rails
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.72'
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 71
|
9
|
-
version: "0.71"
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Ary Borenszweig
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-07-30 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: rgviz
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70273597103400 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
- 46
|
32
|
-
version: "0.46"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.46'
|
33
22
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rails
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: *70273597103400
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rails
|
27
|
+
requirement: &70273597102640 !ruby/object:Gem::Requirement
|
39
28
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
version: "0"
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
47
33
|
type: :runtime
|
48
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70273597102640
|
49
36
|
description:
|
50
37
|
email: aborenszweig@manas.com.ar
|
51
38
|
executables: []
|
52
|
-
|
53
39
|
extensions: []
|
54
|
-
|
55
|
-
extra_rdoc_files:
|
40
|
+
extra_rdoc_files:
|
56
41
|
- README.markdown
|
57
|
-
files:
|
42
|
+
files:
|
58
43
|
- lib/rgviz_rails.rb
|
59
44
|
- lib/rgviz_rails/executor.rb
|
60
45
|
- lib/rgviz_rails/js_renderer.rb
|
@@ -67,39 +52,28 @@ files:
|
|
67
52
|
- lib/rgviz_rails/init.rb
|
68
53
|
- rails/init.rb
|
69
54
|
- README.markdown
|
70
|
-
has_rdoc: true
|
71
55
|
homepage: http://github.com/asterite/rgviz-rails
|
72
56
|
licenses: []
|
73
|
-
|
74
57
|
post_install_message:
|
75
58
|
rdoc_options: []
|
76
|
-
|
77
|
-
require_paths:
|
59
|
+
require_paths:
|
78
60
|
- lib
|
79
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
62
|
none: false
|
81
|
-
requirements:
|
82
|
-
- -
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
|
85
|
-
|
86
|
-
- 0
|
87
|
-
version: "0"
|
88
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
68
|
none: false
|
90
|
-
requirements:
|
91
|
-
- -
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
|
94
|
-
segments:
|
95
|
-
- 0
|
96
|
-
version: "0"
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
97
73
|
requirements: []
|
98
|
-
|
99
74
|
rubyforge_project:
|
100
|
-
rubygems_version: 1.
|
75
|
+
rubygems_version: 1.8.10
|
101
76
|
signing_key:
|
102
77
|
specification_version: 3
|
103
78
|
summary: rgviz for rails
|
104
79
|
test_files: []
|
105
|
-
|