Skip to content

Commit

Permalink
refactor(context): Apply changes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger committed Feb 26, 2024
1 parent e0299f6 commit 236e1c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions capellambse_context_diagrams/collectors/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ def collector(
"output": -makers.NEIGHBOR_VMARGIN,
}
child_boxes: list[_elkjs.ELKInputChild] = []
for i, local_ports, side in port_context_collector(ex_datas, ports):
_, label_height = helpers.get_text_extent(i.name)
for child, local_ports, side in port_context_collector(ex_datas, ports):
_, label_height = helpers.get_text_extent(child.name)
height = max(
label_height + 2 * makers.LABEL_VPAD,
makers.PORT_PADDING
+ (makers.PORT_SIZE + makers.PORT_PADDING) * len(local_ports),
)
if box := global_boxes.get(i.uuid): # type: ignore[assignment]
if box := global_boxes.get(child.uuid): # type: ignore[assignment]
if box is centerbox:
continue
box.setdefault("ports", []).extend(
Expand All @@ -76,23 +76,25 @@ def collector(
box["height"] += height
else:
box = makers.make_box(
i, height=height, no_symbol=diagram.display_symbols_as_boxes
child,
height=height,
no_symbol=diagram.display_symbols_as_boxes,
)
box["ports"] = [makers.make_port(j.uuid) for j in local_ports]
if i.parent.uuid == centerbox["id"]:
if child.parent.uuid == centerbox["id"]:
child_boxes.append(box)
else:
global_boxes[i.uuid] = box
global_boxes[child.uuid] = box

if diagram.display_parent_relation:
if i == diagram.target.parent:
if child == diagram.target.parent:
_move_edge_to_local_edges(
box, connections, local_ports, diagram, data
)
elif i.parent == diagram.target.parent:
parent_box = global_boxes[i.parent.uuid]
elif child.parent == diagram.target.parent:
parent_box = global_boxes[child.parent.uuid]
parent_box.setdefault("children", []).append(
global_boxes.pop(i.uuid)
global_boxes.pop(child.uuid)
)
_move_edge_to_local_edges(
parent_box, connections, local_ports, diagram, data
Expand Down
2 changes: 1 addition & 1 deletion capellambse_context_diagrams/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def deserialize_child(
class type that stores all previously named classes.
"""
styleclass: str | None = self.get_styleclass(child["id"])
element: diagram.Box | diagram.Edge
element: diagram.Box | diagram.Edge | diagram.Circle
if child["type"] in {"node", "port"}:
assert parent is None or isinstance(parent, diagram.Box)
has_symbol_cls = False
Expand Down

0 comments on commit 236e1c0

Please sign in to comment.