Skip to content

Commit

Permalink
fix: Fix owner label placing for hierarchical exchanges
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenngn committed May 9, 2024
1 parent 456a630 commit 861511d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 31 deletions.
47 changes: 20 additions & 27 deletions capellambse_context_diagrams/collectors/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ def collector(
ex_datas: list[generic.ExchangeData] = []
edges: common.ElementList[fa.AbstractExchange]
for ex in (edges := list(chain.from_iterable(connections.values()))):
if (
is_hierarchical := exchanges.is_hierarchical(ex, centerbox)
) and not diagram.include_inner_objects:
continue
if is_hierarchical := exchanges.is_hierarchical(ex, centerbox):
if diagram.display_parent_relation:
centerbox["labels"][0][
"layoutOptions"
] = makers.DEFAULT_LABEL_LAYOUT_OPTIONS
if not diagram.include_inner_objects:
continue
if not is_hierarchical or not diagram.display_parent_relation:
elkdata = data
else:
Expand All @@ -59,11 +62,22 @@ def collector(
made_boxes = {centerbox["id"]: centerbox}
to_delete = set()
to_delete.add(centerbox["id"])

def _make_box_and_update_globals(
obj: t.Any,
**kwargs: t.Any,
) -> _elkjs.ELKInputChild:
box = makers.make_box(
obj,
**kwargs,
)
global_boxes[obj.uuid] = box
made_boxes[obj.uuid] = box
return box

if diagram.display_parent_relation and diagram.target.owner:
box = _make_box_and_update_globals(
diagram.target.owner,
global_boxes,
made_boxes,
no_symbol=diagram.display_symbols_as_boxes,
layout_options=makers.DEFAULT_LABEL_LAYOUT_OPTIONS,
)
Expand Down Expand Up @@ -94,8 +108,6 @@ def collector(
else:
box = _make_box_and_update_globals(
child,
global_boxes,
made_boxes,
height=height,
no_symbol=diagram.display_symbols_as_boxes,
)
Expand All @@ -111,8 +123,6 @@ def collector(
if not (parent_box := global_boxes.get(current.owner.uuid)):
parent_box = _make_box_and_update_globals(
current.owner,
global_boxes,
made_boxes,
no_symbol=diagram.display_symbols_as_boxes,
layout_options=makers.DEFAULT_LABEL_LAYOUT_OPTIONS,
)
Expand Down Expand Up @@ -143,8 +153,6 @@ def collector(
if not (parent_box := global_boxes.get(current.owner.uuid)):
parent_box = _make_box_and_update_globals(
current.owner,
global_boxes,
made_boxes,
no_symbol=diagram.display_symbols_as_boxes,
layout_options=makers.DEFAULT_LABEL_LAYOUT_OPTIONS,
)
Expand Down Expand Up @@ -173,21 +181,6 @@ def collector(
return data


def _make_box_and_update_globals(
obj: t.Any,
global_boxes: dict[str, _elkjs.ELKInputChild],
made_boxes: dict[str, _elkjs.ELKInputChild],
**kwargs: t.Any,
) -> _elkjs.ELKInputChild:
box = makers.make_box(
obj,
**kwargs,
)
global_boxes[obj.uuid] = box
made_boxes[obj.uuid] = box
return box


def port_collector(
target: common.GenericElement | common.ElementList, diagram_type: DT
) -> list[common.GenericElement]:
Expand Down
33 changes: 29 additions & 4 deletions tests/test_context_diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ def test_include_inner_objects_in_context_diagram(
model: capellambse.MelodyModel,
) -> None:
obj = model.by_uuid(TEST_HIERARCHY_UUID)
expected_children = TEST_HIERARCHY_CHILDREN_UUIDS

adiag = obj.context_diagram.render(None, include_inner_objects=True)
obj.context_diagram.render("svgdiagram", include_inner_objects=True).save(
Expand All @@ -149,15 +148,14 @@ def test_include_inner_objects_in_context_diagram(

children = {obj.uuid for obj in adiag[TEST_HIERARCHY_UUID].children}

for uuid in expected_children:
for uuid in TEST_HIERARCHY_CHILDREN_UUIDS:
assert uuid in children


def test_exclude_inner_objects_in_context_diagram(
model: capellambse.MelodyModel,
) -> None:
obj = model.by_uuid(TEST_HIERARCHY_UUID)
expected_children = TEST_HIERARCHY_CHILDREN_UUIDS

adiag = obj.context_diagram.render(None, include_inner_objects=False)
obj.context_diagram.render("svgdiagram", include_inner_objects=False).save(
Expand All @@ -166,10 +164,37 @@ def test_exclude_inner_objects_in_context_diagram(

children = {obj.uuid for obj in adiag[TEST_HIERARCHY_UUID].children}

for uuid in expected_children:
for uuid in TEST_HIERARCHY_CHILDREN_UUIDS:
assert uuid not in children


def test_exclude_inner_objects_and_hide_parent_relation_in_context_diagram(
model: capellambse.MelodyModel,
) -> None:
obj = model.by_uuid(TEST_HIERARCHY_UUID)

adiag = obj.context_diagram.render(
None,
display_parent_relation=False,
include_inner_objects=False,
depth=2,
)
obj.context_diagram.render(
"svgdiagram",
display_parent_relation=False,
include_inner_objects=False,
depth=2,
).save(pretty=True)

for uuid in TEST_HIERARCHY_CHILDREN_UUIDS:
with pytest.raises(KeyError):
adiag[uuid] # pylint: disable=pointless-statement

for uuid in TEST_HIERARCHY_PARENTS_UUIDS:
with pytest.raises(KeyError):
adiag[uuid] # pylint: disable=pointless-statement


def test_parent_relation_in_context_diagram(
model: capellambse.MelodyModel,
) -> None:
Expand Down

0 comments on commit 861511d

Please sign in to comment.