Choreo.FSM.Render.Mermaid (Choreo v0.8.0)

Copy Markdown View Source

Mermaid.js rendering for Choreo.FSM state-machine diagrams.

Produces classic state-machine visualisation:

  • Normal states — filled circles
  • Initial states — filled circles with a black entry-point dot
  • Final states — circles with thick stroke (double-circle equivalent)
  • Transitions — labeled arrows
  • Layout is left-to-right by default

Themes

  • :default — light grey states, dark text, left-to-right
  • :dark — dark background, neon accents
  • Choreo.Theme struct — full custom control

Examples

iex> fsm = Choreo.FSM.new() |> Choreo.FSM.add_state(:a)
iex> mermaid = Choreo.FSM.Render.Mermaid.to_mermaid(fsm)
iex> String.contains?(mermaid, "graph LR")
true
iex> String.contains?(mermaid, "a")
true

iex> fsm = Choreo.FSM.new() |> Choreo.FSM.add_initial_state(:idle) |> Choreo.FSM.add_final_state(:done)
iex> mermaid = Choreo.FSM.Render.Mermaid.to_mermaid(fsm, syntax: :state_diagram)
iex> String.contains?(mermaid, "stateDiagram-v2")
true
iex> String.contains?(mermaid, "[*] --> idle")
true

Summary

Functions

Returns a theme for Choreo.FSM Mermaid diagrams.

Renders an FSM to a Mermaid diagram string.

Functions

theme(name \\ :default, overrides \\ [])

@spec theme(
  atom(),
  keyword()
) :: Choreo.Theme.t()

Returns a theme for Choreo.FSM Mermaid diagrams.

to_mermaid(fsm, opts \\ [])

@spec to_mermaid(
  Choreo.FSM.t(),
  keyword()
) :: String.t()

Renders an FSM to a Mermaid diagram string.

Options

  • :syntax:flowchart (default) or :state_diagram (native stateDiagram-v2 syntax)
  • :theme:default, :dark, :warm, :forest, :ocean, or a Choreo.Theme struct (for :flowchart syntax)
  • :direction:lr (default), :td, :rl, :bt (for :flowchart syntax)
  • :highlighted_nodes — list of state IDs to highlight (for :flowchart syntax)
  • :highlighted_edges — list of edge IDs or {from, to} tuples to highlight (for :flowchart syntax)
  • Any other option accepted by Yog.Multi.Mermaid.to_mermaid/2