mbdlyb_ui.mermaid
Copyright (c) 2026 TNO-ESI All rights reserved.
Attributes
Classes
Build interactive Mermaid flowcharts from graph-backed networks. |
Module Contents
- class mbdlyb_ui.mermaid.MermaidBuilder(net: mbdlyb.gdb.GMBDNet, attributes: dict[type[mbdlyb.gdb.GMBDElement], list[str | tuple[str, bool]] | tuple[list[RelationSpec], list[RelationSpec]]], color_map: mbdlyb.colormap.ColorMap, label_map: dict[type[mbdlyb.gdb.GMBDRelation], str] | None = None, direction: str = 'LR')
Build interactive Mermaid flowcharts from graph-backed networks.
- add_element(e: mbdlyb.gdb.GMBDNode, url: str | None = None) str
Append a styled node and optional click handler to the diagram.
- Parameters:
e – Node to display.
url – Optional destination emitted on a node click.
- Returns:
The node’s Mermaid identifier.
- add_to_tree(element: mbdlyb.gdb.GMBDElement) str
Insert an element under its relative FQN path in the diagram tree.
- Parameters:
element – Model element to place in its containing subgraph.
- Returns:
The inserted element’s Mermaid identifier.
- add_tree(t: dict, in_current_view: bool = False)
Render a nested tree as subgraphs and clickable nodes.
- Parameters:
t – Nested mapping of IDs and labels to nodes or child mappings.
in_current_view – Whether node links should remain in this network.
- build() str
Traverse the network and render the complete Mermaid flowchart.
- Returns:
Mermaid source with subgraphs, nodes, class colors, and edges.
- draw_mermaid_diagram(save_button: nicegui.ui.menu_item)
Render the chart and wire its navigation and SVG export events.
- Parameters:
save_button – Menu item that initiates an SVG download.
- static m_id(n: mbdlyb.gdb.GMBDElement | str) str
Convert an element’s FQN or string into a Mermaid-safe identifier.
- Parameters:
n – Model element or raw identifier.
- Returns:
An identifier containing only word characters.
- static m_name(n: mbdlyb.gdb.GMBDElement | str, quote: bool = True) str
Escape a label for inclusion in a Mermaid diagram.
- Parameters:
n – Model element or raw label.
quote – Whether to surround the escaped label in double quotes.
- Returns:
The HTML-escaped, optionally quoted label.
- static m_url(element: mbdlyb.gdb.GMBDElement, in_current_view: bool) str | None
Choose the navigation target for a diagram element.
- Parameters:
element – Element for which to resolve a URL.
in_current_view – Whether the element belongs to the displayed network.
- Returns:
A resolved URL, or None when no URL is configured.
- reset()
Clear chart text and traversal state before a new build.
- type mbdlyb_ui.mermaid.BaseRelationSpec = tuple[type[GMBDDependency], str]
- type mbdlyb_ui.mermaid.RelationSpec = BaseRelationSpec | tuple[type[GMBDDependency], str, tuple[list[BaseRelationSpec], list[BaseRelationSpec]]]