Skip to content

Commit

Permalink
feat(custom_diagram): Add nested recursion and recursion depth
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenngn committed Nov 12, 2024
1 parent 2f29dbe commit ceb0bee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
23 changes: 15 additions & 8 deletions capellambse_context_diagrams/collectors/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def __init__(
self.data = makers.make_diagram(diagram)
self.params = params
self.instructions = self.diagram._collect
self.repeat_instructions: dict[str, t.Any] | None = None
self.repeat_instructions: list[dict[str, t.Any]] = []
self.repeat_depth: list[int] = []
self.visited: set[str] = set()
self.boxes: dict[str, _elkjs.ELKInputChild] = {}
self.edges: dict[str, _elkjs.ELKInputEdge] = {}
Expand Down Expand Up @@ -105,15 +106,21 @@ def _matches_filters(
def _perform_get(
self, obj: m.ModelElement, instructions: dict[str, t.Any]
) -> None:
if instructions.pop("repeat", False):
self.repeat_instructions = instructions
if max_depth := instructions.get("repeat", None):
if self.repeat_instructions:
self.repeat_depth[-1] -= 1
if self.repeat_depth[-1] == 0:
self.repeat_instructions.pop()
else:
self.repeat_instructions.append(instructions)
self.repeat_depth.append(max_depth)
if insts := instructions.get("get"):
create = False
elif insts := instructions.get("include"):
create = True
if not insts:
if self.repeat_instructions:
self._perform_get(obj, self.repeat_instructions)
self._perform_get(obj, self.repeat_instructions[-1])
return
if isinstance(insts, dict):
insts = [insts]
Expand Down Expand Up @@ -206,14 +213,14 @@ def _make_edge_and_ports(
tgt_obj = edge_obj.target
src_owner = src_obj.owner
tgt_owner = tgt_obj.owner
src_owners = list(generic.get_all_owners(src_obj))
tgt_owners = list(generic.get_all_owners(tgt_obj))
if self.diagram._hide_direct_children:
if (
getattr(src_owner, "owner", None) == self.boxable_target
or getattr(tgt_owner, "owner", None) == self.boxable_target
self.boxable_target.uuid in src_owners
or self.boxable_target.uuid in tgt_owners
):
return None
src_owners = list(generic.get_all_owners(src_obj))
tgt_owners = list(generic.get_all_owners(tgt_obj))
if self.diagram._display_parent_relation:
common_owner = None
for owner in src_owners:
Expand Down
4 changes: 0 additions & 4 deletions capellambse_context_diagrams/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ class ContextDiagram(m.AbstractDiagram):
* display_unused_ports - Display ports that are not connected to an edge.
"""

_collect: dict[str, t.Any]
_display_symbols_as_boxes: bool
_display_parent_relation: bool
_hide_direct_children: bool
Expand All @@ -281,7 +280,6 @@ class ContextDiagram(m.AbstractDiagram):
_port_label_position: str
_transparent_background: bool
_display_unused_ports: bool
_unify_edge_direction: str

def __init__(
self,
Expand All @@ -301,7 +299,6 @@ def __init__(
self._elk_input_data: CollectorOutputData | None = None
self.__filters: cabc.MutableSet[str] = self.FilterSet(self)
self._default_render_parameters = {
"collect": {},
"display_symbols_as_boxes": False,
"display_parent_relation": False,
"hide_direct_children": False,
Expand All @@ -311,7 +308,6 @@ def __init__(
"port_label_position": _elkjs.PORT_LABEL_POSITION.OUTSIDE.name,
"display_unused_ports": False,
"transparent_background": False,
"unify_edge_direction": "NONE",
} | default_render_parameters

if standard_filter := STANDARD_FILTERS.get(class_):
Expand Down
3 changes: 2 additions & 1 deletion docs/custom_diagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ get:
## Collector definition
- `get` element at attribute defined in `name`
- `include` element at attribute defined in `name`
- `include` element at attribute defined in `name` or all elements if element is a list as boxes or edges
- `filter` elements if element is a list
- `repeat` elements if for n times

## API Usage

Expand Down

0 comments on commit ceb0bee

Please sign in to comment.