Skip to content

Commit db23f7e

Browse files
authored
fix: hide devices according to layer on file load (#275)
Closes #274
1 parent b58c628 commit db23f7e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ export class GlobalContext {
242242
input.accept = ".json";
243243

244244
input.onchange = (event) => {
245+
// NOTE: browser takes care of making sure we get a single file here
245246
const file = (event.target as HTMLInputElement).files[0];
246247
const reader = new FileReader();
247248
reader.readAsText(file);

src/types/graphs/viewgraph.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@ export class ViewGraph {
3131
this.ctx = ctx;
3232
this.datagraph = datagraph;
3333
this.viewport = ctx.getViewport();
34-
this.layer = layer;
34+
35+
// NOTE: here we initialize on Link layer to avoid weird issues related
36+
// to devices hiding themselves due to being on an unfinished viewgraph
37+
this.layer = Layer.Link;
3538
this.packetManager = new PacketManager();
3639
this.constructView();
40+
41+
// Change to the specified layer
42+
this.changeLayerAndHideDevices(layer);
3743
}
3844

3945
private constructView() {
@@ -195,7 +201,11 @@ export class ViewGraph {
195201
return this.layer;
196202
}
197203

198-
changeCurrLayer(newLayer: Layer) {
204+
/**
205+
* Changes the layer of the viewgraph and updates the visibility of devices and edges.
206+
* This skips notifying other components about the change.
207+
*/
208+
private changeLayerAndHideDevices(newLayer: Layer) {
199209
this.layer = newLayer;
200210

201211
for (const [, device] of this.graph.getAllVertices()) {
@@ -227,6 +237,10 @@ export class ViewGraph {
227237
for (const [, device] of this.graph.getAllVertices()) {
228238
device.updateDevicesAspect();
229239
}
240+
}
241+
242+
changeCurrLayer(newLayer: Layer) {
243+
this.changeLayerAndHideDevices(newLayer);
230244

231245
// warn Packet Manager that the layer has been changed
232246
this.packetManager.layerChanged(newLayer);

0 commit comments

Comments
 (0)