diff --git a/docs/extras/styling.md b/docs/extras/styling.md index 439711be..2d106c5c 100644 --- a/docs/extras/styling.md +++ b/docs/extras/styling.md @@ -131,3 +131,22 @@ Style your diagram elements ([ElkChildType][capellambse_context_diagrams.seriali
Context diagram of Lost SystemFunction with junction point styling
+ +# 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) + ``` +
+ +
Context diagram of Hierarchy LogicalComponenet with type [LAB] display_port_labels
+
diff --git a/docs/gen_images.py b/docs/gen_images.py index 0e525526..0f13f1dd 100644 --- a/docs/gen_images.py +++ b/docs/gen_images.py @@ -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: @@ -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") diff --git a/tests/test_filters.py b/tests/test_filters.py index 64acf6ba..dfbeda48 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -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] @@ -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