Skip to content

Commit

Permalink
feat: Enable display_derived_interfaces on single child (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger authored Jul 2, 2024
1 parent 89eabf4 commit b95f27d
Show file tree
Hide file tree
Showing 4 changed files with 426 additions and 23 deletions.
16 changes: 16 additions & 0 deletions capellambse_context_diagrams/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ def _create_diagram(self, params: dict[str, t.Any]) -> cdiagram.Diagram:
setattr(self, param_name, override)

data = params.get("elkdata") or get_elkdata(self, params)
if has_single_child(data):
self.display_derived_interfaces = True
data = get_elkdata(self, params)

layout = try_to_layout(data)
add_context(layout, params.get("is_legend", False))
return self.serializer.make_diagram(
Expand Down Expand Up @@ -687,3 +691,15 @@ def calculate_label_position(
center_y = y + height / 2
tspan_y = center_y - width / 2 + padding
return (x + width / 2, center_y, tspan_y)


def has_single_child(data: _elkjs.ELKInputData | _elkjs.ELKInputChild) -> bool:
"""Checks if ``data`` has a single or no child."""
if not data.children:
return True

for child in data.children:
if not has_single_child(child):
return False

return len(data.children) == 1
Loading

0 comments on commit b95f27d

Please sign in to comment.