From 912dcb0de0d53928bf996be644b51b8b7072311d Mon Sep 17 00:00:00 2001 From: ewuerger Date: Wed, 14 Feb 2024 15:36:29 +0100 Subject: [PATCH] feat(context-diagrams): Add `display_parent_relation` feature This moves the centerbox into another box if it is the parent of the centerbox. --- .../collectors/default.py | 34 +++++++++++++++++++ capellambse_context_diagrams/context.py | 5 +++ 2 files changed, 39 insertions(+) diff --git a/capellambse_context_diagrams/collectors/default.py b/capellambse_context_diagrams/collectors/default.py index ec9186c8..2e922dda 100644 --- a/capellambse_context_diagrams/collectors/default.py +++ b/capellambse_context_diagrams/collectors/default.py @@ -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 @@ -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]: diff --git a/capellambse_context_diagrams/context.py b/capellambse_context_diagrams/context.py index ab8b5639..c57b8833 100644 --- a/capellambse_context_diagrams/context.py +++ b/capellambse_context_diagrams/context.py @@ -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. @@ -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: @@ -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