33
33
const container = document . getElementById ( 'network' ) ;
34
34
let network = new vis . Network ( container , data , options ) ;
35
35
let seed = network . getSeed ( ) ;
36
- let nodePositions = [ ] ;
37
36
38
37
network . on ( "stabilizationIterationsDone" , function ( ) {
39
38
network . setOptions ( {
58
57
let selectionCanvasContext ;
59
58
60
59
const hierarchicalOptionsDirectionSelect = document . getElementById ( 'direction' ) ;
61
- const showHierarchicalOptionsCheckbox = document . getElementById ( 'showHierarchicalOptions' ) ;
62
60
63
61
// add button event listeners
64
62
const saveAsPngButton = document . getElementById ( 'saveAsPngButton' ) ;
71
69
regenerateGraphButton . addEventListener ( 'click' , regenerateGraph ) ;
72
70
const saveSelectionAsPngButton = document . getElementById ( 'saveSelectionAsPngButton' ) ;
73
71
saveSelectionAsPngButton . addEventListener ( 'click' , saveSelectionAsPng ) ;
74
- const showHierarchicalOptionsButton = document . getElementById ( 'showHierarchicalOptions' ) ;
75
- showHierarchicalOptionsButton . addEventListener ( 'click' , setNetworkLayout ) ;
72
+ const showHierarchicalOptionsCheckbox = document . getElementById ( 'showHierarchicalOptions' ) ;
73
+ showHierarchicalOptionsCheckbox . addEventListener ( 'click' , showHierarchicalOptions ) ;
76
74
const hierarchicalDirectionSelect = document . getElementById ( 'direction' ) ;
77
75
hierarchicalDirectionSelect . addEventListener ( 'change' , setNetworkLayout ) ;
78
76
const hierarchicalSortMethodSelect = document . getElementById ( 'sortMethod' ) ;
79
77
hierarchicalSortMethodSelect . addEventListener ( 'change' , setNetworkLayout ) ;
80
78
const hierarchicalOptionsSortMethodSelect = document . getElementById ( 'sortMethod' ) ;
79
+ const hierarchicalOptionsDirection = document . getElementById ( 'hierarchicalOptions_direction' ) ;
80
+ const hierarchicalOptionsSortMethod = document . getElementById ( 'hierarchicalOptions_sortmethod' ) ;
81
81
82
82
function mouseUpEventListener ( event ) {
83
83
// Convert the canvas to image data that can be saved
305
305
306
306
function regenerateGraph ( ) {
307
307
seed = Math . random ( ) ;
308
- nodes . forEach ( function ( node ) {
309
- nodes . update ( {
310
- id : node . id ,
311
- fixed : false ,
312
- x : undefined ,
313
- y : undefined
314
- } ) ;
315
- } ) ;
308
+ removeNodePositions ( ) ;
316
309
setNetworkLayout ( ) ;
317
310
}
318
311
350
343
} ;
351
344
}
352
345
346
+ function showHierarchicalOptions ( ) {
347
+ if ( showHierarchicalOptionsCheckbox . checked ) {
348
+ hierarchicalOptionsDirection . style [ 'display' ] = 'block' ;
349
+ hierarchicalOptionsSortMethod . style [ 'display' ] = 'block' ;
350
+ if ( hierarchicalOptionsDirectionSelect . value && hierarchicalOptionsDirectionSelect . value === 'Random' ) {
351
+ regenerateGraphButton . style [ 'display' ] = 'block' ;
352
+ } else {
353
+ regenerateGraphButton . style [ 'display' ] = 'none' ;
354
+ }
355
+ } else {
356
+ hierarchicalOptionsDirection . style [ 'display' ] = 'none' ;
357
+ hierarchicalOptionsSortMethod . style [ 'display' ] = 'none' ;
358
+ regenerateGraphButton . style [ 'display' ] = 'block' ;
359
+ }
360
+ }
361
+
353
362
function setNetworkLayout ( ) {
354
- const hierarchicalOptionsDirection = document . getElementById ( 'hierarchicalOptions_direction' ) ;
355
- const hierarchicalOptionsSortMethod = document . getElementById ( 'hierarchicalOptions_sortmethod' ) ;
356
- hierarchicalOptionsDirection . style [ 'display' ] = showHierarchicalOptionsCheckbox . checked ? 'block' : 'none' ;
357
- hierarchicalOptionsSortMethod . style [ 'display' ] = showHierarchicalOptionsCheckbox . checked ? 'block' : 'none' ;
358
363
if ( showHierarchicalOptionsCheckbox . checked ) {
359
364
if ( hierarchicalOptionsDirectionSelect . value && hierarchicalOptionsDirectionSelect . value === 'Random' ) {
360
365
setRandomLayout ( ) ;
366
+ seed = Math . random ( ) ;
367
+ removeNodePositions ( ) ;
368
+ regenerateGraphButton . style [ 'display' ] = 'block' ;
361
369
} else {
362
370
const direction = hierarchicalOptionsDirectionSelect . value ? hierarchicalOptionsDirectionSelect . value : 'UD' ;
363
371
const sortMethod = hierarchicalOptionsSortMethodSelect . value ? hierarchicalOptionsSortMethodSelect . value : 'hubsize' ;
364
372
setHierarchicalLayout ( direction , sortMethod ) ;
373
+ regenerateGraphButton . style [ 'display' ] = 'none' ;
365
374
}
366
375
} else {
367
376
options . layout = { } ;
377
+ regenerateGraphButton . style [ 'display' ] = 'block' ;
368
378
}
369
379
options . layout . randomSeed = seed ;
370
380
network = new vis . Network ( container , data , options ) ;
414
424
} ) ;
415
425
}
416
426
427
+ function removeNodePositions ( ) {
428
+ nodes . forEach ( function ( node ) {
429
+ nodes . update ( {
430
+ id : node . id ,
431
+ fixed : false ,
432
+ x : undefined ,
433
+ y : undefined
434
+ } ) ;
435
+ } ) ;
436
+ }
437
+
417
438
} ( ) ) ;
0 commit comments