From e91ef8d2e94f93f9c0d6d4bfbcc1173a31ada6e5 Mon Sep 17 00:00:00 2001 From: ewuerger Date: Thu, 22 Feb 2024 15:59:59 +0100 Subject: [PATCH] fix(tree-view): Fix direction of `Generalization` edges --- .../collectors/tree_view.py | 10 +++++----- capellambse_context_diagrams/serializers.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/capellambse_context_diagrams/collectors/tree_view.py b/capellambse_context_diagrams/collectors/tree_view.py index 75732b76..29b8f57d 100644 --- a/capellambse_context_diagrams/collectors/tree_view.py +++ b/capellambse_context_diagrams/collectors/tree_view.py @@ -80,8 +80,8 @@ def process_class(self, cls, params): self.data["edges"].append( { "id": edge.uuid, - "sources": [cls.generalizes.uuid], - "targets": [cls.source.uuid], + "sources": [cls.source.uuid], + "targets": [cls.generalizes.uuid], } ) @@ -122,9 +122,9 @@ def collector( """Return the class tree data for ELK.""" assert isinstance(diagram.target, information.Class) data = generic.collector(diagram, no_symbol=True) - all_associations: cabc.Iterable[information.Association] = ( - diagram._model.search("Association") - ) + all_associations: cabc.Iterable[ + information.Association + ] = diagram._model.search("Association") _set_layout_options(data, params) processor = ClassProcessor(data, all_associations) processor._set_data_types_and_labels(data["children"][0], diagram.target) diff --git a/capellambse_context_diagrams/serializers.py b/capellambse_context_diagrams/serializers.py index bae440ac..f88f074c 100644 --- a/capellambse_context_diagrams/serializers.py +++ b/capellambse_context_diagrams/serializers.py @@ -9,6 +9,7 @@ """ from __future__ import annotations +import collections.abc as cabc import logging import typing as t @@ -149,6 +150,8 @@ class type that stores all previously named classes. elif child["type"] == "edge": styleclass = child.get("styleclass", styleclass) # type: ignore[assignment] styleclass = REMAP_STYLECLASS.get(styleclass, styleclass) # type: ignore[arg-type] + EDGE_HANDLER.get(styleclass, lambda c: c)(child) + if child["routingPoints"]: refpoints = [ ref + (point["x"], point["y"]) @@ -315,3 +318,16 @@ def route_shortest_connection( line_end, source=line_start, style=diagram.RoutingStyle.OBLIQUE ) return [source_intersection, target_intersection] + + +def reverse_edge_refpoints(child: _elkjs.ELKOutputEdge) -> None: + source = child["sourceId"] + target = child["targetId"] + child["targetId"] = source + child["sourceId"] = target + child["routingPoints"] = child["routingPoints"][::-1] + + +EDGE_HANDLER: dict[str, cabc.Callable[[_elkjs.ELKOutputEdge], None]] = { + "Generalization": reverse_edge_refpoints +}