Skip to content

Commit 939c24b

Browse files
committed
You can now choose how to auto-layout the component hierarchy graph.
1 parent 573bff2 commit 939c24b

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

stylesheet/showComponentHierarchy.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
z-index: 100;
1818
padding: 5px 5px 5px 10px;
1919
margin: 5px;
20+
display: grid;
21+
grid-template-columns: auto auto auto auto auto auto;
2022
}
2123

2224
#helpText {
@@ -33,4 +35,9 @@ input[type=button] {
3335
display: none;
3436
background-color: rgba(240, 240, 240, 0.4);
3537
z-index: 200;
38+
}
39+
40+
#hierarchicalOptions_direction, #hierarchicalOptions_sortmethod {
41+
display: none;
42+
margin-left: 3px;
3643
}

templates/showComponentHierarchy_Template.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@
1616
<input type="button" id="saveAsPngButton" value="Save as png">
1717
<input type="button" id="saveSelectionAsPngButton" value="Save selection as png">
1818
<input type="button" id="copyToClipboardButton" value="Copy to clipboard">
19+
<div id="hierarchical">Change layout:<input type="checkbox" id="showHierarchicalOptions"></div>
20+
<div id="hierarchicalOptions_direction">
21+
Direction: <select id="direction">
22+
<option value="UD">Up-Down</option>
23+
<option value="DU">Down-Up</option>
24+
<option value="LR">Left-Right</option>
25+
<option value="RL">Right-Left</option>
26+
</select>
27+
</div>
28+
<div id="hierarchicalOptions_sortmethod">
29+
Sort method: <select id="sortMethod">
30+
<option value="hubsize">Hub size</option>
31+
<option value="directed">Directed</option>
32+
</select>
33+
</div>
1934
<div id="helpText">Click and drag to select the area to be saved.</div>
2035
</div>
2136
<div id="selectionLayer" class="fullScreen"><canvas id="captureCanvas"></canvas></div>

templates/showComponentHierarchy_Template.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@
3333
};
3434
var container = document.getElementById('network');
3535
var network = new vis.Network(container, data, options);
36-
36+
var seed = network.getSeed();
37+
3738
const vscode = acquireVsCodeApi();
3839
const helpTextDiv = document.getElementById('helpText');
3940
let lastMouseX = lastMouseY = 0;
4041
let mouseX = mouseY = 0;
4142
let selection;
4243
// get the vis.js canvas
43-
const graphDiv = document.getElementById('network');
44-
const visDiv = graphDiv.firstElementChild;
45-
const graphCanvas = visDiv.firstElementChild;
44+
var graphDiv = document.getElementById('network');
45+
var visDiv = graphDiv.firstElementChild;
46+
var graphCanvas = visDiv.firstElementChild;
4647
const selectionLayer = document.getElementById('selectionLayer');
4748
const selectionCanvas = selectionLayer.firstElementChild;
4849
let selectionCanvasContext;
@@ -55,6 +56,12 @@
5556
const copyToClipboardButton = document.getElementById('copyToClipboardButton');
5657
copyToClipboardButton.addEventListener('click', copyToClipboard);
5758
copyToClipboardButton.style['display'] = 'none'; // TODO: Remove when copyToClipboard is implemented
59+
const showHierarchicalOptionsButton = document.getElementById('showHierarchicalOptions');
60+
showHierarchicalOptionsButton.addEventListener('click', setNetworkLayout);
61+
const hierarchicalDirectionSelect = document.getElementById('direction');
62+
hierarchicalDirectionSelect.addEventListener('change', setNetworkLayout);
63+
const hierarchicalSortMethodSelect = document.getElementById('sortMethod');
64+
hierarchicalSortMethodSelect.addEventListener('change', setNetworkLayout);
5865

5966
function mouseUpEventListener(event) {
6067
// Convert the canvas to image data that can be saved
@@ -155,6 +162,9 @@
155162
}
156163

157164
function saveAsPng() {
165+
graphDiv = document.getElementById('network');
166+
visDiv = graphDiv.firstElementChild;
167+
graphCanvas = visDiv.firstElementChild;
158168
// Calculate the bounding box of all the elements on the canvas
159169
const boundingBox = getBoundingBox();
160170

@@ -230,4 +240,27 @@
230240
console.log('Not implemented yet...');
231241
}
232242

243+
function setNetworkLayout() {
244+
const hierarchicalOptionsDirection = document.getElementById('hierarchicalOptions_direction');
245+
const hierarchicalOptionsSortMethod = document.getElementById('hierarchicalOptions_sortmethod');
246+
const showHierarchicalOptionsCheckbox = document.getElementById('showHierarchicalOptions');
247+
hierarchicalOptionsDirection.style['display'] = showHierarchicalOptionsCheckbox.checked ? 'block' : 'none';
248+
hierarchicalOptionsSortMethod.style['display'] = showHierarchicalOptionsCheckbox.checked ? 'block' : 'none';
249+
const hierarchicalOptionsDirectionSelect = document.getElementById('direction');
250+
const hierarchicalOptionsSortMethodSelect = document.getElementById('sortMethod');
251+
if(showHierarchicalOptionsCheckbox.checked) {
252+
options.layout = {
253+
hierarchical: {
254+
enabled: true,
255+
direction: hierarchicalOptionsDirectionSelect.value ? hierarchicalOptionsDirectionSelect.value : 'UD',
256+
sortMethod: hierarchicalOptionsSortMethodSelect.value ? hierarchicalOptionsSortMethodSelect.value : 'hubsize'
257+
}
258+
};
259+
} else {
260+
options.layout = {};
261+
}
262+
options.layout.randomSeed = seed;
263+
network = new vis.Network(container, data, options);
264+
}
265+
233266
}());

0 commit comments

Comments
 (0)