@@ -24,6 +24,7 @@ def __init__(
24
24
self .styles = styles
25
25
self .prefix = prefix
26
26
self .lab_name = lab_name
27
+ self .annotations = containerlab_data .get ("annotations" )
27
28
28
29
def format_node_name (self , base_name : str ) -> str :
29
30
"""
@@ -62,28 +63,50 @@ def _build_nodes(self):
62
63
node_height = self .styles .get ("node_height" , 75 )
63
64
base_style = self .styles .get ("base_style" , "" )
64
65
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
+
65
72
nodes = {}
66
73
for node_name , node_data in nodes_from_clab .items ():
67
74
formatted_node_name = self .format_node_name (node_name )
68
75
69
- # Extract position from graph-posX and graph-posY labels if available
76
+ # Initialize default values
70
77
pos_x = node_data .get ("pos_x" , "" )
71
78
pos_y = node_data .get ("pos_y" , "" )
79
+ graph_icon = None
80
+ graph_level = None
72
81
73
- # Check for graph-posX and graph-posY in labels
82
+ # First check labels (lower priority)
74
83
labels = node_data .get ("labels" , {})
75
84
if "graph-posX" in labels :
76
85
pos_x = labels ["graph-posX" ]
77
86
if "graph-posY" in labels :
78
87
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
79
102
80
103
node = Node (
81
104
name = formatted_node_name ,
82
105
label = node_name ,
83
106
kind = node_data .get ("kind" , "" ),
84
107
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 ,
87
110
base_style = base_style ,
88
111
custom_style = self .styles .get (node_data .get ("kind" , "" ), "" ),
89
112
pos_x = pos_x ,
0 commit comments