|
1 | 1 | (function () {
|
2 | 2 | var nodes = new vis.DataSet([]);
|
| 3 | + var nodeCoordinates = []; |
3 | 4 |
|
4 | 5 | nodes.forEach(nodeId => {
|
5 | 6 | nodes.get(nodeId).color = {
|
|
35 | 36 | var defaultGraphDirection = ''; // The graph direction from the dgml file itself
|
36 | 37 | setDefaultGraphDirection();
|
37 | 38 | var container = document.getElementById('network');
|
| 39 | + var seed = Math.random(); |
| 40 | + options.layout.randomSeed = seed; |
38 | 41 | var network = new vis.Network(container, data, options);
|
39 |
| - var seed = network.getSeed(); |
40 | 42 | network.on("stabilizationIterationsDone", function () {
|
41 | 43 | network.setOptions( { physics: false } );
|
42 | 44 | });
|
|
258 | 260 |
|
259 | 261 | function setDefaultGraphDirection() {
|
260 | 262 | const hierarchicalOptionsDirection = document.getElementById('direction');
|
| 263 | + let selectedOption = ''; |
| 264 | + selectedOption = defaultGraphDirection === '' ? 'Fixed' : defaultGraphDirection; |
261 | 265 | for (var i, j = 0; i = hierarchicalOptionsDirection.options[j]; j++) {
|
262 |
| - if (i.value === defaultGraphDirection) { |
| 266 | + if (i.value === selectedOption) { |
263 | 267 | hierarchicalOptionsDirection.selectedIndex = j;
|
264 | 268 | break;
|
265 | 269 | }
|
266 | 270 | }
|
267 | 271 | }
|
268 | 272 |
|
| 273 | + function storeCoordinates(node) { |
| 274 | + if(node.x !== undefined && node.y !== undefined) { |
| 275 | + nodeCoordinates[node.id] = { x: node.x, y: node.y }; |
| 276 | + } |
| 277 | + delete node.x; |
| 278 | + delete node.y; |
| 279 | + delete node.fixed; |
| 280 | + } |
| 281 | + |
| 282 | + function restoreCoordinates(node) { |
| 283 | + if (node.id in nodeCoordinates) { |
| 284 | + var nodeCoords = nodeCoordinates[node.id]; |
| 285 | + if (nodeCoords.x !== undefined && nodeCoords.y !== undefined) { |
| 286 | + node.x = nodeCoords.x; |
| 287 | + node.y = nodeCoords.y; |
| 288 | + node.fixed = { x: true, y: true}; |
| 289 | + } |
| 290 | + } |
| 291 | + } |
| 292 | + |
269 | 293 | function setNetworkLayout() {
|
270 | 294 | const hierarchicalOptionsDirection = document.getElementById('hierarchicalOptions_direction');
|
271 | 295 | const hierarchicalOptionsSortMethod = document.getElementById('hierarchicalOptions_sortmethod');
|
|
276 | 300 | const hierarchicalOptionsSortMethodSelect = document.getElementById('sortMethod');
|
277 | 301 | if (showHierarchicalOptionsCheckbox.checked) {
|
278 | 302 | if (hierarchicalOptionsDirectionSelect.value && hierarchicalOptionsDirectionSelect.value === 'Random') {
|
279 |
| - options.layout = {}; |
| 303 | + nodes.getIds().forEach(id => storeCoordinates(nodes.get(id) )); |
| 304 | + options.layout = { hierarchical: { enabled: false } }; |
280 | 305 | seed = Math.random();
|
| 306 | + } else if (hierarchicalOptionsDirectionSelect.value && hierarchicalOptionsDirectionSelect.value === 'Fixed') { |
| 307 | + options.layout = { hierarchical: { enabled: false } }; |
| 308 | + nodes.getIds().forEach(id => restoreCoordinates(nodes.get(id)) ); |
281 | 309 | } else {
|
282 | 310 | options.layout = {
|
283 | 311 | hierarchical: {
|
|
289 | 317 | }
|
290 | 318 | } else {
|
291 | 319 | if (defaultGraphDirection === '') {
|
292 |
| - options.layout = {}; |
| 320 | + options.layout = { hierarchical: { enabled: false } }; |
| 321 | + nodes.getIds().forEach(id => restoreCoordinates(nodes.get(id)) ); |
293 | 322 | } else {
|
294 | 323 | options.layout = {
|
295 | 324 | hierarchical: {
|
|
298 | 327 | sortMethod: 'hubsize'
|
299 | 328 | }
|
300 | 329 | };
|
| 330 | + nodes.getIds().forEach(id => storeCoordinates(nodes.get(id) )); |
301 | 331 | }
|
302 | 332 | }
|
303 | 333 | options.layout.randomSeed = seed;
|
| 334 | + network.setOptions( { |
| 335 | + physics: { |
| 336 | + enabled: true, |
| 337 | + solver: 'repulsion' |
| 338 | + } |
| 339 | + }); |
| 340 | + nodes.getIds().forEach(id => { |
| 341 | + const node = nodes.get(id); |
| 342 | + }); |
304 | 343 | network = new vis.Network(container, data, options);
|
305 | 344 | network.on("stabilizationIterationsDone", function () {
|
306 | 345 | network.setOptions( { physics: false } );
|
|
0 commit comments