Skip to content

default

Build an ELK diagram from collected capellambse context.

This submodule provides a collector that transforms capellambse data to an ELK- layouted diagram _elkjs.ELKInputData.

The data was collected with the functions from collectors.

DiagramBuilder 🔗

DiagramBuilder(diagram: ContextDiagram, params: dict[str, Any])

Collect the context for a ContextDiagram.

Source code in src/capellambse_context_diagrams/builders/default.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
def __init__(
    self,
    diagram: context.ContextDiagram,
    params: dict[str, t.Any],
) -> None:
    self.diagram = diagram
    self.collection = self.diagram._collect(self.diagram)
    self.target: m.ModelElement = self.diagram.target
    self.boxable_target = _get_boxeable_target(self.diagram)
    self.data = _makers.make_diagram(diagram)
    self.params = params

    self.boxes: dict[str, _elkjs.ELKInputChild] = {}
    self.edges: dict[str, _elkjs.ELKInputEdge] = {}
    self.ports: dict[str, _elkjs.ELKInputPort] = {}

    self.boxes_to_delete: set[str] = set()
    self.edges_to_flip: dict[str, dict[bool, set[str]]] = {}
    self.min_heights: dict[str, dict[str, float]] = {}
    self.directions: dict[str, bool] = {}
    self.diagram_target_owners: list[str] = list(
        _generic.get_all_owners(self.boxable_target)
    )

    if self.diagram._display_parent_relation:
        self.edge_owners: dict[str, str] = {}
        self.common_owners: set[str] = set()

    self.max_depth: int = sys.maxsize
    if self.diagram._mode == enums.MODE.GREYBOX:
        self.max_depth = 1

    if self.diagram._edge_direction in {
        enums.EDGE_DIRECTION.RIGHT,
        enums.EDGE_DIRECTION.LEFT,
        enums.EDGE_DIRECTION.TREE,
    }:
        self.data.layoutOptions["layered.nodePlacement.strategy"] = (
            "NETWORK_SIMPLEX"
        )
    if self.diagram._edge_direction in {
        enums.EDGE_DIRECTION.RIGHT,
        enums.EDGE_DIRECTION.LEFT,
    }:
        self.directions[self.boxable_target.uuid] = (
            self.diagram._edge_direction == enums.EDGE_DIRECTION.LEFT
        )

builder 🔗

builder(
    diagram: ContextDiagram,
    params: dict[str, Any],
    builder_type: type[DiagramBuilder] = DiagramBuilder,
) -> _elkjs.ELKInputData

High level builder function to build collected data for ELK.

PARAMETER DESCRIPTION
diagram

The ContextDiagram instance to get the _elkjs.ELKInputData for.

TYPE: ContextDiagram

params

Optional render params dictionary.

TYPE: dict[str, Any]

builder_type

The type of diagram builder to use.

TYPE: type[DiagramBuilder] DEFAULT: DiagramBuilder

RETURNS DESCRIPTION
elkdata

The data that can be fed into elkjs.

Source code in src/capellambse_context_diagrams/builders/default.py
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
def builder(
    diagram: context.ContextDiagram,
    params: dict[str, t.Any],
    builder_type: type[DiagramBuilder] = DiagramBuilder,
) -> _elkjs.ELKInputData:
    """High level builder function to build collected data for ELK.

    Parameters
    ----------
    diagram
        The [`ContextDiagram`][capellambse_context_diagrams.context.ContextDiagram]
        instance to get the
        [`_elkjs.ELKInputData`][capellambse_context_diagrams._elkjs.ELKInputData]
        for.
    params
        Optional render params dictionary.
    builder_type
        The type of diagram builder to use.

    Returns
    -------
    elkdata
        The data that can be fed into elkjs.
    """
    return builder_type(diagram, params)()

get_top_uncommon_owner 🔗

get_top_uncommon_owner(
    src: ModelElement, tgt_owners: list[str]
) -> m.ModelElement

Return the top-level owner of src not in tgt_owners.

Source code in src/capellambse_context_diagrams/builders/default.py
57
58
59
60
61
62
63
64
65
66
67
68
69
def get_top_uncommon_owner(
    src: m.ModelElement, tgt_owners: list[str]
) -> m.ModelElement:
    """Return the top-level owner of ``src`` not in ``tgt_owners``."""
    current = src
    while (
        hasattr(current, "owner")
        and current.owner is not None
        and current.owner.uuid not in tgt_owners
        and not isinstance(current.owner, _makers.PackageTypes)
    ):
        current = current.owner
    return current