1- import { Texture , Sprite , FederatedPointerEvent , Graphics } from "pixi.js" ;
1+ import {
2+ Texture ,
3+ Sprite ,
4+ FederatedPointerEvent ,
5+ Graphics ,
6+ TextStyle ,
7+ Text ,
8+ } from "pixi.js" ;
29import { Packet } from "./../packet" ;
310import { ViewGraph } from "./../graphs/viewgraph" ;
411import {
@@ -7,7 +14,7 @@ import {
714 selectElement ,
815} from "./../viewportManager" ;
916import { RightBar } from "../../index" ;
10- import { Colors } from "../../utils" ;
17+ import { Colors , ZIndexLevels } from "../../utils" ;
1118
1219export const DEVICE_SIZE = 20 ;
1320
@@ -59,11 +66,29 @@ export class Device extends Sprite {
5966 this . eventMode = "static" ;
6067 this . interactive = true ;
6168 this . cursor = "pointer" ;
69+ this . zIndex = ZIndexLevels . Device ;
70+
71+ // Add device ID label using the helper function
72+ this . addDeviceIdLabel ( ) ;
6273
6374 this . on ( "pointerdown" , this . onPointerDown , this ) ;
6475 this . on ( "click" , this . onClick , this ) ;
6576 }
6677
78+ // Function to add the ID label to the device
79+ addDeviceIdLabel ( ) {
80+ const textStyle = new TextStyle ( {
81+ fontSize : 12 ,
82+ fill : Colors . Black ,
83+ align : "center" ,
84+ } ) ;
85+ const idText = new Text ( `ID: ${ this . id } ` , textStyle ) ;
86+ idText . anchor . set ( 0.5 ) ;
87+ idText . y = this . height - 15 ;
88+ idText . zIndex = ZIndexLevels . Label ;
89+ this . addChild ( idText ) ; // Add the ID text as a child of the device
90+ }
91+
6792 getConnections ( ) : { edgeId : number ; adyacentId : number } [ ] {
6893 return Array . from ( this . connections . entries ( ) ) . map (
6994 ( [ edgeId , adyacentId ] ) => {
@@ -222,6 +247,8 @@ export class Device extends Sprite {
222247 // Change color to red and increase line thickness
223248 this . highlightMarker . stroke ( { width : 3 , color : Colors . Violet } ) ; // Red and thicker
224249
250+ this . highlightMarker . zIndex = ZIndexLevels . Device ;
251+
225252 // Ensure the marker is in the same container as the viewport
226253 this . addChild ( this . highlightMarker ) ;
227254 }
0 commit comments