Skip to content

Commit

Permalink
docs: Add docs and tests for display_port_labels
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenngn committed Sep 18, 2024
1 parent f9ed91e commit 9f72324
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/extras/styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,22 @@ Style your diagram elements ([ElkChildType][capellambse_context_diagrams.seriali
<img src="../../assets/images/Context of Lost red junction.svg" width="1000000">
<figcaption>Context diagram of Lost SystemFunction with junction point styling</figcaption>
</figure>

# Display Port Labels

The `display_port_labels` render parameter allows you to display the port labels and `port_label_position` allows you to set the position of the port labels.

??? example display port labels for "Hierarchical diagram"

``` py
import capellambse

model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
obj = model.by_uuid("16b4fcc5-548d-4721-b62a-d3d5b1c1d2eb")
diagram = obj.context_diagram.render("svgdiagram", display_port_labels=True)
diagram.save(pretty=True)
```
<figure markdown>
<img src="assets/images/Context of Hierarchy display_port_labels.svg" width="1000000">
<figcaption>Context diagram of Hierarchy LogicalComponenet with type [LAB] display_port_labels</figcaption>
</figure>
14 changes: 14 additions & 0 deletions docs/gen_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ def generate_no_edgelabel_image(uuid: str) -> None:
)


def generate_display_port_labels_image(uuid: str) -> None:
cdiagram: context.ContextDiagram = model.by_uuid(uuid).context_diagram
cdiagram.invalidate_cache()
filename = " ".join((str(dest / cdiagram.name), "display_port_labels"))
with mkdocs_gen_files.open(f"{filename}.svg", "w") as fd:
print(
cdiagram.render(
"svg", display_port_labels=True, transparent_background=False
),
file=fd,
)


def generate_filter_image(
uuid: str, filter_name: str, suffix: str = ""
) -> None:
Expand Down Expand Up @@ -198,6 +211,7 @@ def generate_interface_with_hide_interface_image():

wizard_uuid = general_context_diagram_uuids["educate Wizards"]
generate_no_edgelabel_image(wizard_uuid)
generate_display_port_labels_image(hierarchy_context)

lost_uuid = general_context_diagram_uuids["Lost"]
generate_filter_image(lost_uuid, filters.EX_ITEMS, "ex")
Expand Down
14 changes: 14 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
CAP_EXPLOIT = "4513c8cd-b94b-4bde-bd00-4c18aaf600ff"
FNC_UUID = "a5642060-c9cc-4d49-af09-defaa3024bae"
INTERF_UUID = "9cbdd233-aff5-47dd-9bef-9be1277c77c3"
HIERARCHY_UUID = "16b4fcc5-548d-4721-b62a-d3d5b1c1d2eb"

Types = list[
t.Union[crosslayer.fa.FunctionalExchange, crosslayer.fa.ComponentExchange]
Expand Down Expand Up @@ -201,3 +202,16 @@ def test_context_diagrams_no_edgelabels_render_param_is_applied(
for aedge in adiag:
if isinstance(aedge, diagram.Edge):
assert not aedge.labels


def test_context_diagrams_display_port_labels_render_param_is_applied(
model: MelodyModel,
) -> None:
obj = model.by_uuid(HIERARCHY_UUID)
diag: context.ContextDiagram = obj.context_diagram

adiag = diag.render(None, display_port_labels=True)

for aport in adiag:
if isinstance(aport, diagram.Box) and aport.port:
assert aport.floating_labels

0 comments on commit 9f72324

Please sign in to comment.