hyper-vis 1.0.0.lap34 → 1.0.1
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.
- checksums.yaml +4 -4
- data/README.md +154 -23
- data/hyper-vis.gemspec +5 -5
- data/lib/hyper-vis.rb +7 -0
- data/lib/hyperloop/vis/graph2d/component.rb +16 -0
- data/lib/hyperloop/vis/graph2d/mixin.rb +89 -0
- data/lib/hyperloop/vis/graph3d/component.rb +15 -0
- data/lib/hyperloop/vis/graph3d/mixin.rb +79 -0
- data/lib/hyperloop/vis/network/mixin.rb +1 -1
- data/lib/hyperloop/vis/timeline/component.rb +16 -0
- data/lib/hyperloop/vis/timeline/mixin.rb +89 -0
- data/lib/hyperloop/vis/version.rb +1 -1
- data/lib/vis.rb +4 -1
- data/lib/vis/data_common.rb +46 -0
- data/lib/vis/data_set.rb +6 -1
- data/lib/vis/graph2d.rb +145 -0
- data/lib/vis/graph3d.rb +135 -0
- data/lib/vis/network.rb +187 -8
- data/lib/vis/railtie.rb +7 -0
- data/lib/vis/timeline.rb +338 -0
- data/lib/vis/utilities.rb +7 -199
- data/spec/test_app/Gemfile +2 -4
- data/spec/test_app/app/assets/stylesheets/application.css +2 -1
- data/spec/test_app/db/schema.rb +28 -0
- data/spec/vis_graph2d_component_spec.rb +89 -0
- data/spec/vis_graph2d_spec.rb +304 -0
- data/spec/vis_graph3d_component_spec.rb +124 -0
- data/spec/vis_graph3d_spec.rb +247 -0
- data/spec/vis_timeline_component_spec.rb +89 -0
- data/spec/vis_timeline_spec.rb +425 -0
- metadata +37 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8b7330654c04a70b036a7c1fa3d32b1bfb5fc5c338516a031ef8daa1ff2e125
|
4
|
+
data.tar.gz: 45241374d63e213eb3d881a8031e71a4f901dfbf32fa637b186c1b1db8955a96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ac9706a1521c635d9867a58eaa83e6db898693d5e6ea1db2446828b7398dfcf5b288da4c6d7139287a1a12e7458b76781e38e093dbc1194fc1385366e99a249
|
7
|
+
data.tar.gz: '09fbdf2b037a43e8014f8fa1f4bd1c0ece333bb6b64012823832b332d884cb6243cb1d6a6c1e9ffbf633e1811d1dc595254a61e74608e0dcdb7485943232c040'
|
data/README.md
CHANGED
@@ -1,48 +1,116 @@
|
|
1
1
|
# hyper-vis
|
2
2
|
|
3
|
-
A Opal Ruby
|
4
|
-
|
5
|
-
- Vis Dataset
|
6
|
-
- Vis Dataview
|
7
|
-
- Vis
|
3
|
+
A [Opal](http://opalrb.com) Ruby wrapper for [Vis.js](http://visjs.org) with a [Ruby-Hyperloop](http://ruby-hyperloop.org) Component.
|
4
|
+
Implements the complete API for:
|
5
|
+
- [Vis Dataset](http://visjs.org/docs/data/dataset.html)
|
6
|
+
- [Vis Dataview](http://visjs.org/docs/data/dataview.html)
|
7
|
+
- [Vis Graph2d](http://visjs.org/docs/graph2d/)
|
8
|
+
- [Vis Graph3d](http://visjs.org/docs/graph3d/)
|
9
|
+
- [Vis Network](http://visjs.org/docs/network/)
|
10
|
+
- [Vis Timeline](http://visjs.org/docs/timeline/)
|
8
11
|
|
9
|
-
|
10
|
-
|
12
|
+
Includes vis.js version 4.21.0
|
13
|
+
|
14
|
+
## Demo
|
15
|
+
|
16
|
+
Reactive hyper-vis in action:
|
17
|
+
|
18
|
+
[](http://www.youtube.com/watch?v=fPSpESBbeMQ "Reactivity Demo")
|
19
|
+
|
20
|
+
## Quality
|
21
|
+
[](https://semaphoreci.com/janbiedermann/hyper-vis)
|
22
|
+
[](https://github.com/janbiedermann/hyper-vis/issues)
|
23
|
+
[](http://isitmaintained.com/project/janbiedermann/hyper-vis "Percentage of issues still open")
|
24
|
+
[](http://isitmaintained.com/project/janbiedermann/hyper-vis "Average time to resolve an issue")
|
25
|
+
[](https://github.com/janbiedermann/hyper-vis/pulls)
|
26
|
+
|
27
|
+
#### Tests
|
11
28
|
```
|
12
|
-
|
29
|
+
Finished in 2 minutes 39.7 seconds (files took 3.18 seconds to load)
|
30
|
+
132 examples, 0 failures, 15 pending
|
31
|
+
```
|
32
|
+
#### To run Tests
|
33
|
+
Clone repo, then:
|
34
|
+
```bash
|
35
|
+
bundle update
|
36
|
+
cd spec/test_app
|
37
|
+
bundle update
|
38
|
+
cd ../..
|
39
|
+
bundle exec rspec
|
13
40
|
```
|
14
|
-
and `bundle update`
|
15
|
-
hyper-vis depends on `hyper-component` from (ruby-hyperloop)[http://ruby-hyperloop.org]
|
16
41
|
|
17
|
-
|
42
|
+
## Installation
|
43
|
+
for a Rails app:
|
44
|
+
```ruby
|
45
|
+
gem 'hyper-vis'
|
18
46
|
```
|
47
|
+
and `bundle update`.
|
48
|
+
|
49
|
+
hyper-vis depends on `hyper-component` from Ruby-Hyperloop but can be used without it.
|
50
|
+
|
51
|
+
vis.js is automatically imported for Ruby-Hyperloop. If you get vis.js with webpacker, you may need to cancel the import in your config/intializers/hyperloop.rb
|
52
|
+
```ruby
|
19
53
|
config.cancel_import 'vis/source/vis.js'
|
20
54
|
```
|
21
|
-
The wrapper expects a global `vis
|
22
|
-
|
55
|
+
The wrapper expects a global `vis` (not `Vis`) to be availabe in javascript.
|
56
|
+
For Vis to function as expected the stylesheets must be included.
|
57
|
+
For a Rails app, the asset path is automatically added.
|
58
|
+
In your `application.css` add:
|
59
|
+
```
|
60
|
+
*= require vis.css
|
61
|
+
```
|
62
|
+
For other frameworks vis.js, stylesheets and images are available in the gems `lib/vis/source/` directory.
|
23
63
|
|
24
|
-
|
64
|
+
## Usage
|
25
65
|
|
26
|
-
|
27
|
-
|
66
|
+
The wrapper follows vis 1 to 1, conforming to ruby standards, instead of `setSize` in javascript, you would use `set_size`. Also see specs in the `specs` directory for usage or the vis documentation (linked above).
|
67
|
+
All arguments or return values are 'rubyfied' as much as possible, so you can just use ruby.
|
68
|
+
|
69
|
+
### The Vis part
|
70
|
+
```ruby
|
28
71
|
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
29
72
|
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
30
73
|
dom_node = Vis::Network.test_container
|
31
74
|
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
32
75
|
xy = net.canvas_to_dom({x: 10, y: 10})
|
33
76
|
```
|
34
|
-
|
35
|
-
The
|
36
|
-
The
|
77
|
+
### The Component part
|
78
|
+
The Components takes care about all the things necessary to make Vis.js play nice with React.
|
79
|
+
The Components also provide a helper to access the document: `document`.
|
80
|
+
|
81
|
+
#### Vis::Network::Mixin
|
37
82
|
Vis::Network can be used within the render_with_dom_node.
|
38
|
-
```
|
83
|
+
```ruby
|
39
84
|
class MyVisNetworkComponent
|
40
85
|
include Hyperloop::Vis::Network::Mixin
|
41
86
|
|
42
|
-
|
87
|
+
# the component automatically calls the render_with_dom_node block every
|
88
|
+
# time new data or options are received
|
89
|
+
|
90
|
+
# however
|
91
|
+
# setting automatic_refresh false turns that off ...
|
92
|
+
# (default is true, so this is optional):
|
93
|
+
automatic_refresh false
|
94
|
+
|
95
|
+
# ... and with automatic_refresh false refresh can
|
96
|
+
# be handled in the before_receive_props callback
|
97
|
+
# for example (this is also optional):
|
98
|
+
before_receive_props do |new_props|
|
99
|
+
# data can be accessed using the helper vis_data
|
100
|
+
if new_props[:vis_data] != vis_data
|
101
|
+
@net.set_data(new_props[:vis_data])
|
102
|
+
end
|
103
|
+
end
|
43
104
|
|
44
|
-
|
105
|
+
render_with_dom_node do |dom_node, data, options|
|
106
|
+
# its important to use the data as passed in as 'data' argument
|
107
|
+
# to get the latests passed data for each new render
|
108
|
+
@net = Vis::Network.new(dom_node, data, options)
|
109
|
+
|
110
|
+
# data is also atomatically saved and available using the helper
|
111
|
+
vis_data
|
45
112
|
|
113
|
+
# example of using the document helper
|
46
114
|
canvas = document.JS.querySelector('canvas')
|
47
115
|
end
|
48
116
|
end
|
@@ -51,13 +119,76 @@ class AOuterComponent < Hyperloop::Component
|
|
51
119
|
render do
|
52
120
|
received_data = []
|
53
121
|
|
122
|
+
# example of using a callback in the options
|
54
123
|
options = { manipulation: {
|
55
124
|
edit_node: proc { |node_data, callback| received_data << node_data }
|
56
125
|
}}
|
57
126
|
|
127
|
+
# initialize a dataset
|
58
128
|
data = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
59
129
|
|
130
|
+
# call the component
|
60
131
|
DIV { MyVisNetworkComponent(vis_data: data, otions: options)}
|
61
132
|
end
|
62
133
|
end
|
63
|
-
```
|
134
|
+
```
|
135
|
+
#### Vis::Graph3d::Mixin
|
136
|
+
Works the same as Vis::Network::Mixin
|
137
|
+
|
138
|
+
#### Vis::Timeline::Mixin
|
139
|
+
Similar to Vis::Network, mostly params and helpers are different:
|
140
|
+
```ruby
|
141
|
+
class MyVisTimelineComponent
|
142
|
+
include Hyperloop::Vis::Timeline::Mixin
|
143
|
+
|
144
|
+
# the component automatically calls the render_with_dom_node block every
|
145
|
+
# time new data or options are received
|
146
|
+
|
147
|
+
# however
|
148
|
+
# setting automatic_refresh false turns that off ...
|
149
|
+
# (default is true, so this is optional):
|
150
|
+
automatic_refresh false
|
151
|
+
|
152
|
+
# ... and with automatic_refresh false refresh can
|
153
|
+
# be handled in the before_receive_props callback
|
154
|
+
# for example (this is also optional):
|
155
|
+
before_receive_props do |new_props|
|
156
|
+
# data can be accessed using the helpers:
|
157
|
+
items
|
158
|
+
groups
|
159
|
+
options
|
160
|
+
end
|
161
|
+
|
162
|
+
render_with_dom_node do |dom_node, items, groups, options|
|
163
|
+
# its important to use the data as passed in as 'data' argument
|
164
|
+
# to get the latests passed data for each new render
|
165
|
+
@net = Vis::Timeline.new(dom_node, items, groups, options)
|
166
|
+
|
167
|
+
# data is also atomatically saved and available using the helpers
|
168
|
+
items
|
169
|
+
groups
|
170
|
+
options
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
class AOuterComponent < Hyperloop::Component
|
175
|
+
render do
|
176
|
+
options = { align: 'left' }
|
177
|
+
|
178
|
+
# initialize a dataset
|
179
|
+
data = Vis::DataSet.new([
|
180
|
+
{id: 1, content: 'item 1', start: '2013-04-20'},
|
181
|
+
{id: 2, content: 'item 2', start: '2013-04-14'},
|
182
|
+
{id: 3, content: 'item 3', start: '2013-04-18'},
|
183
|
+
{id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19'},
|
184
|
+
{id: 5, content: 'item 5', start: '2013-04-25'},
|
185
|
+
{id: 6, content: 'item 6', start: '2013-04-27'}
|
186
|
+
])
|
187
|
+
|
188
|
+
# call the component
|
189
|
+
DIV { MyVisTimelineComponent(items: data, otions: options)}
|
190
|
+
end
|
191
|
+
end
|
192
|
+
```
|
193
|
+
#### Vis::Graph2d::Mixin
|
194
|
+
Works the same as Vis::Timeline::Mixin
|
data/hyper-vis.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.author = "Jan Biedermann"
|
7
7
|
s.email = "jan@kursator.de"
|
8
8
|
s.homepage = "https://github.com/janbiedermann/hyper-vis"
|
9
|
-
s.summary = "Ruby
|
9
|
+
s.summary = "A Opal Ruby wraper for Vis.js with a Ruby-Hyperloop Component."
|
10
10
|
s.description = "Write React Components in ruby to show graphics created with Vis.js in the ruby way"
|
11
11
|
|
12
12
|
s.files = `git ls-files`.split("\n")
|
@@ -16,10 +16,10 @@ Gem::Specification.new do |s|
|
|
16
16
|
|
17
17
|
s.add_runtime_dependency "opal", "~> 0.11.0"
|
18
18
|
s.add_runtime_dependency "opal-activesupport", "~> 0.3.1"
|
19
|
-
s.add_runtime_dependency "hyper-component", "~> 1.0.0.
|
20
|
-
s.add_runtime_dependency "hyperloop-config", "~> 1.0.0.
|
21
|
-
s.add_development_dependency "hyperloop", "~> 1.0.0.
|
22
|
-
s.add_development_dependency "hyper-spec", "~> 1.0.0.
|
19
|
+
s.add_runtime_dependency "hyper-component", "~> 1.0.0.lap27"
|
20
|
+
s.add_runtime_dependency "hyperloop-config", "~> 1.0.0.lap27"
|
21
|
+
s.add_development_dependency "hyperloop", "~> 1.0.0.lap27"
|
22
|
+
s.add_development_dependency "hyper-spec", "~> 1.0.0.lap27"
|
23
23
|
s.add_development_dependency "listen"
|
24
24
|
s.add_development_dependency "rake", ">= 11.3.0"
|
25
25
|
s.add_development_dependency "rails", ">= 5.1.0"
|
data/lib/hyper-vis.rb
CHANGED
@@ -8,8 +8,15 @@ require 'hyperloop/vis/version'
|
|
8
8
|
if RUBY_ENGINE == 'opal'
|
9
9
|
require 'vis'
|
10
10
|
require 'hyper-component'
|
11
|
+
require 'hyperloop/vis/graph2d/mixin'
|
12
|
+
require 'hyperloop/vis/graph2d/component'
|
13
|
+
require 'hyperloop/vis/graph3d/mixin'
|
14
|
+
require 'hyperloop/vis/graph3d/component'
|
11
15
|
require 'hyperloop/vis/network/mixin'
|
12
16
|
require 'hyperloop/vis/network/component'
|
17
|
+
require 'hyperloop/vis/timeline/mixin'
|
18
|
+
require 'hyperloop/vis/timeline/component'
|
13
19
|
else
|
20
|
+
require 'vis/railtie' if defined?(Rails)
|
14
21
|
Opal.append_path __dir__.untaint
|
15
22
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Hyperloop
|
2
|
+
module Vis
|
3
|
+
module Graph2d
|
4
|
+
class Component
|
5
|
+
include Hyperloop::Vis::Graph2d::Mixin
|
6
|
+
def self.inherited(base)
|
7
|
+
base.class_eval do
|
8
|
+
param items: nil
|
9
|
+
param groups: nil
|
10
|
+
param options: nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'react/component'
|
2
|
+
|
3
|
+
module Hyperloop
|
4
|
+
module Vis
|
5
|
+
module Graph2d
|
6
|
+
module Mixin
|
7
|
+
def self.included(base)
|
8
|
+
base.include(Hyperloop::Component::Mixin)
|
9
|
+
base.class_eval do
|
10
|
+
param items: nil
|
11
|
+
param groups: nil
|
12
|
+
param options: nil
|
13
|
+
|
14
|
+
def _set_dom_node(dom_node)
|
15
|
+
@_dom_node = dom_node
|
16
|
+
end
|
17
|
+
|
18
|
+
def items
|
19
|
+
@_items
|
20
|
+
end
|
21
|
+
|
22
|
+
def groups
|
23
|
+
@_groups
|
24
|
+
end
|
25
|
+
|
26
|
+
def document
|
27
|
+
`window.document`
|
28
|
+
end
|
29
|
+
|
30
|
+
def options
|
31
|
+
@_options
|
32
|
+
end
|
33
|
+
|
34
|
+
def automatic_refresh
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.automatic_refresh(value)
|
39
|
+
define_method(:automatic_refresh) do
|
40
|
+
value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.render_with_dom_node(tag = 'DIV', &block)
|
45
|
+
render do
|
46
|
+
@_vis_render_block = block
|
47
|
+
@_items = params.items
|
48
|
+
@_groups = params.groups
|
49
|
+
@_options = params.options
|
50
|
+
send(tag, ref: method(:_set_dom_node).to_proc)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def should_component_update?
|
55
|
+
`false`
|
56
|
+
end
|
57
|
+
|
58
|
+
after_mount do
|
59
|
+
if @_dom_node && @_vis_render_block
|
60
|
+
instance_exec(@_dom_node, @_items, @_groups, @_options, &@_vis_render_block)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
before_receive_props do |new_props|
|
65
|
+
if automatic_refresh && @_dom_node && @_vis_render_block
|
66
|
+
changed = false
|
67
|
+
if new_props[:items] != @_items
|
68
|
+
@_items = new_props[:items]
|
69
|
+
changed = true
|
70
|
+
end
|
71
|
+
if new_props[:groups] != @_groups
|
72
|
+
@_items = new_props[:groups]
|
73
|
+
changed = true
|
74
|
+
end
|
75
|
+
if new_props[:options] != @_options
|
76
|
+
@_options = new_props[:options]
|
77
|
+
changed = true
|
78
|
+
end
|
79
|
+
if changed
|
80
|
+
instance_exec(@_dom_node, @_items, @_groups, @_options, &@_vis_render_block)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'react/component'
|
2
|
+
|
3
|
+
module Hyperloop
|
4
|
+
module Vis
|
5
|
+
module Graph3d
|
6
|
+
module Mixin
|
7
|
+
def self.included(base)
|
8
|
+
base.include(Hyperloop::Component::Mixin)
|
9
|
+
base.class_eval do
|
10
|
+
param vis_data: nil
|
11
|
+
param options: nil
|
12
|
+
|
13
|
+
def _set_dom_node(dom_node)
|
14
|
+
@_dom_node = dom_node
|
15
|
+
end
|
16
|
+
|
17
|
+
def vis_data
|
18
|
+
@_data
|
19
|
+
end
|
20
|
+
|
21
|
+
def document
|
22
|
+
`window.document`
|
23
|
+
end
|
24
|
+
|
25
|
+
def options
|
26
|
+
@_options
|
27
|
+
end
|
28
|
+
|
29
|
+
def automatic_refresh
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.automatic_refresh(value)
|
34
|
+
define_method(:automatic_refresh) do
|
35
|
+
value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.render_with_dom_node(tag = 'DIV', &block)
|
40
|
+
render do
|
41
|
+
@_vis_render_block = block
|
42
|
+
@_data = params.vis_data
|
43
|
+
@_options = params.options
|
44
|
+
send(tag, ref: method(:_set_dom_node).to_proc)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def should_component_update?
|
49
|
+
`false`
|
50
|
+
end
|
51
|
+
|
52
|
+
after_mount do
|
53
|
+
if @_dom_node && @_vis_render_block
|
54
|
+
instance_exec(@_dom_node, @_data, @_options, &@_vis_render_block)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
before_receive_props do |new_props|
|
59
|
+
if automatic_refresh && @_dom_node && @_vis_render_block
|
60
|
+
changed = false
|
61
|
+
if new_props[:vis_data] != @_data
|
62
|
+
@_data = new_props[:vis_data]
|
63
|
+
changed = true
|
64
|
+
end
|
65
|
+
if new_props[:options] != @_options
|
66
|
+
@_options = new_props[:options]
|
67
|
+
changed = true
|
68
|
+
end
|
69
|
+
if changed
|
70
|
+
instance_exec(@_dom_node, @_data, @_options, &@_vis_render_block)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|