Skip to content

Commit 1b3c5b5

Browse files
committed
Boundingbox of nodes are now returned from the vis.js netowrk and labels are cleaned from tags.
1 parent 3d8529c commit 1b3c5b5

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

templates/showHierarchy_Template.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
const selectionCanvas = selectionLayer.firstElementChild;
5151
let selectionCanvasContext;
5252

53+
const hierarchicalOptionsDirectionSelect = document.getElementById('direction');
54+
5355
// add button event listeners
5456
const saveAsPngButton = document.getElementById('saveAsPngButton');
5557
saveAsPngButton.addEventListener('click', saveAsPng);
@@ -249,17 +251,29 @@
249251
nodes.forEach(node => {
250252
nodeExport.push({
251253
id: node.id,
252-
label: node.label,
253-
color: node.color,
254-
position: network.getPosition(node.id)
254+
label: cleanLabel(node.label),
255+
position: network.getPosition(node.id),
256+
boundingBox: network.getBoundingBox(node.id)
255257
});
256258
});
259+
const direction = hierarchicalOptionsDirectionSelect.value ? hierarchicalOptionsDirectionSelect.value : 'UD';
257260
vscode.postMessage({
258261
command: 'saveAsDgml',
259-
text: nodeExport
262+
text: JSON.stringify({
263+
nodes: nodeExport,
264+
direction: direction
265+
})
260266
});
261267
}
262268

269+
function cleanLabel(label) {
270+
let regex = /(<([^>]+)>)/ig;
271+
let cleanedLabel = label.replace(regex, '');
272+
regex = /\s+/g;
273+
cleanedLabel = cleanedLabel.replace(regex, ' ');
274+
return cleanedLabel;
275+
}
276+
263277
function copyToClipboard() {
264278
console.log('Not implemented yet...');
265279
}
@@ -304,7 +318,6 @@
304318
const showHierarchicalOptionsCheckbox = document.getElementById('showHierarchicalOptions');
305319
hierarchicalOptionsDirection.style['display'] = showHierarchicalOptionsCheckbox.checked ? 'block' : 'none';
306320
hierarchicalOptionsSortMethod.style['display'] = showHierarchicalOptionsCheckbox.checked ? 'block' : 'none';
307-
const hierarchicalOptionsDirectionSelect = document.getElementById('direction');
308321
const hierarchicalOptionsSortMethodSelect = document.getElementById('sortMethod');
309322
if (showHierarchicalOptionsCheckbox.checked) {
310323
if (hierarchicalOptionsDirectionSelect.value && hierarchicalOptionsDirectionSelect.value === 'Random') {

0 commit comments

Comments
 (0)