34
34
var network = new vis . Network ( container , data , options ) ;
35
35
var seed = network . getSeed ( ) ;
36
36
network . on ( "stabilizationIterationsDone" , function ( ) {
37
- network . setOptions ( { physics : false } ) ;
37
+ network . setOptions ( {
38
+ physics : false
39
+ } ) ;
40
+ nodes . forEach ( function ( node ) {
41
+ nodes . update ( {
42
+ id : node . id ,
43
+ fixed : false
44
+ } ) ;
45
+ } ) ;
46
+ postGraphState ( ) ;
38
47
} ) ;
39
48
network . on ( 'dragEnd' , postGraphState ) ;
40
49
52
61
let selectionCanvasContext ;
53
62
54
63
const hierarchicalOptionsDirectionSelect = document . getElementById ( 'direction' ) ;
64
+ const showHierarchicalOptionsCheckbox = document . getElementById ( 'showHierarchicalOptions' ) ;
55
65
56
66
// add button event listeners
57
67
const saveAsPngButton = document . getElementById ( 'saveAsPngButton' ) ;
262
272
nodes . forEach ( node => {
263
273
nodeExport [ node . id ] = {
264
274
id : node . id ,
265
- label : command === 'saveAsDgml' ? cleanLabelDgml ( node . label ) : cleanLabelDot ( node . label ) ,
275
+ label : command === 'saveAsDgml' ? cleanLabelDgml ( node . label ) : cleanLabelDot ( node . label ) ,
266
276
position : network . getPosition ( node . id ) ,
267
277
boundingBox : network . getBoundingBox ( node . id )
268
278
} ;
292
302
let cleanedLabel = label . replace ( / ( < ( [ ^ > ] + ) > ) / ig, '' ) ;
293
303
return cleanedLabel ;
294
304
}
305
+
295
306
function removeNewlines ( label ) {
296
307
let cleanedLabel = label . replace ( / \s + / g, '' ) ;
297
308
return cleanedLabel ;
298
309
}
310
+
299
311
function convertNewlinesToDotNewlines ( label ) {
300
312
let cleanedLabel = label . replace ( / \n / g, '<br align="left"/>' ) ;
301
313
return cleanedLabel ;
306
318
}
307
319
308
320
function setRandomLayout ( ) {
309
- options . layout = {
321
+ options . layout = {
310
322
hierarchical : {
311
323
enabled : false
312
324
}
322
334
323
335
function setHierarchicalLayout ( direction , sortMethod ) {
324
336
options . layout = {
325
- hierarchical : {
337
+ hierarchical : {
326
338
enabled : true ,
327
339
levelSeparation : 200 ,
328
340
nodeSpacing : 200 ,
342
354
function setNetworkLayout ( ) {
343
355
const hierarchicalOptionsDirection = document . getElementById ( 'hierarchicalOptions_direction' ) ;
344
356
const hierarchicalOptionsSortMethod = document . getElementById ( 'hierarchicalOptions_sortmethod' ) ;
345
- const showHierarchicalOptionsCheckbox = document . getElementById ( 'showHierarchicalOptions' ) ;
346
357
hierarchicalOptionsDirection . style [ 'display' ] = showHierarchicalOptionsCheckbox . checked ? 'block' : 'none' ;
347
358
hierarchicalOptionsSortMethod . style [ 'display' ] = showHierarchicalOptionsCheckbox . checked ? 'block' : 'none' ;
348
359
const hierarchicalOptionsSortMethodSelect = document . getElementById ( 'sortMethod' ) ;
361
372
options . layout . randomSeed = seed ;
362
373
network = new vis . Network ( container , data , options ) ;
363
374
network . on ( "stabilizationIterationsDone" , function ( ) {
364
- network . setOptions ( { physics : false } ) ;
375
+ network . setOptions ( {
376
+ physics : false
377
+ } ) ;
378
+ nodes . forEach ( function ( node ) {
379
+ nodes . update ( {
380
+ id : node . id ,
381
+ fixed : false
382
+ } ) ;
383
+ } ) ;
384
+ postGraphState ( ) ;
365
385
} ) ;
366
386
network . on ( 'dragEnd' , postGraphState ) ;
367
- vscode . postMessage ( {
368
- command : 'setGraphState' ,
369
- text : JSON . stringify ( {
370
- networkSeed : seed ,
371
- graphDirection : hierarchicalOptionsDirectionSelect . value ,
372
- graphLayout : hierarchicalOptionsSortMethodSelect . value ,
373
- nodePositions : getNodePositions ( )
374
- } )
375
- } ) ;
387
+ postGraphState ( ) ;
376
388
}
377
389
378
390
function postGraphState ( ) {
379
391
const message = JSON . stringify ( {
380
392
networkSeed : seed ,
381
- // graphDirection: hierarchicalOptionsDirectionSelect.value,
382
- // graphLayout: hierarchicalOptionsSortMethodSelect.value,
393
+ graphDirection : showHierarchicalOptionsCheckbox . checked ? hierarchicalOptionsDirectionSelect . value : undefined ,
394
+ graphLayout : showHierarchicalOptionsCheckbox . checked ? hierarchicalOptionsSortMethodSelect . value : undefined ,
395
+ showHierarchicalOptions : showHierarchicalOptionsCheckbox . checked ,
383
396
nodePositions : getNodePositions ( )
384
397
} ) ;
385
- console . log ( 'postGraphState' , message ) ;
386
398
vscode . postMessage ( {
387
399
command : 'setGraphState' ,
388
400
text : message
392
404
function getNodePositions ( ) {
393
405
const nodePositions = { } ;
394
406
nodes . forEach ( node => {
407
+ const position = network . getPosition ( node . id ) ;
395
408
nodePositions [ node . id ] = {
396
- id : node . id ,
397
- position : network . getPosition ( node . id )
409
+ x : position . x ,
410
+ y : position . y
398
411
} ;
399
412
} ) ;
400
413
return nodePositions ;
401
414
}
402
-
415
+
403
416
} ( ) ) ;
0 commit comments