View source: R/format-mermaid.R
| to_mermaid | R Documentation |
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.
to_mermaid(x, direction = "TD")
x |
A |
direction |
Graph direction: "TB" (top-bottom), "TD" (top-down), "BT" (bottom-top), "LR" (left-right), or "RL" (right-left). Default is "TD". |
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 tail)
Partial edges (--o) use --o in Mermaid (circle head)
Partial edges (o-o) use o--o in Mermaid (circle both ends)
Node names are automatically escaped if they contain special characters.
A caugi_mermaid object containing the Mermaid representation.
Other export:
caugi_deserialize(),
caugi_dot(),
caugi_export(),
caugi_graphml(),
caugi_mermaid(),
caugi_serialize(),
export-classes,
format-caugi,
format-dot,
format-graphml,
format-mermaid,
knit_print.caugi_export(),
read_caugi(),
read_graphml(),
to_dot(),
to_graphml(),
write_caugi(),
write_dot(),
write_graphml(),
write_mermaid()
cg <- caugi(
A %-->% B + C,
B %-->% D,
C %-->% D,
class = "DAG"
)
# Get Mermaid string
mmd <- to_mermaid(cg)
mmd@content
# With custom direction
mmd <- to_mermaid(cg, direction = "LR")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.