Converts a caugi graph to the Mermaid flowchart format as a string.
Mermaid diagrams can be rendered in Quarto, R Markdown, GitHub, and
many other platforms.
Usage
to_mermaid(x, direction = "TD")
Value
A caugi_mermaid object containing the Mermaid representation.
Arguments
x
A caugi object.
direction
Graph direction: "TB" (top-bottom), "TD" (top-down),
"BT" (bottom-top), "LR" (left-right), or "RL" (right-left).
Default is "TD".
Details
The function handles different edge types:
Directed edges (-->) use --> in Mermaid
Undirected edges (---) use --- in Mermaid
Bidirected edges (<->) use <--> in Mermaid
Partial edges (o->) use o--> in Mermaid (circle end)
Node names are automatically escaped if they contain special characters.
cg <- caugi(
A %-->% B + C,
B %-->% D,
C %-->% D,
class = "DAG")
# Get Mermaid stringmmd <- to_mermaid(cg)
mmd@content
# With custom directionmmd <- to_mermaid(cg, direction = "LR")