Skip to content

Commit 115f594

Browse files
committed
Fixed bug: Save selection is now working after layout has been changed.
You can now choose a random layout for the component hierarchy graph.
1 parent da9a96a commit 115f594

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

templates/showComponentHierarchy_Template.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<option value="DU">Down-Up</option>
2424
<option value="LR">Left-Right</option>
2525
<option value="RL">Right-Left</option>
26+
<option value="Random" selected>Random</option>
2627
</select>
2728
</div>
2829
<div id="hierarchicalOptions_sortmethod">

templates/showComponentHierarchy_Template.js

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
function drawGuideLine(ctx, mouseX, mouseY) {
102102
ctx.beginPath();
103103
ctx.setLineDash([3, 7]);
104-
if(mouseX > -1) {
104+
if (mouseX > -1) {
105105
ctx.moveTo(mouseX, 0);
106106
ctx.lineTo(mouseX, selectionCanvas.height);
107107
} else if (mouseY > -1) {
@@ -143,6 +143,10 @@
143143
}
144144

145145
function saveSelectionAsPng() {
146+
graphDiv = document.getElementById('network');
147+
visDiv = graphDiv.firstElementChild;
148+
graphCanvas = visDiv.firstElementChild;
149+
146150
// show the help text
147151
helpTextDiv.style['display'] = 'block';
148152

@@ -157,14 +161,14 @@
157161
selection = {};
158162

159163
selectionLayer.addEventListener("mouseup", mouseUpEventListener, true);
160-
selectionLayer.addEventListener("mousedown", mouseDownEventListener , true);
164+
selectionLayer.addEventListener("mousedown", mouseDownEventListener, true);
161165
selectionLayer.addEventListener("mousemove", mouseMoveEventListener, true);
162166
}
163167

164168
function saveAsPng() {
165169
graphDiv = document.getElementById('network');
166170
visDiv = graphDiv.firstElementChild;
167-
graphCanvas = visDiv.firstElementChild;
171+
graphCanvas = visDiv.firstElementChild;
168172
// Calculate the bounding box of all the elements on the canvas
169173
const boundingBox = getBoundingBox();
170174

@@ -173,7 +177,7 @@
173177
finalSelectionCanvas.width = boundingBox.width;
174178
finalSelectionCanvas.height = boundingBox.height;
175179
const finalSelectionCanvasContext = finalSelectionCanvas.getContext('2d');
176-
finalSelectionCanvasContext.drawImage(graphCanvas, boundingBox.top , boundingBox.left , boundingBox.width, boundingBox.height , 0, 0, boundingBox.width, boundingBox.height);
180+
finalSelectionCanvasContext.drawImage(graphCanvas, boundingBox.top, boundingBox.left, boundingBox.width, boundingBox.height, 0, 0, boundingBox.width, boundingBox.height);
177181

178182
// Call back to the extension context to save the image of the graph to the workspace folder.
179183
vscode.postMessage({
@@ -192,7 +196,7 @@
192196
var cWidth = graphCanvas.width * bytesPerPixels;
193197
var cHeight = graphCanvas.height;
194198
var minY = minX = maxY = maxX = -1;
195-
for (var y = cHeight; y > 0 && maxY === -1; y--) {
199+
for (var y = cHeight; y > 0 && maxY === -1; y--) {
196200
for (var x = 0; x < cWidth; x += bytesPerPixels) {
197201
var arrayPos = x + y * cWidth;
198202
if (imgData.data[arrayPos + 3] > 0 && maxY === -1) {
@@ -231,15 +235,15 @@
231235
return {
232236
'top': minX,
233237
'left': minY,
234-
'width': maxX-minX,
235-
'height': maxY-minY
238+
'width': maxX - minX,
239+
'height': maxY - minY
236240
};
237241
}
238242

239243
function copyToClipboard() {
240244
console.log('Not implemented yet...');
241245
}
242-
246+
243247
function setNetworkLayout() {
244248
const hierarchicalOptionsDirection = document.getElementById('hierarchicalOptions_direction');
245249
const hierarchicalOptionsSortMethod = document.getElementById('hierarchicalOptions_sortmethod');
@@ -248,19 +252,24 @@
248252
hierarchicalOptionsSortMethod.style['display'] = showHierarchicalOptionsCheckbox.checked ? 'block' : 'none';
249253
const hierarchicalOptionsDirectionSelect = document.getElementById('direction');
250254
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-
};
255+
if (showHierarchicalOptionsCheckbox.checked) {
256+
if (hierarchicalOptionsDirectionSelect.value && hierarchicalOptionsDirectionSelect.value === 'Random') {
257+
options.layout = {};
258+
seed = Math.random();
259+
} else {
260+
options.layout = {
261+
hierarchical: {
262+
enabled: true,
263+
direction: hierarchicalOptionsDirectionSelect.value ? hierarchicalOptionsDirectionSelect.value : 'UD',
264+
sortMethod: hierarchicalOptionsSortMethodSelect.value ? hierarchicalOptionsSortMethodSelect.value : 'hubsize'
265+
}
266+
};
267+
}
259268
} else {
260269
options.layout = {};
261270
}
262271
options.layout.randomSeed = seed;
263272
network = new vis.Network(container, data, options);
264273
}
265-
274+
266275
}());

0 commit comments

Comments
 (0)