Skip to content

Commit

Permalink
fix: Fix minimum size calculation of boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenngn committed Nov 26, 2024
1 parent 6305008 commit e4dfd0d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
13 changes: 11 additions & 2 deletions capellambse_context_diagrams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,21 @@ def register_cable_tree_view() -> None:
def register_custom_diagram() -> None:
"""Add the `custom_diagram` attribute to `ModelObject`s."""
supported_classes: list[tuple[type[m.ModelElement], DiagramType]] = [
(oa.Entity, DiagramType.OAB),
(oa.OperationalActivity, DiagramType.OAB),
(oa.OperationalCapability, DiagramType.OCB),
(oa.CommunicationMean, DiagramType.OAB),
(sa.Mission, DiagramType.MCB),
(sa.Capability, DiagramType.MCB),
(sa.SystemComponent, DiagramType.SAB),
(sa.SystemFunction, DiagramType.SAB),
(cs.PhysicalLink, DiagramType.PAB),
(la.LogicalComponent, DiagramType.LAB),
(la.LogicalFunction, DiagramType.LAB),
(pa.PhysicalComponent, DiagramType.PAB),
(pa.PhysicalFunction, DiagramType.PAB),
(fa.ComponentExchange, DiagramType.SAB),
(cs.PhysicalLink, DiagramType.PAB),
(cs.PhysicalPort, DiagramType.PAB),
(fa.ComponentExchange, DiagramType.SAB),
]
for class_, dgcls in supported_classes:
m.set_accessor(
Expand Down
5 changes: 5 additions & 0 deletions capellambse_context_diagrams/collectors/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __call__(self) -> _elkjs.ELKInputData:
and getattr(current, "owner", None) is not None
and not isinstance(current.owner, generic.PackageTypes)
):
self.common_owners.discard(current.uuid)
current = self._make_owner_box(current)
self.common_owners.discard(current.uuid)
for edge_uuid, box_uuid in self.edge_owners.items():
Expand Down Expand Up @@ -224,6 +225,10 @@ def _make_owner_box(
break
else:
children.append(obj_box)
obj_box.width = max(
obj_box.width,
parent_box.width,
)
for label in parent_box.labels:
label.layoutOptions = makers.DEFAULT_LABEL_LAYOUT_OPTIONS
self.boxes_to_delete.add(obj.uuid)
Expand Down
11 changes: 1 addition & 10 deletions docs/custom_diagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,9 @@ my_model = capellambse.MelodyModel(...)
my_element = my_model.by_uuid(...)
my_yaml = "..."
my_element.custom_diagram(collect=yaml.safe_load(my_yaml)).render("svgdiagram").save(pretty=True)
my_element.custom_diagram.render("svgdiagram", collect=yaml.safe_load(my_yaml)).save(pretty=True)
```

## Supported Elements

- [`sa.SystemFunction`][capellambse.metamodel.sa.SystemFunction]
- [`cs.PhysicalLink`][capellambse.metamodel.cs.PhysicalFunction]
- [`la.LogicalFunction`][capellambse.metamodel.la.LogicalFunction]
- [`pa.PhysicalFunction`][capellambse.metamodel.pa.PhysicalFunction]
- [`fa.ComponentExchange`][capellambse.metamodel.fa.ComponentExchange]
- [`cs.PhysicalPort`][capellambse.metamodel.cs.PhysicalPort]

## Check out the code

To understand the collection have a look into the
Expand Down

0 comments on commit e4dfd0d

Please sign in to comment.