From 062375e93843c20ef4282db42bd484dff25fb6b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Sat, 7 Jun 2025 12:28:30 -0300 Subject: [PATCH 1/3] docs: add comment about file loading --- src/context.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/context.ts b/src/context.ts index 6c29a418..597e7353 100644 --- a/src/context.ts +++ b/src/context.ts @@ -242,6 +242,7 @@ export class GlobalContext { input.accept = ".json"; input.onchange = (event) => { + // NOTE: browser takes care of making sure we get a single file here const file = (event.target as HTMLInputElement).files[0]; const reader = new FileReader(); reader.readAsText(file); From b30a3b379c8a54fc3bc54a19a1f09dd461f8ab15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Sat, 7 Jun 2025 12:40:48 -0300 Subject: [PATCH 2/3] fix: perform layer change when loading file --- src/types/graphs/viewgraph.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/types/graphs/viewgraph.ts b/src/types/graphs/viewgraph.ts index 132c0d5a..84afaf0c 100644 --- a/src/types/graphs/viewgraph.ts +++ b/src/types/graphs/viewgraph.ts @@ -31,9 +31,15 @@ export class ViewGraph { this.ctx = ctx; this.datagraph = datagraph; this.viewport = ctx.getViewport(); - this.layer = layer; + + // NOTE: here we initialize on Link layer to avoid weird issues related + // to devices hiding themselves due to being on an unfinished viewgraph + this.layer = Layer.Link; this.packetManager = new PacketManager(); this.constructView(); + + // Change to the specified layer + this.changeCurrLayer(layer); } private constructView() { From 80c66caeca3f4c737a79b1f6a856d8cd101288f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Sat, 7 Jun 2025 12:42:19 -0300 Subject: [PATCH 3/3] fix: avoid notifying other devices about the change --- src/types/graphs/viewgraph.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/types/graphs/viewgraph.ts b/src/types/graphs/viewgraph.ts index 84afaf0c..8ef6cc72 100644 --- a/src/types/graphs/viewgraph.ts +++ b/src/types/graphs/viewgraph.ts @@ -39,7 +39,7 @@ export class ViewGraph { this.constructView(); // Change to the specified layer - this.changeCurrLayer(layer); + this.changeLayerAndHideDevices(layer); } private constructView() { @@ -201,7 +201,11 @@ export class ViewGraph { return this.layer; } - changeCurrLayer(newLayer: Layer) { + /** + * Changes the layer of the viewgraph and updates the visibility of devices and edges. + * This skips notifying other components about the change. + */ + private changeLayerAndHideDevices(newLayer: Layer) { this.layer = newLayer; for (const [, device] of this.graph.getAllVertices()) { @@ -233,6 +237,10 @@ export class ViewGraph { for (const [, device] of this.graph.getAllVertices()) { device.updateDevicesAspect(); } + } + + changeCurrLayer(newLayer: Layer) { + this.changeLayerAndHideDevices(newLayer); // warn Packet Manager that the layer has been changed this.packetManager.layerChanged(newLayer);