@@ -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