Skip to content

styling

Functions for style overrides of diagram elements.

BLUE_ACTOR_FNCS module-attribute 🔗

BLUE_ACTOR_FNCS: dict[str, Styler] = {'node': parent_is_actor_fills_blue}

CSSStyle for coloring Actor Functions (Functions of Components with the attribute is_actor set to True) with a blue gradient like in Capella.

CSSStyles module-attribute 🔗

CSSStyles = StyleOverrides | None

A dictionary with CSS styles. The keys are the attribute names and the values can be of the types str, aird.RGB and even t.Sequence[aird.RGB] for coloring a ModelElement with a gradient.

See also

parent_is_actor_fills_blue

SYSTEM_CAP_STYLING module-attribute 🔗

SYSTEM_CAP_STYLING: dict[str, Styler] = {'node': style_center_symbol}

CSSStyle for custom styling of SystemAnalysis diagrams.

The center box is drawn with a white background and a grey dashed line.

Styler module-attribute 🔗

Styler = Callable[
    [ModelElement, "serializers.DiagramSerializer"], StyleOverrides | None
]

Function that produces CSSStyles for given obj.

PVMTObjectType 🔗

Bases: str, Enum

Enumeration of object types for PVMT styling.

get_styleoverrides_from_pvmt 🔗

get_styleoverrides_from_pvmt(
    obj: ModelElement, pvmt_styling: _PVMTStyling, obj_type: PVMTObjectType
) -> diagram.StyleOverrides

Return PVMT StyleOverrides for a model element.

If children_coloring is enabled and the element has no direct PVMT styling, it will inherit styling from the nearest parent element that has PVMT styling.

Source code in src/capellambse_context_diagrams/styling.py
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
def get_styleoverrides_from_pvmt(
    obj: m.ModelElement,
    pvmt_styling: _PVMTStyling,
    obj_type: PVMTObjectType,
) -> diagram.StyleOverrides:
    """Return PVMT ``StyleOverrides`` for a model element.

    If ``children_coloring`` is enabled and the element has no direct
    PVMT styling, it will inherit styling from the nearest parent
    element that has PVMT styling.
    """
    direct_styles = _extract_direct_pvmt_styles(obj, pvmt_styling, obj_type)
    if direct_styles or not pvmt_styling.children_coloring:
        return direct_styles

    return _extract_inherited_pvmt_styles(obj, pvmt_styling, obj_type)

normalize_pvmt_styling 🔗

normalize_pvmt_styling(
    pvmt_styling: dict[str, Any] | list[str] | str | None,
) -> dict[str, t.Any] | None

Normalize pvmt_styling parameter to dict format.

Notes

The following ways of providing pvmt_styling are accepted:

  • dict: {"value_groups": [...], "children_coloring": ...}
  • list: ["group1", "group2"]
  • str: "group1"
  • None: None
Source code in src/capellambse_context_diagrams/styling.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
def normalize_pvmt_styling(
    pvmt_styling: dict[str, t.Any] | list[str] | str | None,
) -> dict[str, t.Any] | None:
    """Normalize ``pvmt_styling`` parameter to dict format.

    Notes
    -----
    The following ways of providing ``pvmt_styling`` are accepted:

    * dict: {"value_groups": [...], "children_coloring": ...}
    * list: ["group1", "group2"]
    * str: "group1"
    * None: None
    """
    if pvmt_styling is None:
        return None

    if isinstance(pvmt_styling, dict):
        if "value_groups" not in pvmt_styling:
            raise ValueError(
                "pvmt_styling dict must contain 'value_groups' key"
            )
        return pvmt_styling

    if isinstance(pvmt_styling, list):
        return {"value_groups": pvmt_styling}

    if isinstance(pvmt_styling, str):
        return {"value_groups": [pvmt_styling]}

    raise TypeError(
        "pvmt_styling must be dict, list, str or None!"
        f" got {type(pvmt_styling)!r}"
    )

parent_is_actor_fills_blue 🔗

parent_is_actor_fills_blue(
    obj: ModelElement, serializer: DiagramSerializer
) -> CSSStyles

Return CSSStyles for given obj rendering it blue.

Source code in src/capellambse_context_diagrams/styling.py
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def parent_is_actor_fills_blue(
    obj: m.ModelElement, serializer: serializers.DiagramSerializer
) -> CSSStyles:
    """Return ``CSSStyles`` for given ``obj`` rendering it blue."""
    del serializer
    try:
        if obj.owner.is_actor:
            return {
                "fill": [
                    capstyle.COLORS["_CAP_Actor_Blue_min"],
                    capstyle.COLORS["_CAP_Actor_Blue"],
                ],
                "stroke": capstyle.COLORS["_CAP_Actor_Border_Blue"],
            }
    except AttributeError:
        pass

    return None

style_center_symbol 🔗

style_center_symbol(
    obj: ModelElement, serializer: DiagramSerializer
) -> CSSStyles

Return CSSStyles for given obj.

Source code in src/capellambse_context_diagrams/styling.py
135
136
137
138
139
140
141
142
143
144
145
def style_center_symbol(
    obj: m.ModelElement, serializer: serializers.DiagramSerializer
) -> CSSStyles:
    """Return ``CSSStyles`` for given ``obj``."""
    if obj != serializer._diagram.target:
        return None
    return {
        "fill": capstyle.COLORS["white"],
        "stroke": capstyle.COLORS["gray"],
        "stroke-dasharray": "3",
    }