Skip to content

Commit 66bd035

Browse files
committed
Refactoring the setNetworkLayout
1 parent 3832d81 commit 66bd035

File tree

1 file changed

+21
-37
lines changed

1 file changed

+21
-37
lines changed

templates/dgmlViewer_Template.js

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -296,54 +296,38 @@
296296
const showHierarchicalOptionsCheckbox = document.getElementById('showHierarchicalOptions');
297297
hierarchicalOptionsDirection.style['display'] = showHierarchicalOptionsCheckbox.checked ? 'block' : 'none';
298298
hierarchicalOptionsSortMethod.style['display'] = showHierarchicalOptionsCheckbox.checked ? 'block' : 'none';
299-
const hierarchicalOptionsDirectionSelect = document.getElementById('direction');
300-
const hierarchicalOptionsSortMethodSelect = document.getElementById('sortMethod');
299+
300+
options.layout.hierarchical = {
301+
enabled: false
302+
};
303+
options.physics = {
304+
enabled: true,
305+
solver: 'repulsion'
306+
};
301307
if (showHierarchicalOptionsCheckbox.checked) {
308+
const hierarchicalOptionsDirectionSelect = document.getElementById('direction');
302309
if (hierarchicalOptionsDirectionSelect.value && hierarchicalOptionsDirectionSelect.value === 'Random') {
303-
nodes.getIds().forEach(id => storeCoordinates(nodes.get(id) ));
304-
options.layout = { hierarchical: { enabled: false } };
310+
nodes.getIds().forEach(id => storeCoordinates(nodes.get(id)));
305311
seed = Math.random();
312+
options.layout.randomSeed = seed;
306313
} else if (hierarchicalOptionsDirectionSelect.value && hierarchicalOptionsDirectionSelect.value === 'Fixed') {
307-
options.layout = { hierarchical: { enabled: false } };
308-
nodes.getIds().forEach(id => restoreCoordinates(nodes.get(id)) );
314+
nodes.getIds().forEach(id => restoreCoordinates(nodes.get(id)));
309315
} else {
310-
options.layout = {
311-
hierarchical: {
312-
enabled: true,
313-
direction: hierarchicalOptionsDirectionSelect.value ? hierarchicalOptionsDirectionSelect.value : defaultGraphDirection,
314-
sortMethod: hierarchicalOptionsSortMethodSelect.value ? hierarchicalOptionsSortMethodSelect.value : 'hubsize'
315-
}
316+
const hierarchicalOptionsSortMethodSelect = document.getElementById('sortMethod');
317+
options.layout.hierarchical = {
318+
enabled: true,
319+
direction: hierarchicalOptionsDirectionSelect.value ? hierarchicalOptionsDirectionSelect.value : defaultGraphDirection,
320+
sortMethod: hierarchicalOptionsSortMethodSelect.value ? hierarchicalOptionsSortMethodSelect.value : 'hubsize'
316321
};
317322
}
318323
} else {
319-
if (defaultGraphDirection === '') {
320-
options.layout = { hierarchical: { enabled: false } };
321-
nodes.getIds().forEach(id => restoreCoordinates(nodes.get(id)) );
322-
} else {
323-
options.layout = {
324-
hierarchical: {
325-
enabled: true,
326-
direction: defaultGraphDirection,
327-
sortMethod: 'hubsize'
328-
}
329-
};
330-
nodes.getIds().forEach(id => storeCoordinates(nodes.get(id) ));
331-
}
324+
nodes.getIds().forEach(id => restoreCoordinates(nodes.get(id)));
332325
}
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-
});
343326
network = new vis.Network(container, data, options);
344327
network.on("stabilizationIterationsDone", function () {
345-
network.setOptions( { physics: false } );
328+
network.setOptions({
329+
physics: false
330+
});
346331
});
347332
}
348-
349333
}());

0 commit comments

Comments
 (0)