@@ -24,6 +24,7 @@ def __init__(
2424 self .styles = styles
2525 self .prefix = prefix
2626 self .lab_name = lab_name
27+ self .annotations = containerlab_data .get ("annotations" )
2728
2829 def format_node_name (self , base_name : str ) -> str :
2930 """
@@ -62,28 +63,50 @@ def _build_nodes(self):
6263 node_height = self .styles .get ("node_height" , 75 )
6364 base_style = self .styles .get ("base_style" , "" )
6465
66+ # Create mapping of node annotations by id if annotations exist
67+ node_annotations_map = {}
68+ if self .annotations and "nodeAnnotations" in self .annotations :
69+ for annotation in self .annotations ["nodeAnnotations" ]:
70+ node_annotations_map [annotation ["id" ]] = annotation
71+
6572 nodes = {}
6673 for node_name , node_data in nodes_from_clab .items ():
6774 formatted_node_name = self .format_node_name (node_name )
6875
69- # Extract position from graph-posX and graph-posY labels if available
76+ # Initialize default values
7077 pos_x = node_data .get ("pos_x" , "" )
7178 pos_y = node_data .get ("pos_y" , "" )
79+ graph_icon = None
80+ graph_level = None
7281
73- # Check for graph-posX and graph-posY in labels
82+ # First check labels (lower priority)
7483 labels = node_data .get ("labels" , {})
7584 if "graph-posX" in labels :
7685 pos_x = labels ["graph-posX" ]
7786 if "graph-posY" in labels :
7887 pos_y = labels ["graph-posY" ]
88+ if "graph-icon" in labels :
89+ graph_icon = labels ["graph-icon" ]
90+ if "graph-level" in labels :
91+ graph_level = labels ["graph-level" ]
92+
93+ # Then check annotations (higher priority - overrides labels)
94+ if node_name in node_annotations_map :
95+ annotation = node_annotations_map [node_name ]
96+ if "position" in annotation :
97+ pos_x = str (annotation ["position" ]["x" ])
98+ pos_y = str (annotation ["position" ]["y" ])
99+ if "icon" in annotation :
100+ graph_icon = annotation ["icon" ]
101+ # Note: graph-level could be added to annotations if needed
79102
80103 node = Node (
81104 name = formatted_node_name ,
82105 label = node_name ,
83106 kind = node_data .get ("kind" , "" ),
84107 mgmt_ipv4 = node_data .get ("mgmt_ipv4" , "" ),
85- graph_level = node_data . get ( "labels" , {}). get ( "graph-level" , None ) ,
86- graph_icon = node_data . get ( "labels" , {}). get ( "graph-icon" , None ) ,
108+ graph_level = graph_level ,
109+ graph_icon = graph_icon ,
87110 base_style = base_style ,
88111 custom_style = self .styles .get (node_data .get ("kind" , "" ), "" ),
89112 pos_x = pos_x ,
0 commit comments