# `AshWorkflow.Charts`
[🔗](https://github.com/team-alembic/ash_workflow/blob/v0.12.0/lib/ash_workflow/charts.ex#L1)

Draws a workflow as a diagram.

A chart reads the workflow DSL, so it shows which steps are automatic,
manual, wait states or terminal. It labels timeouts with their deadlines,
shows the condition of each route, and draws the moves the generated `undo`
action can make. For a chart of the generated state machine itself, use
`AshStateMachine.Charts`.

    AshWorkflow.Charts.mermaid_state_diagram(MyApp.Candidate)
    AshWorkflow.Charts.render(MyApp.Candidate, :json, pretty: true)

Each format is a module that implements `AshWorkflow.Charts.Backend`, and all
of them draw from the same `AshWorkflow.Charts.Graph`. The formats this
library ships are:

* `:mermaid` — `AshWorkflow.Charts.Mermaid`, a Mermaid `stateDiagram-v2`.
* `:json` — `AshWorkflow.Charts.Json`, plain data for a client that draws
  the workflow itself.
* `:dot` — `AshWorkflow.Charts.Dot`, a Graphviz DOT chart with colour and
  line styles. `svg: true` draws it as SVG with `dot`.

`mix ash_workflow.diagram` writes the same output from the command line.

# `backend!`

```elixir
@spec backend!(term()) :: module()
```

The backend module for a format name, or the module itself when it
implements `AshWorkflow.Charts.Backend`. Raises `ArgumentError` otherwise.

# `formats`

```elixir
@spec formats() :: [atom()]
```

The format names `render/3` accepts in place of a backend module.

# `graph`

```elixir
@spec graph(Ash.Resource.t(), keyword()) :: AshWorkflow.Charts.Graph.t()
```

The diagram model for a resource. See `AshWorkflow.Charts.Graph.build/2`.

# `mermaid_state_diagram`

```elixir
@spec mermaid_state_diagram(Ash.Resource.t(), keyword()) :: String.t()
```

Draws a resource's workflow as a Mermaid `stateDiagram-v2`. The same as
`render(resource, :mermaid, opts)`.

# `render`

```elixir
@spec render(Ash.Resource.t(), atom(), keyword()) :: String.t()
```

Draws a resource's workflow in a format, and returns the diagram as a string.

## Options

`:undo` and `:notes` go to `AshWorkflow.Charts.Graph.build/2`. Every other
option goes to the backend, for example `:pretty` for `:json`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
