Skip to content

Commit

Permalink
docs(custom_diagram): Add example to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenngn committed Dec 9, 2024
1 parent ad39f99 commit d2162d4
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion docs/custom_diagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,37 @@
`Custom diagram`s let's you create custom diagrams based on the data in the model. You define the data collection using an iterable and `Custom diagram` takes care of the rest.
You can access `.custom_diagram` on any supported model element.

??? example "Custom Diagram of `PP 1 `"

``` py
import capellambse

visited = set()

def _collector(
target: m.ModelElement,
) -> cabc.Iterator[m.ModelElement]:
if target.uuid in visited:
return
visited.add(target.uuid)
for link in target.links:
yield link
yield from _collector(link.source)
yield from _collector(link.target)


model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
obj = model.by_uuid("c403d4f4-9633-42a2-a5d6-9e1df2655146")
diag = obj.context_diagram
diag.render("svgdiagram", collect=_collector(obj)).save(pretty=True)
```
<figure markdown>
<img src="assets/images/Context of PP 1.svg" width="1000000">
<figcaption>Context of PP 1 [PAB]</figcaption>
</figure>

## Check out the code

To understand the collection have a look into the
[`cable_tree`][capellambse_context_diagrams.collectors.cable_tree]
[`custom`][capellambse_context_diagrams.collectors.custom]
module.

0 comments on commit d2162d4

Please sign in to comment.