File tree Expand file tree Collapse file tree 1 file changed +39
-12
lines changed Expand file tree Collapse file tree 1 file changed +39
-12
lines changed Original file line number Diff line number Diff line change 21
21
edges : edges
22
22
} ;
23
23
var options = {
24
- physics : {
25
- enabled : true ,
26
- solver : 'repulsion'
27
- } ,
28
24
edges : {
29
25
smooth : false // Make edges straight lines.
30
26
} ,
33
29
shape : 'box' // The shape of the nodes.
34
30
}
35
31
} ;
32
+ setRandomLayout ( ) ;
36
33
var container = document . getElementById ( 'network' ) ;
37
34
var network = new vis . Network ( container , data , options ) ;
38
35
var seed = network . getSeed ( ) ;
249
246
console . log ( 'Not implemented yet...' ) ;
250
247
}
251
248
249
+ function setRandomLayout ( ) {
250
+ options . layout = {
251
+ hierarchical : {
252
+ enabled : false
253
+ }
254
+ } ;
255
+ options . physics = {
256
+ enabled : true ,
257
+ barnesHut : {
258
+ springConstant : 0 ,
259
+ avoidOverlap : 0.8
260
+ }
261
+ } ;
262
+ }
263
+
264
+ function setHierarchicalLayout ( direction , sortMethod ) {
265
+ options . layout = {
266
+ hierarchical : {
267
+ enabled : true ,
268
+ levelSeparation : 200 ,
269
+ nodeSpacing : 200 ,
270
+ direction : direction ,
271
+ sortMethod : sortMethod
272
+ }
273
+ } ;
274
+ options . physics = {
275
+ enabled : true ,
276
+ hierarchicalRepulsion : {
277
+ springConstant : 0 ,
278
+ avoidOverlap : 0.2
279
+ }
280
+ } ;
281
+ }
282
+
252
283
function setNetworkLayout ( ) {
253
284
const hierarchicalOptionsDirection = document . getElementById ( 'hierarchicalOptions_direction' ) ;
254
285
const hierarchicalOptionsSortMethod = document . getElementById ( 'hierarchicalOptions_sortmethod' ) ;
259
290
const hierarchicalOptionsSortMethodSelect = document . getElementById ( 'sortMethod' ) ;
260
291
if ( showHierarchicalOptionsCheckbox . checked ) {
261
292
if ( hierarchicalOptionsDirectionSelect . value && hierarchicalOptionsDirectionSelect . value === 'Random' ) {
262
- options . layout = { } ;
293
+ setRandomLayout ( ) ;
263
294
seed = Math . random ( ) ;
264
295
} else {
265
- options . layout = {
266
- hierarchical : {
267
- enabled : true ,
268
- direction : hierarchicalOptionsDirectionSelect . value ? hierarchicalOptionsDirectionSelect . value : 'UD' ,
269
- sortMethod : hierarchicalOptionsSortMethodSelect . value ? hierarchicalOptionsSortMethodSelect . value : 'hubsize'
270
- }
271
- } ;
296
+ const direction = hierarchicalOptionsDirectionSelect . value ? hierarchicalOptionsDirectionSelect . value : 'UD' ;
297
+ const sortMethod = hierarchicalOptionsSortMethodSelect . value ? hierarchicalOptionsSortMethodSelect . value : 'hubsize' ;
298
+ setHierarchicalLayout ( direction , sortMethod ) ;
272
299
}
273
300
} else {
274
301
options . layout = { } ;
You can’t perform that action at this time.
0 commit comments