|
1
|
|
|
from typing import Any |
|
2
|
|
|
|
|
3
|
|
|
import networkx_mermaid as nxm |
|
4
|
|
|
|
|
5
|
|
|
from .. import color |
|
6
|
|
|
from ..enums import GraphType |
|
7
|
|
|
from ..modeling import GraphModel |
|
8
|
|
|
from ._networkx import NetworkxBuilder |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class MermaidBuilder(NetworkxBuilder): |
|
12
|
|
|
"""Build a Mermaid Graph""" |
|
13
|
|
|
|
|
14
|
|
|
def __init__(self, model: GraphModel, graph_type: GraphType = GraphType.Graph): |
|
15
|
|
|
super().__init__(model, graph_type) |
|
16
|
|
|
|
|
17
|
|
|
def build(self, |
|
18
|
|
|
orientation: nxm.DiagramOrientation = nxm.DiagramOrientation.LEFT_RIGHT, |
|
19
|
|
|
node_shape: nxm.DiagramNodeShape = nxm.DiagramNodeShape.DEFAULT, |
|
20
|
|
|
title: str | None = None, |
|
21
|
|
|
with_edge_labels: bool = False, |
|
22
|
|
|
**kwargs: Any) -> nxm.typing.MermaidDiagram: |
|
23
|
|
|
""" |
|
24
|
|
|
Build a Mermaid Graph |
|
25
|
|
|
|
|
26
|
|
|
Args: |
|
27
|
|
|
orientation : Orientation, optional |
|
28
|
|
|
The orientation of the graph, by default Orientation.LEFT_RIGHT. |
|
29
|
|
|
node_shape : NodeShape, optional |
|
30
|
|
|
The shape of the nodes, by default NodeShape.DEFAULT. |
|
31
|
|
|
title: str, optional |
|
32
|
|
|
The title of the graph (default: None). |
|
33
|
|
|
If None, the graph name will be used if available. |
|
34
|
|
|
Supplying and empty string will remove the title. |
|
35
|
|
|
with_edge_labels: |
|
36
|
|
|
Whether to include edge labels, by default False. |
|
37
|
|
|
**kwargs: additional inputs to the node and edge generator functions |
|
38
|
|
|
|
|
39
|
|
|
Returns: |
|
40
|
|
|
Mermaid Graph |
|
41
|
|
|
""" |
|
42
|
|
|
super().build(**kwargs) |
|
43
|
|
|
color.convert_colors_to_hex(self._graph) |
|
44
|
|
|
nxm_builder = nxm.DiagramBuilder(orientation=orientation, node_shape=node_shape) |
|
45
|
|
|
return nxm_builder.build(self._graph, title=title, with_edge_labels=with_edge_labels) |
|
46
|
|
|
|