Skip to content

Commit

Permalink
feat(context-diagrams): Add display_parent_relation feature
Browse files Browse the repository at this point in the history
This moves the centerbox into another box if it is the parent of the centerbox.
  • Loading branch information
ewuerger committed Feb 14, 2024
1 parent 5cb386e commit 912dcb0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
34 changes: 34 additions & 0 deletions capellambse_context_diagrams/collectors/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ def collector(
box["ports"] = [makers.make_port(j.uuid) for j in local_ports]
if i.parent.uuid == centerbox["id"]:
child_boxes.append(box)
elif (
diagram.display_parent_relation and i == diagram.target.parent
):
box["children"] = [centerbox]
global_boxes[i.uuid] = box
del data["children"][0]
_move_edge_to_local_edges(
box, connections, local_ports, diagram, data
)
else:
global_boxes[i.uuid] = box

Expand All @@ -87,6 +96,31 @@ def collector(
return data


def _move_edge_to_local_edges(
box: _elkjs.ELKInputChild,
connections: list[common.GenericElement],
local_ports: list[common.GenericElement],
diagram: context.ContextDiagram,
data: _elkjs.ELKInputData,
) -> None:
edges_to_remove: list[str] = []
for c in connections:
if (
c.target in local_ports
and c.source in diagram.target.ports
or c.source in local_ports
and c.target in diagram.target.ports
):
for edge in data["edges"]:
if edge["id"] == c.uuid:
box.setdefault("edges", []).append(edge)
edges_to_remove.append(edge["id"])

data["edges"] = [
e for e in data["edges"] if e["id"] not in edges_to_remove
]


def port_collector(
target: common.GenericElement | common.ElementList, diagram_type: DT
) -> list[common.GenericElement]:
Expand Down
5 changes: 5 additions & 0 deletions capellambse_context_diagrams/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ class ContextDiagram(diagram.AbstractDiagram):
avoids the object of interest to become one giant, oversized
symbol in the middle of the diagram, and instead keeps the
symbol small and only enlarges the surrounding box.
display_parent_relation
Display objects with a parent relationship to the object of
interest as the parent box.
slim_center_box
Minimal width for the center box, containing just the icon and
the label. This is False if hierarchy was identified.
Expand All @@ -253,6 +256,7 @@ def __init__(
*,
render_styles: dict[str, styling.Styler] | None = None,
display_symbols_as_boxes: bool = False,
display_parent_relation: bool = False,
include_inner_objects: bool = False,
slim_center_box: bool = True,
) -> None:
Expand All @@ -264,6 +268,7 @@ def __init__(
self.serializer = serializers.DiagramSerializer(self)
self.__filters: cabc.MutableSet[str] = self.FilterSet(self)
self.display_symbols_as_boxes = display_symbols_as_boxes
self.display_parent_relation = display_parent_relation
self.include_inner_objects = include_inner_objects
self.slim_center_box = slim_center_box

Expand Down

0 comments on commit 912dcb0

Please sign in to comment.