Skip to content

Commit

Permalink
docs: Update custom_diagram docs
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Lehmann <[email protected]>
  • Loading branch information
huyenngn and Wuestengecko committed Dec 16, 2024
1 parent d2162d4 commit 51772a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
5 changes: 1 addition & 4 deletions capellambse_context_diagrams/collectors/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
"""This module defines the collector for the CustomDiagram."""
from __future__ import annotations

import builtins
import collections.abc as cabc
import copy
import typing as t

import capellambse
import capellambse.model as m

from .. import _elkjs, context
Expand All @@ -33,7 +30,7 @@ class CustomCollector:

def __init__(
self,
diagram: context.CustomDiagram,
diagram: context.ContextDiagram,
params: dict[str, t.Any],
) -> None:
self.diagram = diagram
Expand Down
25 changes: 14 additions & 11 deletions docs/custom_diagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,30 @@

# Custom Diagram

`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.
`Custom diagram`s let 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)

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)
yield from collector(target)

model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
obj = model.by_uuid("c403d4f4-9633-42a2-a5d6-9e1df2655146")
Expand Down

0 comments on commit 51772a8

Please sign in to comment.