Skip to content

Commit

Permalink
fix bug with lateral links
Browse files Browse the repository at this point in the history
  • Loading branch information
FloSch62 committed Jun 24, 2024
1 parent 0916796 commit 5015368
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion clab2drawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,28 @@ def add_ports(diagram, styles, verbose=True):

def add_links(diagram, styles):
nodes = diagram.nodes
global_seen_links = set()

for node in nodes.values():
downstream_links = node.get_downstream_links()
lateral_links = node.get_lateral_links()

links = downstream_links + lateral_links

# Filter links globally
filtered_links = []
for link in links:
source_id = f"{link.source.name}:{link.source_intf}"
target_id = f"{link.target.name}:{link.target_intf}"
link_pair = tuple(sorted([source_id, target_id]))

if link_pair not in global_seen_links:
global_seen_links.add(link_pair)
filtered_links.append(link)

# Group links by their target
target_groups = {}
for link in links:
for link in filtered_links:
target = link.target
if target not in target_groups:
target_groups[target] = []
Expand Down Expand Up @@ -361,6 +373,7 @@ def add_links(diagram, styles):
) = link.get_label_positions(entryX, entryY, exitX, exitY, styles)

diagram.add_link(
link_id=f"link:{link.source.name}:{link.source_intf}:{link.target.name}:{link.target_intf}",
source=link.source.name,
target=link.target.name,
style=style,
Expand Down Expand Up @@ -389,6 +402,7 @@ def add_links(diagram, styles):
)
else:
diagram.add_link(
link_id=f"link:{link.source.name}:{link.source_intf}:{link.target.name}:{link.target_intf}",
source=link.source.name,
target=link.target.name,
src_label=link.source_intf,
Expand Down

0 comments on commit 5015368

Please sign in to comment.