Skip to content

Commit

Permalink
fix: Fix Styling
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenngn committed Sep 18, 2024
1 parent da45d02 commit c0f6bb0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 69 deletions.
114 changes: 46 additions & 68 deletions capellambse_context_diagrams/collectors/exchange_item_relation_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,15 @@

DEFAULT_LAYOUT_OPTIONS: _elkjs.LayoutOptions = {
"algorithm": "layered",
"layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
"elk.direction": "RIGHT",
"layered.nodePlacement.strategy": "LINEAR_SEGMENTS",
"edgeStraightening": "NONE",
"spacing.labelNode": "0.0",
"nodeSize.constraints": "NODE_LABELS",
"aspectRatio": 1000,
"layered.considerModelOrder.strategy": "PREFER_NODES",
"layered.considerModelOrder.components": "MODEL_ORDER",
"edgeRouting": "ORTHOGONAL",
}

DEFAULT_EDGE_LAYOUT_OPTIONS: _elkjs.LayoutOptions = {
"spacing.edgeLabel": "0.0",
"layered.edgeLabels.sideSelection": "SMART_DOWN",
}

DEFAULT_TREE_VIEW_LAYOUT_OPTIONS: _elkjs.LayoutOptions = {
"algorithm": "layered",
"elk.direction": "DOWN",
"layered.edgeLabels.sideSelection": "ALWAYS_DOWN",
"edgeRouting": "POLYLINE",
"nodeSize.constraints": "NODE_LABELS",
"partitioning.active": True,
"hierarchyHandling": "INCLUDE_CHILDREN",
"layered.spacing.edgeEdgeBetweenLayers": "2.0",
}


Expand All @@ -51,32 +39,15 @@ def __init__(
self.data = makers.make_diagram(diagram)
self.data.layoutOptions = DEFAULT_LAYOUT_OPTIONS
self.params = params or {}
self.tree_view_box = _elkjs.ELKInputChild(
id="__HideElement:tree-view",
layoutOptions=DEFAULT_TREE_VIEW_LAYOUT_OPTIONS,
children=[],
edges=[],
)
self.left_box = _elkjs.ELKInputChild(
id="__HideElement:left",
layoutOptions=_elkjs.get_global_layered_layout_options(),
children=[],
edges=[],
)
self.right_box = _elkjs.ELKInputChild(
id="__HideElement:right",
layoutOptions=_elkjs.get_global_layered_layout_options(),
children=[],
edges=[],
)
self.global_boxes: dict[str, _elkjs.ELKInputChild] = {}
self.classes: dict[str, information.Class] = {}
self.edges: dict[str, list[_elkjs.ELKInputEdge]] = {}

def __call__(self) -> _elkjs.ELKInputData:
if not self.diagram.target.allocated_exchange_items:
if not self.diagram.target.exchange_items:
logger.warning("No exchange items to display")
return self.data
for item in self.diagram.target.allocated_exchange_items:
for item in self.diagram.target.exchange_items:
if not (parent_box := self.global_boxes.get(item.parent.uuid)):
parent_box = self.global_boxes.setdefault(
item.parent.uuid,
Expand All @@ -85,55 +56,62 @@ def __call__(self) -> _elkjs.ELKInputData:
layout_options=makers.DEFAULT_LABEL_LAYOUT_OPTIONS,
),
)
self.left_box.children.append(parent_box)

if item.uuid in (i.id for i in parent_box.children):
continue
box = makers.make_box(item)
parent_box.children.append(box)

for elem in item.elements:
if elem.abstract_type:
self.classes.setdefault(
elem.abstract_type.uuid, elem.abstract_type
)
eid = f"__ExchangeItemElement:{item.uuid}_{elem.abstract_type.uuid}"
self.data.edges.append(
_elkjs.ELKInputEdge(
id=eid,
layoutOptions=DEFAULT_EDGE_LAYOUT_OPTIONS,
sources=[item.uuid],
targets=[elem.abstract_type.uuid],
# Add back labels once edge label issue is fixed
# labels=makers.make_label(elem.name),
)
)
if elem.abstract_type is None:
continue
self.classes.setdefault(
elem.abstract_type.uuid, elem.abstract_type
)
eid = f"__ExchangeItemElement:{item.uuid}_{elem.abstract_type.uuid}"
edge = _elkjs.ELKInputEdge(
id=eid,
sources=[item.uuid],
targets=[elem.abstract_type.uuid],
labels=makers.make_label(
elem.name,
),
)
self.data.edges.append(edge)
self.edges.setdefault(item.parent.uuid, []).append(edge)

for cls in self.classes.values():
box = self._make_class_box(cls)
partition = 0
current = cls
while current.super and current.super.uuid in self.classes:
partition += 1
current = current.super
box.layoutOptions["partitioning.partition"] = partition
self.tree_view_box.children.append(box)
if partition > 0:
self.data.children.append(box)
if cls.super:
eid = f"__Generalization:{cls.super.uuid}_{cls.uuid}"
self.tree_view_box.edges.append(
self.data.edges.append(
_elkjs.ELKInputEdge(
id=eid,
sources=[cls.super.uuid],
targets=[cls.uuid],
)
)

while len(self.left_box.children) > len(self.right_box.children):
box = self.left_box.children.pop()
self.right_box.children.append(box)
top = sum(len(box.children) for box in self.global_boxes.values())
mid = top / 2
ordered = list(self.global_boxes.keys())
for uuid in ordered:
if top < mid:
break
self.data.edges.append(
_elkjs.ELKInputEdge(
id=f"__Hide{uuid}",
sources=[uuid],
targets=[ordered[-1]],
)
)
for edge in self.edges.get(uuid, []):
edge.sources, edge.targets = edge.targets, edge.sources
edge.id = f"__Reverse-{edge.id[2:]}"
top -= len(self.global_boxes[uuid].children)

self.data.children.extend(
[self.left_box, self.tree_view_box, self.right_box]
)
self.data.children.extend(self.global_boxes.values())
return self.data

def _make_class_box(self, cls: information.Class) -> _elkjs.ELKInputChild:
Expand Down
9 changes: 8 additions & 1 deletion capellambse_context_diagrams/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ class type that stores all previously named classes.
uuid: str
styleclass: str | None
derived = False
reverse = False

if child.id.startswith("__HideElement"):
if child.id.startswith("__Hide"):
if hasattr(child, "position"):
ref = ref + (child.position.x, child.position.y)
for i in getattr(child, "children", []):
Expand All @@ -147,6 +148,9 @@ class type that stores all previously named classes.
if styleclass.startswith("Derived-"):
styleclass = styleclass.removeprefix("Derived-")
derived = True
elif styleclass.startswith("Reverse-"):
styleclass = styleclass.removeprefix("Reverse-")
reverse = True
else:
styleclass = self.get_styleclass(child.id)
uuid = child.id
Expand Down Expand Up @@ -201,6 +205,9 @@ class type that stores all previously named classes.
if target_id.startswith("__"):
target_id = target_id[2:].split(":", 1)[-1]

if reverse:
source_id, target_id = target_id, source_id

if child.routingPoints:
refpoints = [
ref + (point.x, point.y) for point in child.routingPoints
Expand Down

0 comments on commit c0f6bb0

Please sign in to comment.