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
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
require File.expand_path('../../config/environment', __FILE__)
|
3
|
+
require 'rails/test_help'
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
7
|
+
fixtures :all
|
8
|
+
|
9
|
+
# Add more helper methods to be used by all tests here...
|
10
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Hyperloop::Vis::Component', js: true do
|
4
|
+
|
5
|
+
it 'creates a component by using the mixin and renders it' do
|
6
|
+
mount 'OuterComponent' do
|
7
|
+
class VisComponent
|
8
|
+
include Hyperloop::Vis::Mixin
|
9
|
+
|
10
|
+
render_with_dom_node do |dom_node, data|
|
11
|
+
net = Vis::Network.new(dom_node, data)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
class OuterComponent < Hyperloop::Component
|
15
|
+
render do
|
16
|
+
data = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
17
|
+
DIV { VisComponent(data: data)}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
expect(page.body).to include('<canvas')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'creates a component by inheriting and renders it' do
|
25
|
+
mount 'OuterComponent' do
|
26
|
+
class VisComponent < Hyperloop::Vis::Component
|
27
|
+
render_with_dom_node do |dom_node, data|
|
28
|
+
net = Vis::Network.new(dom_node, data)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
class OuterComponent < Hyperloop::Component
|
32
|
+
render do
|
33
|
+
data = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
34
|
+
DIV { VisComponent(data: data)}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
expect(page.body).to include('<canvas')
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Vis::DataSet', js: true do
|
4
|
+
it 'creates a empty DataSet' do
|
5
|
+
expect_evaluate_ruby do
|
6
|
+
dataset = Vis::DataSet.new
|
7
|
+
[dataset.is_a?(Vis::DataSet), dataset.size]
|
8
|
+
end.to eq([true, 0])
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'creates a DataSet with predefined data' do
|
12
|
+
expect_evaluate_ruby do
|
13
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}])
|
14
|
+
[dataset.is_a?(Vis::DataSet), dataset.size]
|
15
|
+
end.to eq([true, 2])
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'createa a DataSet with options' do
|
19
|
+
expect_evaluate_ruby do
|
20
|
+
dataset = Vis::DataSet.new(field_id: 'foo')
|
21
|
+
[dataset.is_a?(Vis::DataSet), dataset.size]
|
22
|
+
end.to eq([true, 0])
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'createa a DataSet with predefined data and options' do
|
26
|
+
expect_evaluate_ruby do
|
27
|
+
dataset = Vis::DataSet.new([{foo: 1, name: 'foo'}, {foo: 2, name: 'bar'}], field_id: 'foo')
|
28
|
+
[dataset.is_a?(Vis::DataSet), dataset.size]
|
29
|
+
end.to eq([true, 2])
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'can add data to a DataSet' do
|
33
|
+
expect_evaluate_ruby do
|
34
|
+
dataset = Vis::DataSet.new
|
35
|
+
dataset.add({id: 1, name: 'foo'})
|
36
|
+
[dataset.is_a?(Vis::DataSet), dataset.size]
|
37
|
+
end.to eq([true, 1])
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'can add a array of data to a DataSet' do
|
41
|
+
expect_evaluate_ruby do
|
42
|
+
dataset = Vis::DataSet.new
|
43
|
+
dataset.add([{foo: 1, name: 'foo'}, {foo: 2, name: 'bar'}])
|
44
|
+
[dataset.is_a?(Vis::DataSet), dataset.size]
|
45
|
+
end.to eq([true, 2])
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'can iterate through a DataSet' do
|
49
|
+
expect_evaluate_ruby do
|
50
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}])
|
51
|
+
iterations = 0
|
52
|
+
dataset.each { iterations += 1 }
|
53
|
+
[dataset.is_a?(Vis::DataSet), dataset.size, iterations]
|
54
|
+
end.to eq([true, 2, 2])
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'can get data by id from a DataSet' do
|
58
|
+
expect_evaluate_ruby do
|
59
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}])
|
60
|
+
data = dataset.get(2)
|
61
|
+
[dataset.is_a?(Vis::DataSet), dataset.size, data[:name]]
|
62
|
+
end.to eq([true, 2, 'bar'])
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'can get an array of data by ids from a DataSet' do
|
66
|
+
expect_evaluate_ruby do
|
67
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}])
|
68
|
+
data = dataset.get([1, 2])
|
69
|
+
[dataset.is_a?(Vis::DataSet), dataset.size, data.size, data[0][:name], data[1][:name]]
|
70
|
+
end.to eq([true, 2, 2, 'foo', 'bar'])
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'can get a filtered array of data by ids from a DataSet' do
|
74
|
+
expect_evaluate_ruby do
|
75
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}])
|
76
|
+
data = dataset.get([1, 2], filter: proc { |item| item[:name] == 'foo' })
|
77
|
+
[dataset.is_a?(Vis::DataSet), dataset.size, data.size, data[0][:name]]
|
78
|
+
end.to eq([true, 2, 1, 'foo'])
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'can get data by id with [] from a DataSet' do
|
82
|
+
expect_evaluate_ruby do
|
83
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}])
|
84
|
+
data = dataset[2]
|
85
|
+
[dataset.is_a?(Vis::DataSet), dataset.size, data[:name]]
|
86
|
+
end.to eq([true, 2, 'bar'])
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'can get all ids from a DataSet' do
|
90
|
+
expect_evaluate_ruby do
|
91
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}])
|
92
|
+
data = dataset.get_ids
|
93
|
+
[dataset.is_a?(Vis::DataSet), dataset.size, [1, 2]]
|
94
|
+
end.to eq([true, 2, [1, 2]])
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'can map a DataSet' do
|
98
|
+
expect_evaluate_ruby do
|
99
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}])
|
100
|
+
data = dataset.map { |i| i[:name] }
|
101
|
+
[dataset.is_a?(Vis::DataSet), dataset.size, data]
|
102
|
+
end.to eq([true, 2, ['foo', 'bar']])
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'can get the item with max value of a field of a DataSet' do
|
106
|
+
expect_evaluate_ruby do
|
107
|
+
dataset = Vis::DataSet.new([{id: 1, height: 50}, {id: 2, height: 100}])
|
108
|
+
data = dataset.max(:height)
|
109
|
+
[dataset.is_a?(Vis::DataSet), dataset.size, data[:height]]
|
110
|
+
end.to eq([true, 2, 100])
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'can get the item with min value of a field of a DataSet' do
|
114
|
+
expect_evaluate_ruby do
|
115
|
+
dataset = Vis::DataSet.new([{id: 1, height: 50}, {id: 2, height: 100}])
|
116
|
+
data = dataset.min(:height)
|
117
|
+
[dataset.is_a?(Vis::DataSet), dataset.size, data[:height]]
|
118
|
+
end.to eq([true, 2, 50])
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'can register a on event handler for a DataSet' do
|
122
|
+
expect_evaluate_ruby do
|
123
|
+
dataset = Vis::DataSet.new([{id: 1, height: 50}, {id: 2, height: 100}])
|
124
|
+
items = []
|
125
|
+
dataset.on(:update) { |event, properties, sender_id| items << properties[:items] }
|
126
|
+
dataset.update({id: 2, height: 200})
|
127
|
+
items
|
128
|
+
end.to eq([[2]])
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'can register a on event handler for a DataSet and remove it again' do
|
132
|
+
expect_evaluate_ruby do
|
133
|
+
dataset = Vis::DataSet.new([{id: 1, height: 50}, {id: 2, height: 100}])
|
134
|
+
items = []
|
135
|
+
eh_id = dataset.on(:update) { |event, properties, sender_id| items << properties[:items] }
|
136
|
+
dataset.update({id: 2, height: 200})
|
137
|
+
dataset.off(:update, eh_id)
|
138
|
+
dataset.update({id: 1, height: 400})
|
139
|
+
items
|
140
|
+
end.to eq([[2]])
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'can remove a item by id from a DataSet' do
|
144
|
+
expect_evaluate_ruby do
|
145
|
+
dataset = Vis::DataSet.new([{id: 1, height: 50}, {id: 2, height: 100}])
|
146
|
+
data = dataset.remove(1)
|
147
|
+
[dataset.is_a?(Vis::DataSet), dataset.size, data]
|
148
|
+
end.to eq([true, 1, [1]])
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'can remove multiple items by ids from a DataSet' do
|
152
|
+
expect_evaluate_ruby do
|
153
|
+
dataset = Vis::DataSet.new([{id: 1, height: 50}, {id: 2, height: 100}])
|
154
|
+
data = dataset.remove([1,2])
|
155
|
+
[dataset.is_a?(Vis::DataSet), dataset.size, data]
|
156
|
+
end.to eq([true, 0, [1, 2]])
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'can remove a item by itself from a DataSet' do
|
160
|
+
expect_evaluate_ruby do
|
161
|
+
dataset = Vis::DataSet.new([{id: 1, height: 50}, {id: 2, height: 100}])
|
162
|
+
data = dataset.remove({id: 2, height: 100})
|
163
|
+
[dataset.is_a?(Vis::DataSet), dataset.size, data]
|
164
|
+
end.to eq([true, 1, [2]])
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'can update a item from a DataSet' do
|
168
|
+
expect_evaluate_ruby do
|
169
|
+
dataset = Vis::DataSet.new([{id: 1, height: 50}, {id: 2, height: 100}])
|
170
|
+
data = dataset.update({id: 2, height: 200})
|
171
|
+
height = dataset[2][:height]
|
172
|
+
[dataset.is_a?(Vis::DataSet), dataset.size, data, height]
|
173
|
+
end.to eq([true, 2, [2], 200])
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'can update multiple itema from a DataSet' do
|
177
|
+
expect_evaluate_ruby do
|
178
|
+
dataset = Vis::DataSet.new([{id: 1, height: 50}, {id: 2, height: 100}])
|
179
|
+
data = dataset.update([{id: 1, height: 75}, {id: 2, height: 200}])
|
180
|
+
heights = [dataset[1][:height], dataset[2][:height]]
|
181
|
+
[dataset.is_a?(Vis::DataSet), dataset.size, data, heights]
|
182
|
+
end.to eq([true, 2, [1, 2], [75, 200]])
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Vis::DataView', js: true do
|
4
|
+
it 'creates a DataView with a DataSet' do
|
5
|
+
expect_evaluate_ruby do
|
6
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
7
|
+
dataview = Vis::DataView.new(dataset)
|
8
|
+
[dataview.is_a?(Vis::DataView), dataview.size]
|
9
|
+
end.to eq([true, 3])
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'creates a filtered DataView with a DataSet' do
|
13
|
+
expect_evaluate_ruby do
|
14
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
15
|
+
dataview = Vis::DataView.new(dataset, filter: proc { |item| ['bar', 'pub'].include?(item[:name]) })
|
16
|
+
[dataview.is_a?(Vis::DataView), dataview.size]
|
17
|
+
end.to eq([true, 2])
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'it can get a item by id from a DataView' do
|
21
|
+
expect_evaluate_ruby do
|
22
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
23
|
+
dataview = Vis::DataView.new(dataset, filter: proc { |item| ['bar', 'pub'].include?(item[:name]) })
|
24
|
+
item = dataview.get(2)
|
25
|
+
[dataview.is_a?(Vis::DataView), dataview.size, item[:name]]
|
26
|
+
end.to eq([true, 2, 'bar'])
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'it cannot get a filtered item by id from a DataView' do
|
30
|
+
expect_evaluate_ruby do
|
31
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
32
|
+
dataview = Vis::DataView.new(dataset, filter: proc { |item| ['bar', 'pub'].include?(item[:name]) })
|
33
|
+
item = dataview.get(1)
|
34
|
+
[dataview.is_a?(Vis::DataView), dataview.size, item]
|
35
|
+
end.to eq([true, 2, nil])
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'it gets a filtered array of items by id from a DataView' do
|
39
|
+
expect_evaluate_ruby do
|
40
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
41
|
+
dataview = Vis::DataView.new(dataset, filter: proc { |item| ['bar', 'pub'].include?(item[:name]) })
|
42
|
+
items = dataview.get([1,2,3])
|
43
|
+
[dataview.is_a?(Vis::DataView), dataview.size, items.size]
|
44
|
+
end.to eq([true, 2, 2])
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'it gets the DataSet from a DataView' do
|
48
|
+
expect_evaluate_ruby do
|
49
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
50
|
+
dataview = Vis::DataView.new(dataset, filter: proc { |item| ['bar', 'pub'].include?(item[:name]) })
|
51
|
+
set = dataview.get_data_set
|
52
|
+
[dataview.is_a?(Vis::DataView), dataview.size, set.is_a?(Vis::DataSet), set.size]
|
53
|
+
end.to eq([true, 2, true, 3])
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'it gets the filtered list of ids from a DataView' do
|
57
|
+
expect_evaluate_ruby do
|
58
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
59
|
+
dataview = Vis::DataView.new(dataset, filter: proc { |item| ['bar', 'pub'].include?(item[:name]) })
|
60
|
+
ids = dataview.get_ids
|
61
|
+
[dataview.is_a?(Vis::DataView), dataview.size, ids]
|
62
|
+
end.to eq([true, 2, [2, 3]])
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'can register a on event handler for a DataVet' do
|
66
|
+
expect_evaluate_ruby do
|
67
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
68
|
+
dataview = Vis::DataView.new(dataset, filter: proc { |item| ['bar', 'pub'].include?(item[:name]) })
|
69
|
+
items = []
|
70
|
+
dataview.on(:update) { |event, properties, sender_id| items << properties[:items] }
|
71
|
+
dataset.update({id: 2, name: 'pub'})
|
72
|
+
items
|
73
|
+
end.to eq([[2]])
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'can register a on event handler for a DataSet and remove it again' do
|
77
|
+
expect_evaluate_ruby do
|
78
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
79
|
+
dataview = Vis::DataView.new(dataset, filter: proc { |item| ['bar', 'pub'].include?(item[:name]) })
|
80
|
+
items = []
|
81
|
+
eh_id = dataview.on(:update) { |event, properties, sender_id| items << properties[:items] }
|
82
|
+
dataset.update({id: 2, name: 'pub'})
|
83
|
+
dataview.off(:update, eh_id)
|
84
|
+
dataset.update({id: 2, name: 'bar'})
|
85
|
+
items
|
86
|
+
end.to eq([[2]])
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'it can refresh a DataView' do
|
90
|
+
expect_evaluate_ruby do
|
91
|
+
array = ['bar', 'pub']
|
92
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
93
|
+
dataview = Vis::DataView.new(dataset, filter: proc { |item| array.include?(item[:name]) })
|
94
|
+
size_before = dataview.size
|
95
|
+
array = ['bar', 'pub', 'foo']
|
96
|
+
dataview.refresh
|
97
|
+
[dataview.is_a?(Vis::DataView), size_before, dataview.size]
|
98
|
+
end.to eq([true, 2, 3])
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'it can set a new DataSaet for the DataView' do
|
102
|
+
expect_evaluate_ruby do
|
103
|
+
array = ['bar', 'pub']
|
104
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
105
|
+
dataview = Vis::DataView.new(dataset, filter: proc { |item| array.include?(item[:name]) })
|
106
|
+
size_before = dataview.size
|
107
|
+
dataset2 = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}])
|
108
|
+
dataview.set_data(dataset2)
|
109
|
+
[dataview.is_a?(Vis::DataView), size_before, dataview.size]
|
110
|
+
end.to eq([true, 2, 1])
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,557 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Vis::Network', js: true do
|
4
|
+
|
5
|
+
it 'creates a new Network' do
|
6
|
+
expect_evaluate_ruby do
|
7
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
8
|
+
dom_node = Vis::Network.test_container
|
9
|
+
net = Vis::Network.new(dom_node, {nodes: dataset})
|
10
|
+
[net.is_a?(Vis::Network), dom_node.JS[:children].JS[:length]]
|
11
|
+
end.to eq([true, 1])
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'creates a new Network and destroys it' do
|
15
|
+
expect_evaluate_ruby do
|
16
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
17
|
+
dom_node = Vis::Network.test_container
|
18
|
+
net = Vis::Network.new(dom_node, {nodes: dataset})
|
19
|
+
created = dom_node.JS[:children].JS[:length]
|
20
|
+
net.destroy
|
21
|
+
[net.is_a?(Vis::Network), created, dom_node.JS[:children].JS[:length]]
|
22
|
+
end.to eq([true, 1, 0])
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'it can replace the data' do
|
26
|
+
expect_evaluate_ruby do
|
27
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
28
|
+
dom_node = Vis::Network.test_container
|
29
|
+
net = Vis::Network.new(dom_node, {nodes: dataset})
|
30
|
+
created = dom_node.JS[:children].JS[:length]
|
31
|
+
old_position = net.find_node(1)
|
32
|
+
new_dataset = Vis::DataSet.new([{id: 4, name: 'club'}, {id: 5, name: 'bar'}, {id: 6, name: 'pub'}])
|
33
|
+
net.set_data(nodes: new_dataset)
|
34
|
+
position = net.find_node(4)
|
35
|
+
invalid_position = net.find_node(1)
|
36
|
+
[net.is_a?(Vis::Network), created, old_position, position, invalid_position]
|
37
|
+
end.to eq([true, 1, [1], [4], []])
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'it can set options' do
|
41
|
+
expect_evaluate_ruby do
|
42
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
43
|
+
dom_node = Vis::Network.test_container
|
44
|
+
net = Vis::Network.new(dom_node, {nodes: dataset})
|
45
|
+
created = dom_node.JS[:children].JS[:length]
|
46
|
+
error = false
|
47
|
+
begin
|
48
|
+
net.set_options(autoresize: true)
|
49
|
+
rescue
|
50
|
+
error = true
|
51
|
+
end
|
52
|
+
[net.is_a?(Vis::Network), created, error]
|
53
|
+
end.to eq([true, 1, false])
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'it can set and remove a event listener' do
|
57
|
+
expect_evaluate_ruby do
|
58
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
59
|
+
dom_node = Vis::Network.test_container
|
60
|
+
net = Vis::Network.new(dom_node, {nodes: dataset})
|
61
|
+
created = dom_node.JS[:children].JS[:length]
|
62
|
+
received = []
|
63
|
+
handler_id = net.on(:resize) do |event_info|
|
64
|
+
received << event_info
|
65
|
+
end
|
66
|
+
net.set_size(100, 100)
|
67
|
+
net.off(:resize, handler_id)
|
68
|
+
net.set_size(200, 200)
|
69
|
+
[net.is_a?(Vis::Network), created, received.size]
|
70
|
+
end.to eq([true, 1, 1])
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'it can set a event listener thats called once' do
|
74
|
+
expect_evaluate_ruby do
|
75
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
76
|
+
dom_node = Vis::Network.test_container
|
77
|
+
net = Vis::Network.new(dom_node, {nodes: dataset})
|
78
|
+
created = dom_node.JS[:children].JS[:length]
|
79
|
+
received = []
|
80
|
+
handler_id = net.once(:resize) do |event_info|
|
81
|
+
received << event_info
|
82
|
+
end
|
83
|
+
net.set_size(100, 100)
|
84
|
+
net.set_size(200, 200)
|
85
|
+
[net.is_a?(Vis::Network), created, received.size]
|
86
|
+
end.to eq([true, 1, 1])
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'translates canvas coordinates to dom coordinatea' do
|
90
|
+
expect_evaluate_ruby do
|
91
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
92
|
+
dom_node = Vis::Network.test_container
|
93
|
+
net = Vis::Network.new(dom_node, {nodes: dataset})
|
94
|
+
created = dom_node.JS[:children].JS[:length]
|
95
|
+
xy = net.canvas_to_dom({x: 10, y: 10})
|
96
|
+
[net.is_a?(Vis::Network), created, xy[:x] > 10, xy[:y] > 10]
|
97
|
+
end.to eq([true, 1, true, true])
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'translates dom coordinates to canvas coordinates' do
|
101
|
+
expect_evaluate_ruby do
|
102
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
103
|
+
dom_node = Vis::Network.test_container
|
104
|
+
net = Vis::Network.new(dom_node, {nodes: dataset})
|
105
|
+
created = dom_node.JS[:children].JS[:length]
|
106
|
+
xy = net.dom_to_canvas({x: 10, y: 10})
|
107
|
+
[net.is_a?(Vis::Network), created, xy[:x] < 0, xy[:y] < 0]
|
108
|
+
end.to eq([true, 1, true, true])
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'can call redraw' do
|
112
|
+
expect_evaluate_ruby do
|
113
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
114
|
+
dom_node = Vis::Network.test_container
|
115
|
+
net = Vis::Network.new(dom_node, {nodes: dataset})
|
116
|
+
created = dom_node.JS[:children].JS[:length]
|
117
|
+
net.redraw
|
118
|
+
redrawn = dom_node.JS[:children].JS[:length]
|
119
|
+
[net.is_a?(Vis::Network), created, redrawn]
|
120
|
+
end.to eq([true, 1, 1])
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'set the size of the canvas' do
|
124
|
+
expect_evaluate_ruby do
|
125
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
126
|
+
dom_node = Vis::Network.test_container
|
127
|
+
net = Vis::Network.new(dom_node, {nodes: dataset})
|
128
|
+
created = dom_node.JS[:children].JS[:length]
|
129
|
+
before_canvas_width = dom_node.JS.querySelector('canvas').JS[:width]
|
130
|
+
before_canvas_height = dom_node.JS.querySelector('canvas').JS[:height]
|
131
|
+
net.set_size(50, 50)
|
132
|
+
after_canvas_width = dom_node.JS.querySelector('canvas').JS[:width]
|
133
|
+
after_canvas_height = dom_node.JS.querySelector('canvas').JS[:height]
|
134
|
+
# vis accounts for retina displays for example, so the actual size reported by
|
135
|
+
# by the dom canvas element is not what is set by set_size, thats why we do this:
|
136
|
+
[net.is_a?(Vis::Network), created, before_canvas_width > after_canvas_width, before_canvas_height > after_canvas_height]
|
137
|
+
end.to eq([true, 1, true, true])
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'creates a cluster and finds node in it' do
|
141
|
+
expect_evaluate_ruby do
|
142
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
143
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
144
|
+
dom_node = Vis::Network.test_container
|
145
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
146
|
+
created = dom_node.JS[:children].JS[:length]
|
147
|
+
net.cluster(join_condition: proc { |node_options| true })
|
148
|
+
node_pos = net.find_node(2)
|
149
|
+
[net.is_a?(Vis::Network), created, node_pos.first.start_with?('cluster:'), node_pos.last]
|
150
|
+
end.to eq([true, 1, true, 2])
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'creates a cluster by connection' do
|
154
|
+
expect_evaluate_ruby do
|
155
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
156
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
157
|
+
dom_node = Vis::Network.test_container
|
158
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
159
|
+
created = dom_node.JS[:children].JS[:length]
|
160
|
+
net.cluster_by_connection(2)
|
161
|
+
node_pos = net.find_node(2)
|
162
|
+
[net.is_a?(Vis::Network), created, node_pos.first.start_with?('cluster:'), node_pos.last]
|
163
|
+
end.to eq([true, 1, true, 2])
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'creates a cluster by hubsize' do
|
167
|
+
expect_evaluate_ruby do
|
168
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
169
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
170
|
+
dom_node = Vis::Network.test_container
|
171
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
172
|
+
created = dom_node.JS[:children].JS[:length]
|
173
|
+
net.cluster_by_hubsize(2)
|
174
|
+
node_pos = net.find_node(2)
|
175
|
+
[net.is_a?(Vis::Network), created, node_pos.first.start_with?('cluster:'), node_pos.last]
|
176
|
+
end.to eq([true, 1, true, 2])
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'clusters the outliers' do
|
180
|
+
expect_evaluate_ruby do
|
181
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
182
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
183
|
+
dom_node = Vis::Network.test_container
|
184
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
185
|
+
created = dom_node.JS[:children].JS[:length]
|
186
|
+
net.cluster_outliers
|
187
|
+
node_pos = net.find_node(1)
|
188
|
+
[net.is_a?(Vis::Network), created, node_pos.first.start_with?('cluster:'), node_pos.last]
|
189
|
+
end.to eq([true, 1, true, 1])
|
190
|
+
end
|
191
|
+
|
192
|
+
xit 'get clustered edges' do
|
193
|
+
expect_evaluate_ruby do
|
194
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
195
|
+
edge_dataset = Vis::DataSet.new([{id: 'one', from: 1, to: 2}, {id: 'two', from: 2, to: 3}])
|
196
|
+
dom_node = Vis::Network.test_container
|
197
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
198
|
+
created = dom_node.JS[:children].JS[:length]
|
199
|
+
net.cluster(join_condition: proc { |node_options| true })
|
200
|
+
edges = net.get_clustered_edges('one')
|
201
|
+
[net.is_a?(Vis::Network), created, edges]
|
202
|
+
end.to eq([true, 1, true])
|
203
|
+
end
|
204
|
+
|
205
|
+
xit 'getBaseEdges'
|
206
|
+
xit 'updateEdge'
|
207
|
+
xit 'updateClusteredNode'
|
208
|
+
|
209
|
+
it 'clusters is a cluster' do
|
210
|
+
expect_evaluate_ruby do
|
211
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
212
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
213
|
+
dom_node = Vis::Network.test_container
|
214
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
215
|
+
created = dom_node.JS[:children].JS[:length]
|
216
|
+
net.cluster_outliers
|
217
|
+
pos = net.find_node(1)
|
218
|
+
is_cluster = net.is_cluster(pos[0])
|
219
|
+
[net.is_a?(Vis::Network), created, is_cluster]
|
220
|
+
end.to eq([true, 1, true])
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'gets nodes in cluster' do
|
224
|
+
expect_evaluate_ruby do
|
225
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
226
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
227
|
+
dom_node = Vis::Network.test_container
|
228
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
229
|
+
created = dom_node.JS[:children].JS[:length]
|
230
|
+
net.cluster_outliers
|
231
|
+
pos = net.find_node(1)
|
232
|
+
nodes = net.get_nodes_in_cluster(pos[0])
|
233
|
+
[net.is_a?(Vis::Network), created, nodes]
|
234
|
+
end.to eq([true, 1, [1, 2, 3]])
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'opens the cluster' do
|
238
|
+
expect_evaluate_ruby do
|
239
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
240
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
241
|
+
dom_node = Vis::Network.test_container
|
242
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
243
|
+
created = dom_node.JS[:children].JS[:length]
|
244
|
+
net.cluster_outliers
|
245
|
+
pos = net.find_node(1)
|
246
|
+
before_is_cluster = net.is_cluster(pos[0])
|
247
|
+
net.open_cluster(pos[0])
|
248
|
+
after_is_cluster = net.is_cluster(pos[0])
|
249
|
+
[net.is_a?(Vis::Network), created, before_is_cluster, after_is_cluster]
|
250
|
+
end.to eq([true, 1, true, false])
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'can get the seed' do
|
254
|
+
expect_evaluate_ruby do
|
255
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
256
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
257
|
+
dom_node = Vis::Network.test_container
|
258
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
259
|
+
created = dom_node.JS[:children].JS[:length]
|
260
|
+
seed = net.get_seed
|
261
|
+
[net.is_a?(Vis::Network), created, seed.is_a?(Integer)]
|
262
|
+
end.to eq([true, 1, true])
|
263
|
+
end
|
264
|
+
|
265
|
+
# use callback method in options for the following
|
266
|
+
it 'it selects a node, enables edit mode, edits node, disables edit mode' do
|
267
|
+
expect_evaluate_ruby do
|
268
|
+
received_data = []
|
269
|
+
options = { manipulation: {
|
270
|
+
edit_node: proc { |node_data, callback| received_data << node_data }
|
271
|
+
}}
|
272
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
273
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
274
|
+
dom_node = Vis::Network.test_container
|
275
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset}, options)
|
276
|
+
created = dom_node.JS[:children].JS[:length]
|
277
|
+
net.enable_edit_mode
|
278
|
+
net.select_nodes([1])
|
279
|
+
net.edit_node
|
280
|
+
net.disable_edit_mode
|
281
|
+
[net.is_a?(Vis::Network), created, received_data.first[:name]]
|
282
|
+
end.to eq([true, 1, 'foo'])
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'can select nodes and delete them' do
|
286
|
+
expect_evaluate_ruby do
|
287
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
288
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
289
|
+
dom_node = Vis::Network.test_container
|
290
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
291
|
+
created = dom_node.JS[:children].JS[:length]
|
292
|
+
net.select_nodes([1])
|
293
|
+
net.delete_selected
|
294
|
+
res = dataset.get(1)
|
295
|
+
[net.is_a?(Vis::Network), created, res]
|
296
|
+
end.to eq([true, 1, nil])
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'can get the positions of nodes' do
|
300
|
+
expect_evaluate_ruby do
|
301
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
302
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
303
|
+
dom_node = Vis::Network.test_container
|
304
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
305
|
+
created = dom_node.JS[:children].JS[:length]
|
306
|
+
positions = net.get_positions(['1', '2'])
|
307
|
+
[net.is_a?(Vis::Network), created, positions.size, positions['1']['x'].is_a?(Integer)]
|
308
|
+
end.to eq([true, 1, 2, true])
|
309
|
+
end
|
310
|
+
|
311
|
+
it 'can store the positions of nodes' do
|
312
|
+
expect_evaluate_ruby do
|
313
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
314
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
315
|
+
dom_node = Vis::Network.test_container
|
316
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
317
|
+
created = dom_node.JS[:children].JS[:length]
|
318
|
+
net.store_positions
|
319
|
+
item = dataset.get(1)
|
320
|
+
[net.is_a?(Vis::Network), created, item.has_key?(:x), item[:x].is_a?(Integer)]
|
321
|
+
end.to eq([true, 1, true, true])
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'can move a node' do
|
325
|
+
expect_evaluate_ruby do
|
326
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
327
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
328
|
+
dom_node = Vis::Network.test_container
|
329
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
330
|
+
created = dom_node.JS[:children].JS[:length]
|
331
|
+
before_position = net.get_positions(['1'])
|
332
|
+
net.move_node('1', 10, 10)
|
333
|
+
after_position = net.get_positions(['1'])
|
334
|
+
[net.is_a?(Vis::Network), created,
|
335
|
+
before_position['1'][:x] != after_position['1'][:x],
|
336
|
+
before_position['1'][:y] != after_position['1'][:y],
|
337
|
+
after_position['1'][:x],
|
338
|
+
after_position['1'][:y]]
|
339
|
+
end.to eq([true, 1, true, true, 10, 10])
|
340
|
+
end
|
341
|
+
|
342
|
+
it 'gets the bounding box of a node' do
|
343
|
+
expect_evaluate_ruby do
|
344
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
345
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
346
|
+
dom_node = Vis::Network.test_container
|
347
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
348
|
+
created = dom_node.JS[:children].JS[:length]
|
349
|
+
bounding_box = net.get_bounding_box(['1'])
|
350
|
+
[net.is_a?(Vis::Network), created,
|
351
|
+
bounding_box[:top].is_a?(Integer),
|
352
|
+
bounding_box[:left].is_a?(Integer),
|
353
|
+
bounding_box[:right].is_a?(Integer),
|
354
|
+
bounding_box[:bottom].is_a?(Integer)]
|
355
|
+
end.to eq([true, 1, true, true, true, true])
|
356
|
+
end
|
357
|
+
|
358
|
+
it 'it can get connected nodes' do
|
359
|
+
expect_evaluate_ruby do
|
360
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
361
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
362
|
+
dom_node = Vis::Network.test_container
|
363
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
364
|
+
created = dom_node.JS[:children].JS[:length]
|
365
|
+
connected_nodes = net.get_connected_nodes(1)
|
366
|
+
[net.is_a?(Vis::Network), created, connected_nodes]
|
367
|
+
end.to eq([true, 1, [2]])
|
368
|
+
end
|
369
|
+
|
370
|
+
it 'it can get connected edges' do
|
371
|
+
expect_evaluate_ruby do
|
372
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
373
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
374
|
+
dom_node = Vis::Network.test_container
|
375
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
376
|
+
created = dom_node.JS[:children].JS[:length]
|
377
|
+
connected_edges = net.get_connected_edges(1)
|
378
|
+
[net.is_a?(Vis::Network), created, connected_edges.first.is_a?(String)]
|
379
|
+
end.to eq([true, 1, true])
|
380
|
+
end
|
381
|
+
|
382
|
+
it 'can call physics methods' do
|
383
|
+
# just checking if we can call them, not testing functionality
|
384
|
+
expect_evaluate_ruby do
|
385
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
386
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
387
|
+
dom_node = Vis::Network.test_container
|
388
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
389
|
+
created = dom_node.JS[:children].JS[:length]
|
390
|
+
error = false
|
391
|
+
begin
|
392
|
+
net.start_simulation
|
393
|
+
net.stop_simulation
|
394
|
+
net.stabilize
|
395
|
+
rescue
|
396
|
+
error = true
|
397
|
+
end
|
398
|
+
[net.is_a?(Vis::Network), created, error]
|
399
|
+
end.to eq([true, 1, false])
|
400
|
+
end
|
401
|
+
|
402
|
+
it 'can make a selection and get the selection' do
|
403
|
+
expect_evaluate_ruby do
|
404
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
405
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
406
|
+
dom_node = Vis::Network.test_container
|
407
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
408
|
+
created = dom_node.JS[:children].JS[:length]
|
409
|
+
edges = net.get_connected_edges(1)
|
410
|
+
net.set_selection(nodes: [1], edges: edges)
|
411
|
+
selection = net.get_selection
|
412
|
+
[net.is_a?(Vis::Network), created,
|
413
|
+
selection.has_key?(:nodes),
|
414
|
+
selection.has_key?(:edges),
|
415
|
+
selection[:nodes],
|
416
|
+
selection[:edges] == edges]
|
417
|
+
end.to eq([true, 1, true, true, [1], true])
|
418
|
+
end
|
419
|
+
|
420
|
+
it 'can select nodes and get the selection' do
|
421
|
+
expect_evaluate_ruby do
|
422
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
423
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
424
|
+
dom_node = Vis::Network.test_container
|
425
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
426
|
+
created = dom_node.JS[:children].JS[:length]
|
427
|
+
net.select_nodes([1, 3])
|
428
|
+
selection = net.get_selected_nodes
|
429
|
+
[net.is_a?(Vis::Network), created, selection]
|
430
|
+
end.to eq([true, 1, [1, 3]])
|
431
|
+
end
|
432
|
+
|
433
|
+
it 'can select edges and get the selection' do
|
434
|
+
expect_evaluate_ruby do
|
435
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
436
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
437
|
+
dom_node = Vis::Network.test_container
|
438
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
439
|
+
created = dom_node.JS[:children].JS[:length]
|
440
|
+
edges = net.get_connected_edges(1)
|
441
|
+
net.select_edges(edges)
|
442
|
+
selection = net.get_selected_edges
|
443
|
+
[net.is_a?(Vis::Network), created, selection == edges]
|
444
|
+
end.to eq([true, 1, true])
|
445
|
+
end
|
446
|
+
|
447
|
+
it 'can unselect all of a selection' do
|
448
|
+
expect_evaluate_ruby do
|
449
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
450
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
451
|
+
dom_node = Vis::Network.test_container
|
452
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
453
|
+
created = dom_node.JS[:children].JS[:length]
|
454
|
+
edges = net.get_connected_edges(1)
|
455
|
+
net.set_selection(nodes: [1], edges: edges)
|
456
|
+
selection = net.get_selection
|
457
|
+
net.unselect_all
|
458
|
+
after_selection = net.get_selection
|
459
|
+
[net.is_a?(Vis::Network), created,
|
460
|
+
selection[:nodes],
|
461
|
+
selection[:edges] == edges,
|
462
|
+
after_selection[:nodes],
|
463
|
+
after_selection[:edges]]
|
464
|
+
end.to eq([true, 1, [1], true, [], []])
|
465
|
+
end
|
466
|
+
|
467
|
+
it 'gets the scale of the current viewport' do
|
468
|
+
expect_evaluate_ruby do
|
469
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
470
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
471
|
+
dom_node = Vis::Network.test_container
|
472
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
473
|
+
created = dom_node.JS[:children].JS[:length]
|
474
|
+
scale = net.get_scale
|
475
|
+
[net.is_a?(Vis::Network), created, scale]
|
476
|
+
end.to eq([true, 1, 1.0])
|
477
|
+
end
|
478
|
+
|
479
|
+
it 'gets the view position' do
|
480
|
+
expect_evaluate_ruby do
|
481
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
482
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
483
|
+
dom_node = Vis::Network.test_container
|
484
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
485
|
+
created = dom_node.JS[:children].JS[:length]
|
486
|
+
position = net.get_view_position
|
487
|
+
[net.is_a?(Vis::Network), created,
|
488
|
+
position[:x].is_a?(Integer),
|
489
|
+
position[:y].is_a?(Integer)]
|
490
|
+
end.to eq([true, 1, true, true])
|
491
|
+
end
|
492
|
+
|
493
|
+
it 'can call fit' do
|
494
|
+
# not sure of a way to check, so we just call and make sure no exceptions is thrown
|
495
|
+
expect_evaluate_ruby do
|
496
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
497
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
498
|
+
dom_node = Vis::Network.test_container
|
499
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
500
|
+
created = dom_node.JS[:children].JS[:length]
|
501
|
+
has_error = false
|
502
|
+
begin
|
503
|
+
net.fit
|
504
|
+
rescue
|
505
|
+
has_error = true
|
506
|
+
end
|
507
|
+
[net.is_a?(Vis::Network), created, has_error]
|
508
|
+
end.to eq([true, 1, false])
|
509
|
+
end
|
510
|
+
|
511
|
+
it 'can focus on a node and releae it' do
|
512
|
+
# no way to check if a node is focused?
|
513
|
+
expect_evaluate_ruby do
|
514
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
515
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
516
|
+
dom_node = Vis::Network.test_container
|
517
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
518
|
+
created = dom_node.JS[:children].JS[:length]
|
519
|
+
has_error = false
|
520
|
+
begin
|
521
|
+
net.focus('3')
|
522
|
+
net.release_node
|
523
|
+
rescue
|
524
|
+
has_error = true
|
525
|
+
end
|
526
|
+
[net.is_a?(Vis::Network), created, has_error]
|
527
|
+
end.to eq([true, 1, false])
|
528
|
+
end
|
529
|
+
|
530
|
+
it 'can move the viewport' do
|
531
|
+
# no way to check if a node is focused?
|
532
|
+
expect_evaluate_ruby do
|
533
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
534
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
535
|
+
dom_node = Vis::Network.test_container
|
536
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
537
|
+
created = dom_node.JS[:children].JS[:length]
|
538
|
+
old_position = net.get_view_position
|
539
|
+
net.move_to({position: {x: 50, y: 50}})
|
540
|
+
new_position = net.get_view_position
|
541
|
+
[net.is_a?(Vis::Network), created, old_position != new_position, new_position['x'], new_position['y']]
|
542
|
+
end.to eq([true, 1, true, 50, 50])
|
543
|
+
end
|
544
|
+
|
545
|
+
it 'can get the options from a configurator' do
|
546
|
+
# no way to check if a node is focused?
|
547
|
+
expect_evaluate_ruby do
|
548
|
+
dataset = Vis::DataSet.new([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'pub'}])
|
549
|
+
edge_dataset = Vis::DataSet.new([{from: 1, to: 2}, {from: 2, to: 3}])
|
550
|
+
dom_node = Vis::Network.test_container
|
551
|
+
net = Vis::Network.new(dom_node, {nodes: dataset, edges: edge_dataset})
|
552
|
+
created = dom_node.JS[:children].JS[:length]
|
553
|
+
options = net.get_options_from_configurator
|
554
|
+
[net.is_a?(Vis::Network), created, options.is_a?(Hash)]
|
555
|
+
end.to eq([true, 1, true])
|
556
|
+
end
|
557
|
+
end
|