hyper-vis 1.0.0.lap24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +51 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +1 -0
- data/hyper-vis.gemspec +28 -0
- data/lib/hyper-vis.rb +15 -0
- data/lib/hyperloop/vis/component.rb +12 -0
- data/lib/hyperloop/vis/mixin.rb +50 -0
- data/lib/hyperloop/vis/version.rb +5 -0
- data/lib/vis.rb +9 -0
- data/lib/vis/data_common.rb +23 -0
- data/lib/vis/data_set.rb +91 -0
- data/lib/vis/data_view.rb +29 -0
- data/lib/vis/event_support.rb +24 -0
- data/lib/vis/native.rb +11 -0
- data/lib/vis/network.rb +212 -0
- data/lib/vis/source/vis.js +59957 -0
- data/lib/vis/utilities.rb +205 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/test_app/.gitignore +23 -0
- data/spec/test_app/Gemfile +42 -0
- data/spec/test_app/README.md +24 -0
- data/spec/test_app/Rakefile +6 -0
- data/spec/test_app/app/assets/config/manifest.js +3 -0
- data/spec/test_app/app/assets/images/.keep +0 -0
- data/spec/test_app/app/assets/javascripts/application.js +14 -0
- data/spec/test_app/app/assets/javascripts/cable.js +13 -0
- data/spec/test_app/app/assets/javascripts/channels/.keep +0 -0
- data/spec/test_app/app/assets/stylesheets/application.css +15 -0
- data/spec/test_app/app/channels/application_cable/channel.rb +4 -0
- data/spec/test_app/app/channels/application_cable/connection.rb +4 -0
- data/spec/test_app/app/controllers/application_controller.rb +3 -0
- data/spec/test_app/app/controllers/concerns/.keep +0 -0
- data/spec/test_app/app/helpers/application_helper.rb +2 -0
- data/spec/test_app/app/hyperloop/components/.keep +0 -0
- data/spec/test_app/app/hyperloop/models/.keep +0 -0
- data/spec/test_app/app/hyperloop/operations/.keep +0 -0
- data/spec/test_app/app/hyperloop/stores/.keep +0 -0
- data/spec/test_app/app/jobs/application_job.rb +2 -0
- data/spec/test_app/app/mailers/application_mailer.rb +4 -0
- data/spec/test_app/app/models/application_record.rb +3 -0
- data/spec/test_app/app/models/concerns/.keep +0 -0
- data/spec/test_app/app/policies/application_policy.rb +14 -0
- data/spec/test_app/app/views/layouts/application.html.erb +14 -0
- data/spec/test_app/app/views/layouts/mailer.html.erb +13 -0
- data/spec/test_app/app/views/layouts/mailer.text.erb +1 -0
- data/spec/test_app/bin/bundle +3 -0
- data/spec/test_app/bin/rails +9 -0
- data/spec/test_app/bin/rake +9 -0
- data/spec/test_app/bin/setup +38 -0
- data/spec/test_app/bin/spring +17 -0
- data/spec/test_app/bin/update +29 -0
- data/spec/test_app/bin/yarn +11 -0
- data/spec/test_app/config.ru +5 -0
- data/spec/test_app/config/application.rb +19 -0
- data/spec/test_app/config/boot.rb +3 -0
- data/spec/test_app/config/cable.yml +10 -0
- data/spec/test_app/config/database.yml +25 -0
- data/spec/test_app/config/environment.rb +5 -0
- data/spec/test_app/config/environments/development.rb +54 -0
- data/spec/test_app/config/environments/production.rb +91 -0
- data/spec/test_app/config/environments/test.rb +42 -0
- data/spec/test_app/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/test_app/config/initializers/assets.rb +14 -0
- data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_app/config/initializers/cookies_serializer.rb +5 -0
- data/spec/test_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/test_app/config/initializers/hyperloop.rb +8 -0
- data/spec/test_app/config/initializers/inflections.rb +16 -0
- data/spec/test_app/config/initializers/mime_types.rb +4 -0
- data/spec/test_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/test_app/config/locales/en.yml +33 -0
- data/spec/test_app/config/puma.rb +56 -0
- data/spec/test_app/config/routes.rb +4 -0
- data/spec/test_app/config/secrets.yml +32 -0
- data/spec/test_app/config/spring.rb +6 -0
- data/spec/test_app/db/seeds.rb +7 -0
- data/spec/test_app/lib/assets/.keep +0 -0
- data/spec/test_app/lib/tasks/.keep +0 -0
- data/spec/test_app/log/.keep +0 -0
- data/spec/test_app/package.json +5 -0
- data/spec/test_app/public/404.html +67 -0
- data/spec/test_app/public/422.html +67 -0
- data/spec/test_app/public/500.html +66 -0
- data/spec/test_app/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/test_app/public/apple-touch-icon.png +0 -0
- data/spec/test_app/public/favicon.ico +0 -0
- data/spec/test_app/public/robots.txt +1 -0
- data/spec/test_app/test/application_system_test_case.rb +5 -0
- data/spec/test_app/test/controllers/.keep +0 -0
- data/spec/test_app/test/fixtures/.keep +0 -0
- data/spec/test_app/test/fixtures/files/.keep +0 -0
- data/spec/test_app/test/helpers/.keep +0 -0
- data/spec/test_app/test/integration/.keep +0 -0
- data/spec/test_app/test/mailers/.keep +0 -0
- data/spec/test_app/test/models/.keep +0 -0
- data/spec/test_app/test/system/.keep +0 -0
- data/spec/test_app/test/test_helper.rb +10 -0
- data/spec/test_app/tmp/.keep +0 -0
- data/spec/test_app/vendor/.keep +0 -0
- data/spec/vis_component_spec.rb +40 -0
- data/spec/vis_data_set_spec.rb +184 -0
- data/spec/vis_data_view_spec.rb +112 -0
- data/spec/vis_network_spec.rb +557 -0
- metadata +387 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fe18835be08b221fd9615c5726edee4a71c3fb58381f57b97e174e4ec7c762bf
|
4
|
+
data.tar.gz: c12b8e5d6289cf07211e077e1e026caaeb0caaa07167ed63ead659d5ee1dbc63
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 491a08e191f79ccdb77c279850f3d30688a6bc798ca24e39945a63427ac4e244444351df077e1d0251b58b86f5f560da8aa6be3c2c809c23c7b2b297120232e5
|
7
|
+
data.tar.gz: f2dc038fc7c21240169882776ca970e4f91435406063885148013724d1f736061f9b888a8feda6019d619f9abffe984673dde5b6f96f4de02f50e00409920f55
|
data/.gitignore
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
Gemfile.lock
|
46
|
+
spec/test_app/Gemfile.lock
|
47
|
+
# .ruby-version
|
48
|
+
# .ruby-gemset
|
49
|
+
|
50
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
51
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jan Biedermann
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# hyper-vis
|
data/hyper-vis.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "lib/hyperloop/vis/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "hyper-vis"
|
5
|
+
s.version = Hyperloop::Vis::VERSION
|
6
|
+
s.author = "Jan Biedermann"
|
7
|
+
s.email = "jan@kursator.de"
|
8
|
+
s.homepage = "https://github.com/janbiedermann/hyper-vis"
|
9
|
+
s.summary = "Ruby bindings for Vis as a Ruby Hyperloop Component"
|
10
|
+
s.description = "Write React Components in ruby to show graphics created with Vis.js in the ruby way"
|
11
|
+
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
|
17
|
+
s.add_runtime_dependency "opal", "~> 0.11.0"
|
18
|
+
s.add_runtime_dependency "opal-activesupport", "~> 0.3.1"
|
19
|
+
s.add_runtime_dependency "hyper-component", "~> 1.0.0.lap23"
|
20
|
+
s.add_runtime_dependency "hyperloop-config", "~> 1.0.0.lap23"
|
21
|
+
s.add_development_dependency "hyperloop", "~> 1.0.0.lap23"
|
22
|
+
s.add_development_dependency "hyper-spec", "~> 1.0.0.lap23"
|
23
|
+
s.add_development_dependency "listen"
|
24
|
+
s.add_development_dependency "rake", ">= 11.3.0"
|
25
|
+
s.add_development_dependency "rails", ">= 5.1.0"
|
26
|
+
s.add_development_dependency "rspec-rails"
|
27
|
+
s.add_development_dependency "sqlite3"
|
28
|
+
end
|
data/lib/hyper-vis.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'hyperloop-config'
|
2
|
+
require 'hyper-component'
|
3
|
+
Hyperloop.import 'vis/source/vis.js', client_only: true
|
4
|
+
Hyperloop.import 'hyper-vis'
|
5
|
+
require 'opal-activesupport'
|
6
|
+
require 'hyperloop/vis/version'
|
7
|
+
|
8
|
+
if RUBY_ENGINE == 'opal'
|
9
|
+
require 'vis'
|
10
|
+
require 'hyper-component'
|
11
|
+
require 'hyperloop/vis/mixin'
|
12
|
+
require 'hyperloop/vis/component'
|
13
|
+
else
|
14
|
+
Opal.append_path __dir__.untaint
|
15
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'react/component'
|
2
|
+
|
3
|
+
module Hyperloop
|
4
|
+
module Vis
|
5
|
+
module Mixin
|
6
|
+
def self.included(base)
|
7
|
+
base.include(Hyperloop::Component::Mixin)
|
8
|
+
base.class_eval do
|
9
|
+
param data: nil
|
10
|
+
|
11
|
+
def _set_dom_node(dom_node)
|
12
|
+
@_dom_node = dom_node
|
13
|
+
end
|
14
|
+
|
15
|
+
def data
|
16
|
+
@_data
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.render_with_dom_node(tag = 'DIV', &block)
|
20
|
+
render do
|
21
|
+
@_vis_render_block = block
|
22
|
+
@_data = params.data
|
23
|
+
send(tag, ref: method(:_set_dom_node).to_proc)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def should_component_update?
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
after_mount do
|
32
|
+
if @_dom_node && @_vis_render_block
|
33
|
+
@_vis_render_block.call(@_dom_node, @_data)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
before_receive_props do |new_props|
|
38
|
+
if new_props[:data] != @_data
|
39
|
+
@_data = new_props[:data]
|
40
|
+
if @_dom_node && @_vis_render_block
|
41
|
+
@_vis_render_block.call(@_dom_node, @_data)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/vis.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Vis
|
2
|
+
module DataCommon
|
3
|
+
def [](id)
|
4
|
+
get(id)
|
5
|
+
end
|
6
|
+
|
7
|
+
def get(*args)
|
8
|
+
if `Opal.is_a(args.$last(), Opal.Hash)`
|
9
|
+
args.push(options_to_native(args.pop))
|
10
|
+
end
|
11
|
+
res = `self["native"].get.apply(self["native"], Opal.to_a(args))`
|
12
|
+
if `res !== null && Opal.is_a(res, Opal.Array)`
|
13
|
+
native_to_hash_array(res)
|
14
|
+
else
|
15
|
+
`res !== null ? Opal.Hash.$new(res) : #{nil}`
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_ids(options)
|
20
|
+
@native.JS.getIds(options_to_native(options))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/vis/data_set.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
module Vis
|
2
|
+
class DataSet
|
3
|
+
include Native
|
4
|
+
include Vis::Utilities
|
5
|
+
include Vis::EventSupport
|
6
|
+
include Vis::DataCommon
|
7
|
+
|
8
|
+
aliases_native %i[clear distinct flush length]
|
9
|
+
native_method_with_options :setOptions
|
10
|
+
alias :size :length
|
11
|
+
|
12
|
+
attr_reader :event_handlers
|
13
|
+
|
14
|
+
def initialize(*args)
|
15
|
+
if args[0] && `Opal.is_a(args[0], Opal.Hash)`
|
16
|
+
hash_array = []
|
17
|
+
options = args[0]
|
18
|
+
elsif args[0] && `Opal.is_a(args[0], Opal.Array)`
|
19
|
+
hash_array = args[0]
|
20
|
+
options = args[1] ? args[1] : {}
|
21
|
+
else
|
22
|
+
hash_array = []
|
23
|
+
options = {}
|
24
|
+
end
|
25
|
+
native_data = hash_array_to_native(hash_array)
|
26
|
+
native_options = options_to_native(options)
|
27
|
+
@event_handlers = {}
|
28
|
+
@native = `new vis.DataSet(native_data, native_options)`
|
29
|
+
end
|
30
|
+
|
31
|
+
def []=(id, hash)
|
32
|
+
if get(id)
|
33
|
+
update(hash[:id] = id)
|
34
|
+
else
|
35
|
+
add(hash[:id] = id)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def add(*args)
|
40
|
+
if args[0] && `Opal.is_a(args[0], Opal.Hash)`
|
41
|
+
args[0] = args[0].to_n
|
42
|
+
elsif args[0] && `Opal.is_a(args[0], Opal.Array)`
|
43
|
+
args[0] = hash_array_to_native(args[0])
|
44
|
+
end
|
45
|
+
`self["native"].add.apply(self["native"], Opal.to_a(args))`
|
46
|
+
end
|
47
|
+
|
48
|
+
def each(options = nil, &block)
|
49
|
+
native_options = options_to_native(options)
|
50
|
+
`return self["native"].forEach(function(item) { return block.$call(Opal.Hash.$new(item)); }, native_options)`
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_data_set
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
def map(options = nil, &block)
|
58
|
+
native_options = options_to_native(options)
|
59
|
+
`return self["native"].map(function(item) { return #{block.call(`Opal.Hash.$new(item)`)}; }, native_options)`
|
60
|
+
end
|
61
|
+
|
62
|
+
def max(field)
|
63
|
+
res = @native.JS.max(field)
|
64
|
+
`res !== null ? Opal.Hash.$new(res) : #{nil}`
|
65
|
+
end
|
66
|
+
|
67
|
+
def min(field)
|
68
|
+
res = @native.JS.min(field)
|
69
|
+
`res !== null ? Opal.Hash.$new(res) : #{nil}`
|
70
|
+
end
|
71
|
+
|
72
|
+
def remove(*args)
|
73
|
+
if `Opal.is_a(args[0], Opal.Array)`
|
74
|
+
args[0] = hash_array_to_native(args[0])
|
75
|
+
elsif `Opal.is_a(args[0], Opal.Hash)`
|
76
|
+
args[0] = args[0].to_n
|
77
|
+
end
|
78
|
+
`self["native"].remove.apply(self["native"], Opal.to_a(args))`
|
79
|
+
end
|
80
|
+
|
81
|
+
def update(*args)
|
82
|
+
if args[0] && `Opal.is_a(args[0], Opal.Hash)`
|
83
|
+
args[0] = args[0].to_n
|
84
|
+
elsif args[0] && `Opal.is_a(args[0], Opal.Array)`
|
85
|
+
args[0] = hash_array_to_native(args[0])
|
86
|
+
end
|
87
|
+
`self["native"].update.apply(self["native"], Opal.to_a(args))`
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Vis
|
2
|
+
class DataView
|
3
|
+
include Native
|
4
|
+
include Vis::Utilities
|
5
|
+
include Vis::EventSupport
|
6
|
+
include Vis::DataCommon
|
7
|
+
|
8
|
+
aliases_native %i[refresh length]
|
9
|
+
alias :size :length
|
10
|
+
|
11
|
+
attr_reader :event_handlers
|
12
|
+
|
13
|
+
def initialize(data_set_or_view, options = {})
|
14
|
+
native_options = options_to_native(options)
|
15
|
+
@data_set_or_view = data_set_or_view
|
16
|
+
@event_handlers = {}
|
17
|
+
@native = `new vis.DataView(data_set_or_view.$to_n(), native_options)`
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_data_set
|
21
|
+
@data_set_or_view
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_data(data_set_or_view)
|
25
|
+
@data_set_or_view = data_set_or_view
|
26
|
+
@native.JS.setData(data_set_or_view.to_n)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Vis
|
2
|
+
module EventSupport
|
3
|
+
def off(event, event_handler_id)
|
4
|
+
event = lower_camelize(event)
|
5
|
+
handler = @event_handlers[event][event_handler_id]
|
6
|
+
`self["native"].off(event, handler)`
|
7
|
+
@event_handlers[event].delete(event_handler_id)
|
8
|
+
end
|
9
|
+
|
10
|
+
def on(event, &block)
|
11
|
+
event = lower_camelize(event)
|
12
|
+
@event_handlers[event] = {} unless @event_handlers[event]
|
13
|
+
event_handler_id = `Math.random().toString(36).substring(6)`
|
14
|
+
handler = %x{
|
15
|
+
function(event_str, properties, sender_id) {
|
16
|
+
#{block.call(`event_str`, `Opal.Hash.$new(properties)`, `sender_id`)};
|
17
|
+
}
|
18
|
+
}
|
19
|
+
@event_handlers[event][event_handler_id] = handler
|
20
|
+
`self["native"].on(event, handler);`
|
21
|
+
event_handler_id
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/vis/native.rb
ADDED
data/lib/vis/network.rb
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
module Vis
|
2
|
+
class Network
|
3
|
+
include Native
|
4
|
+
include Vis::Utilities
|
5
|
+
|
6
|
+
aliases_native %i[
|
7
|
+
addEdgeMode
|
8
|
+
addNodeMode
|
9
|
+
deleteSelected
|
10
|
+
destroy
|
11
|
+
editEdgeMode
|
12
|
+
editNode
|
13
|
+
enableEditMode
|
14
|
+
disableEditMode
|
15
|
+
findNode
|
16
|
+
getBaseEdges
|
17
|
+
getClusteredEdges
|
18
|
+
getConnectedEdges
|
19
|
+
getConnectedNodes
|
20
|
+
getNodesInCluster
|
21
|
+
getScale
|
22
|
+
getSeed
|
23
|
+
getSelectedEdges
|
24
|
+
getSelectedNodes
|
25
|
+
isCluster
|
26
|
+
moveNode
|
27
|
+
redraw
|
28
|
+
releaseNode
|
29
|
+
selectEdges
|
30
|
+
selectNodes
|
31
|
+
stabilize
|
32
|
+
startSimulation
|
33
|
+
stopSimulation
|
34
|
+
storePositions
|
35
|
+
unselectAll
|
36
|
+
]
|
37
|
+
|
38
|
+
def initialize(native_container, dataset_hash, options = {})
|
39
|
+
native_options = options_to_native(options)
|
40
|
+
nodes_dataset = dataset_hash[:nodes].to_n
|
41
|
+
edges_dataset = dataset_hash[:edges].to_n
|
42
|
+
native_data = `{ nodes: nodes_dataset, edges: edges_dataset }`
|
43
|
+
@event_handlers = {}
|
44
|
+
@native = `new vis.Network(native_container, native_data, native_options)`
|
45
|
+
end
|
46
|
+
|
47
|
+
# global methods
|
48
|
+
|
49
|
+
def off(event, event_handler_id)
|
50
|
+
event = lower_camelize(event)
|
51
|
+
handler = @event_handlers[event][event_handler_id]
|
52
|
+
`self["native"].off(event, handler)`
|
53
|
+
@event_handlers[event].delete(event_handler_id)
|
54
|
+
end
|
55
|
+
|
56
|
+
def on(event, &block)
|
57
|
+
event = lower_camelize(event)
|
58
|
+
@event_handlers[event] = {} unless @event_handlers[event]
|
59
|
+
event_handler_id = `Math.random().toString(36).substring(6)`
|
60
|
+
handler = %x{
|
61
|
+
function(event_info) {
|
62
|
+
#{block.call(`Opal.Hash.$new(event_info)`)};
|
63
|
+
}
|
64
|
+
}
|
65
|
+
@event_handlers[event][event_handler_id] = handler
|
66
|
+
`self["native"].on(event, handler);`
|
67
|
+
event_handler_id
|
68
|
+
end
|
69
|
+
|
70
|
+
def once(event, &block)
|
71
|
+
handler = %x{
|
72
|
+
function(event_info) {
|
73
|
+
#{block.call(`Opal.Hash.$new(event_info)`)};
|
74
|
+
}
|
75
|
+
}
|
76
|
+
`self["native"].once(event, handler);`
|
77
|
+
end
|
78
|
+
|
79
|
+
def set_data(dataset_hash)
|
80
|
+
nodes_dataset = dataset_hash[:nodes].to_n
|
81
|
+
edges_dataset = dataset_hash[:edges].to_n
|
82
|
+
native_data = `{ nodes: nodes_dataset, edges: edges_dataset }`
|
83
|
+
@native.JS.setData(native_data)
|
84
|
+
end
|
85
|
+
|
86
|
+
def set_options(options)
|
87
|
+
native_options = options_to_native(options)
|
88
|
+
@native.JS.setOptions(native_options)
|
89
|
+
end
|
90
|
+
|
91
|
+
# canvas methods
|
92
|
+
|
93
|
+
def canvas_to_dom(xy_hash)
|
94
|
+
res = @native.JS.canvasToDOM(xy_hash.to_n)
|
95
|
+
`Opal.Hash.$new(res)`
|
96
|
+
end
|
97
|
+
|
98
|
+
def dom_to_canvas(xy_hash)
|
99
|
+
res = @native.JS.DOMtoCanvas(xy_hash.to_n)
|
100
|
+
`Opal.Hash.$new(res)`
|
101
|
+
end
|
102
|
+
|
103
|
+
def set_size(width, height)
|
104
|
+
width = width.to_s
|
105
|
+
height = height.to_s
|
106
|
+
@native.JS.setSize(width, height)
|
107
|
+
end
|
108
|
+
|
109
|
+
# clustering
|
110
|
+
|
111
|
+
def cluster(options)
|
112
|
+
@native.JS.cluster(options_to_native(options))
|
113
|
+
end
|
114
|
+
|
115
|
+
def cluster_by_connection(node_id, options)
|
116
|
+
@native.JS.clusterByConnection(node_id, options_to_native(options))
|
117
|
+
end
|
118
|
+
|
119
|
+
def cluster_by_hubsize(hub_size, options)
|
120
|
+
@native.JS.clusterByHubsize(hub_size, options_to_native(options))
|
121
|
+
end
|
122
|
+
|
123
|
+
def cluster_outliers(options)
|
124
|
+
@native.JS.clusterOutliers(options_to_native(options))
|
125
|
+
end
|
126
|
+
|
127
|
+
def open_cluster(node_id, options)
|
128
|
+
@native.JS.openCluster(node_id, options_to_native(options))
|
129
|
+
end
|
130
|
+
|
131
|
+
def update_edge(start_edge_id, options)
|
132
|
+
@native.JS.updateEdge(start_edge_id, options_to_native(options))
|
133
|
+
end
|
134
|
+
|
135
|
+
def update_clustered_node(clustered_node_id, options)
|
136
|
+
@native.JS.updateClusteredNode(start_edge_id, options_to_native(options))
|
137
|
+
end
|
138
|
+
|
139
|
+
# information
|
140
|
+
|
141
|
+
def get_bounding_box(node_id)
|
142
|
+
res = @native.JS.getBoundingBox(node_id)
|
143
|
+
`Opal.Hash.$new(res)`
|
144
|
+
end
|
145
|
+
|
146
|
+
def get_positions(array_of_node_ids)
|
147
|
+
res = @native.JS.getPositions(array_of_node_ids)
|
148
|
+
`Opal.Hash.$new(res)`
|
149
|
+
end
|
150
|
+
|
151
|
+
# selection
|
152
|
+
|
153
|
+
def get_edge_at(dom_xy_hash)
|
154
|
+
@native.JS.getEdgeAt(xy_hash.to_n)
|
155
|
+
end
|
156
|
+
|
157
|
+
def get_node_at(dom_xy_hash)
|
158
|
+
@native.JS.getNodeAt(xy_hash.to_n)
|
159
|
+
end
|
160
|
+
|
161
|
+
def get_selection
|
162
|
+
res = @native.JS.getSelection
|
163
|
+
`Opal.Hash.$new(res)`
|
164
|
+
end
|
165
|
+
|
166
|
+
def set_selection(selection_hash, options)
|
167
|
+
@native.JS.setSelection(selection_hash.to_n, options_to_native(options))
|
168
|
+
end
|
169
|
+
|
170
|
+
# viewport
|
171
|
+
|
172
|
+
def fit(options)
|
173
|
+
@native.JS.fit(options_to_native(options))
|
174
|
+
end
|
175
|
+
|
176
|
+
def focus(node_id, options)
|
177
|
+
@native.JS.focus(node_id, options_to_native(options))
|
178
|
+
end
|
179
|
+
|
180
|
+
def get_view_position
|
181
|
+
res = @native.JS.getViewPosition
|
182
|
+
`Opal.Hash.$new(res)`
|
183
|
+
end
|
184
|
+
|
185
|
+
def move_to(options)
|
186
|
+
@native.JS.moveTo(options_to_native(options))
|
187
|
+
end
|
188
|
+
|
189
|
+
# configurator module
|
190
|
+
def get_options_from_configurator
|
191
|
+
res = @native.JS.getOptionsFromConfigurator
|
192
|
+
`Opal.Hash.$new(res)`
|
193
|
+
end
|
194
|
+
|
195
|
+
# importing data
|
196
|
+
def self.convert_gephi(gephi_json, options)
|
197
|
+
native_options = options_to_native(options)
|
198
|
+
res = `vis.network.convertGephi(gephi_json, native_options)`
|
199
|
+
`Opal.Hash.$new(res)`
|
200
|
+
end
|
201
|
+
|
202
|
+
def self.convert_dot(dot_string)
|
203
|
+
res = `vis.network.convertDot(dot_string)`
|
204
|
+
`Opal.Hash.$new(res)`
|
205
|
+
end
|
206
|
+
|
207
|
+
# test helper
|
208
|
+
def self.test_container
|
209
|
+
`document.body.appendChild(document.createElement('div'))`
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|