Skip to content

Commit 6b0d288

Browse files
committed
The state of the checkbox and the dropdown boxes are now persisted.
1 parent 4f4af80 commit 6b0d288

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

src/commands/generateDependencyInjectionGraph.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ export class GenerateDependencyInjectionGraph extends ShowHierarchyBase {
124124
jsContent = jsContent.replace('ctx.lineWidth = 1; // graph selection guideline width', `ctx.lineWidth = ${this.config.graphSelectionGuidelineWidth}; // graph selection guideline width`);
125125
jsContent = jsContent.replace('selectionCanvasContext.strokeStyle = \'red\';', `selectionCanvasContext.strokeStyle = '${this.config.graphSelectionColor}';`);
126126
jsContent = jsContent.replace('selectionCanvasContext.lineWidth = 2;', `selectionCanvasContext.lineWidth = ${this.config.graphSelectionWidth};`);
127+
jsContent = jsContent.replace('let showHierarchicalOptionsCheckboxChecked = false;', `let showHierarchicalOptionsCheckboxChecked = ${this.graphState.showHierarchicalOptions};`);
128+
jsContent = jsContent.replace('let hierarchicalOptionsDirectionSelectValue = undefined;', `let hierarchicalOptionsDirectionSelectValue = '${this.graphState.graphDirection}';`);
129+
jsContent = jsContent.replace('let hierarchicalOptionsSortMethodSelectValue = undefined;', `let hierarchicalOptionsSortMethodSelectValue = '${this.graphState.graphLayout}';`);
127130
jsContent = this.setGraphState(jsContent);
128131
return jsContent;
129132
}

src/commands/showComponentHierarchy.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ export class ShowComponentHierarchy extends ShowHierarchyBase {
122122
jsContent = jsContent.replace('ctx.lineWidth = 1; // graph selection guideline width', `ctx.lineWidth = ${this.config.graphSelectionGuidelineWidth}; // graph selection guideline width`);
123123
jsContent = jsContent.replace('selectionCanvasContext.strokeStyle = \'red\';', `selectionCanvasContext.strokeStyle = '${this.config.graphSelectionColor}';`);
124124
jsContent = jsContent.replace('selectionCanvasContext.lineWidth = 2;', `selectionCanvasContext.lineWidth = ${this.config.graphSelectionWidth};`);
125+
jsContent = jsContent.replace('let showHierarchicalOptionsCheckboxChecked = false;', `let showHierarchicalOptionsCheckboxChecked = ${this.graphState.showHierarchicalOptions};`);
126+
jsContent = jsContent.replace('let hierarchicalOptionsDirectionSelectValue = undefined;', `let hierarchicalOptionsDirectionSelectValue = '${this.graphState.graphDirection}';`);
127+
jsContent = jsContent.replace('let hierarchicalOptionsSortMethodSelectValue = undefined;', `let hierarchicalOptionsSortMethodSelectValue = '${this.graphState.graphLayout}';`);
125128
jsContent = this.setGraphState(jsContent);
126129
return jsContent;
127130
}

src/commands/showModuleHierarchy.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ export class ShowModuleHierarchy extends ShowHierarchyBase {
118118
jsContent = jsContent.replace('ctx.lineWidth = 1; // graph selection guideline width', `ctx.lineWidth = ${this.config.graphSelectionGuidelineWidth}; // graph selection guideline width`);
119119
jsContent = jsContent.replace('selectionCanvasContext.strokeStyle = \'red\';', `selectionCanvasContext.strokeStyle = '${this.config.graphSelectionColor}';`);
120120
jsContent = jsContent.replace('selectionCanvasContext.lineWidth = 2;', `selectionCanvasContext.lineWidth = ${this.config.graphSelectionWidth};`);
121+
jsContent = jsContent.replace('let showHierarchicalOptionsCheckboxChecked = false;', `let showHierarchicalOptionsCheckboxChecked = ${this.graphState.showHierarchicalOptions};`);
122+
jsContent = jsContent.replace('let hierarchicalOptionsDirectionSelectValue = undefined;', `let hierarchicalOptionsDirectionSelectValue = '${this.graphState.graphDirection}';`);
123+
jsContent = jsContent.replace('let hierarchicalOptionsSortMethodSelectValue = undefined;', `let hierarchicalOptionsSortMethodSelectValue = '${this.graphState.graphLayout}';`);
121124
jsContent = this.setGraphState(jsContent);
122125
return jsContent;
123126
}

src/model/GraphState.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export class GraphState {
44
constructor() {
55
this.nodePositions = {};
66
}
7-
public graphLayout: string | undefined;
8-
public graphDirection: string | undefined;
7+
public graphLayout: string = "hubsize";
8+
public graphDirection: string = "Random";
99
public networkSeed: string | undefined;
1010
public nodePositions: { [id: string]: Position };
1111
public showHierarchicalOptions: boolean = false;

templates/showHierarchy_Template.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
let lastMouseX = lastMouseY = 0;
4949
let mouseX = mouseY = 0;
5050
let selection;
51+
5152
// get the vis.js canvas
5253
const graphDiv = document.getElementById('network');
5354
const visDiv = graphDiv.firstElementChild;
@@ -79,6 +80,12 @@
7980
const hierarchicalOptionsDirection = document.getElementById('hierarchicalOptions_direction');
8081
const hierarchicalOptionsSortMethod = document.getElementById('hierarchicalOptions_sortmethod');
8182

83+
let hierarchicalOptionsDirectionSelectValue = undefined;
84+
let hierarchicalOptionsSortMethodSelectValue = undefined;
85+
let showHierarchicalOptionsCheckboxChecked = false;
86+
showHierarchicalOptionsCheckbox.checked = showHierarchicalOptionsCheckboxChecked;
87+
showHierarchicalOptions();
88+
8289
function mouseUpEventListener(event) {
8390
// Convert the canvas to image data that can be saved
8491
const aspectRatioX = graphCanvas.width / selectionCanvas.width;
@@ -305,6 +312,10 @@
305312

306313
function regenerateGraph() {
307314
seed = Math.random();
315+
hierarchicalOptionsDirectionSelect.value = 'Random';
316+
hierarchicalOptionsDirectionSelectValue = hierarchicalOptionsDirectionSelect.value;
317+
hierarchicalOptionsSortMethodSelect.value = 'hubsize';
318+
hierarchicalOptionsSortMethodSelectValue = hierarchicalOptionsSortMethodSelect.value;
308319
removeNodePositions();
309320
setNetworkLayout();
310321
}
@@ -344,9 +355,12 @@
344355
}
345356

346357
function showHierarchicalOptions(){
358+
showHierarchicalOptionsCheckboxChecked = showHierarchicalOptionsCheckbox.checked;
347359
if (showHierarchicalOptionsCheckbox.checked) {
348360
hierarchicalOptionsDirection.style['display'] = 'block';
361+
hierarchicalOptionsDirectionSelect.value = hierarchicalOptionsDirectionSelectValue ? hierarchicalOptionsDirectionSelectValue : 'Random';
349362
hierarchicalOptionsSortMethod.style['display'] = 'block';
363+
hierarchicalOptionsSortMethodSelect.value = hierarchicalOptionsSortMethodSelectValue ? hierarchicalOptionsSortMethodSelectValue : 'hubsize';
350364
if (hierarchicalOptionsDirectionSelect.value && hierarchicalOptionsDirectionSelect.value === 'Random') {
351365
regenerateGraphButton.style['display'] = 'block';
352366
} else {
@@ -357,6 +371,7 @@
357371
hierarchicalOptionsSortMethod.style['display'] = 'none';
358372
regenerateGraphButton.style['display'] = 'block';
359373
}
374+
postGraphState();
360375
}
361376

362377
function setNetworkLayout() {
@@ -392,8 +407,8 @@
392407
function postGraphState() {
393408
const message = JSON.stringify({
394409
networkSeed: seed,
395-
graphDirection: showHierarchicalOptionsCheckbox.checked ? hierarchicalOptionsDirectionSelect.value : undefined,
396-
graphLayout: showHierarchicalOptionsCheckbox.checked ? hierarchicalOptionsSortMethodSelect.value : undefined,
410+
graphDirection: showHierarchicalOptionsCheckbox.checked ? hierarchicalOptionsDirectionSelect.value : 'Random',
411+
graphLayout: showHierarchicalOptionsCheckbox.checked ? hierarchicalOptionsSortMethodSelect.value : 'hubsize',
397412
showHierarchicalOptions: showHierarchicalOptionsCheckbox.checked,
398413
nodePositions: getNodePositions()
399414
});

0 commit comments

Comments
 (0)