Skip to contents

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")

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".

Value

A caugi_mermaid object containing the Mermaid representation.

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.

Examples

cg <- caugi(
  A %-->% B + C,
  B %-->% D,
  C %-->% D,
  class = "DAG"
)

# Get Mermaid string
mmd <- to_mermaid(cg)
mmd@content
#> [1] "flowchart TD\n  A --> B\n  A --> C\n  B --> D\n  C --> D"

# With custom direction
mmd <- to_mermaid(cg, direction = "LR")