<!-- https://tinyactors.dev/cli/commands/graph/ -->
# tinyactors graph

Kind: reference. For: [Workflow developer who tests](https://tinyactors.dev/audiences/workflow-tester.xml), [Agent-platform engineer](https://tinyactors.dev/audiences/agent-platform.xml).
Voice: [Reference](https://tinyactors.dev/voices/reference.xml).

> Draw each chart, or list its boxes and edges.

Draw each chart, or list its boxes and edges.

<a id="usage"></a>

## Usage

```shell
tinyactors graph [options] INPUT...
```

Lays each chart out as nested boxes for its states and orthogonal routes for its transitions. With `-f` svg it writes the picture; the other formats list each box and edge. Reads one image (`.tai`), one snapshot, one system manifest or SCXML charts, compiled together into one image first. `--segment` picks a snapshot's image, and - reads standard input.

<a id="options"></a>

## Options

- **`-W, --warnings-as-errors`**: Refuse a chart that compiles with a warning.
- **`-I, --include DIR`**: Search `DIR` for a src that is not beside the file naming it, in the order given. Repeatable.
- **`-c, --chart NAME`**: Look at the chart named `NAME` only. Repeatable.
- **`-s, --segment N`**: Read the image that segment N of a snapshot runs. Default: the newest live segment.
- **`--direction DIRECTION`**: Lay the states out in `DIR`ECTION. Values: down (top to bottom) or right (left to right). Default: down.
- **`--theme THEME`**: Draw the colours of `THEME` with `-f` svg. Values: auto (the reader's preference), light or dark. Default: auto.
- **`--highlight STATE`**: Mark the box of `STATE`. Repeatable.
- **`--path`**: Mark the path the path command finds to `--to` from `--from`, its steps numbered.
- **`-t, --to STATE`**: End the path of `--path` at `STATE`.
- **`--from STATE`**: Start the path of `--path` at `STATE`. Default: the initial configuration.
- **`-d, --depth N`**: Fold every compound or parallel state nested deeper than N levels into one box.
- **`--fold STATE`**: Fold the compound or parallel state `STATE` into one box. Repeatable.

Configure output formats like `-f json` using the [shared options on the command reference](https://tinyactors.dev/cli/commands/index.md#program-options).

<a id="examples"></a>

## Examples

```shell
tinyactors graph -f svg order.scxml > order.svg
```

Draw a chart as SVG.

![tinyactors graph -f svg order.scxml > order.svg](https://tinyactors.dev/cli/commands/examples/graph-1-order.svg)

```shell
tinyactors graph -f svg --chart payment shop.tai > payment.svg
```

Draw one chart of an image.

![tinyactors graph -f svg --chart payment shop.tai > payment.svg](https://tinyactors.dev/cli/commands/examples/graph-2-payment.svg)

```shell
tinyactors graph -f svg --direction right --theme dark order.scxml > order.svg
```

Draw a chart left to right in dark colours.

![tinyactors graph -f svg --direction right --theme dark order.scxml > order.svg](https://tinyactors.dev/cli/commands/examples/graph-3-order.svg)

```shell
tinyactors graph -f svg --path --to shipped --highlight cancelled order.scxml > shipping.svg
```

Mark the path to shipped and highlight cancelled.

![tinyactors graph -f svg --path --to shipped --highlight cancelled order.scxml > shipping.svg](https://tinyactors.dev/cli/commands/examples/graph-4-shipping.svg)

```shell
tinyactors graph -f svg --depth 1 --fold checkout shop.scxml > overview.svg
```

Fold states nested deeper than one level, and checkout.

![tinyactors graph -f svg --depth 1 --fold checkout shop.scxml > overview.svg](https://tinyactors.dev/cli/commands/examples/graph-5-overview.svg)

```shell
tinyactors graph -f json order.tai
```

```text title="output"
{
  "charts": [
    {
      "name": "order",
      "width": 821,
      "height": 432,
      "boxes": [
        {
          "state": "/scxml",
          "kind": "compound",
          "parent": "",
          "drawnAs": "root",
          "x": 0,
          "y": 0,
          "width": 821,
          "height": 432
        },
        {
          "state": "open",
          "kind": "atomic",
          "parent": "/scxml",
          "drawnAs": "atomic",
          "x": 508,
          "y": 40,
          "width": 276,
          "height": 58
        },
        {
          "state": "paying",
          "kind": "atomic",
          "parent": "/scxml",
          "drawnAs": "atomic",
          "x": 278,
          "y": 160,
          "width": 480,
          "height": 34
        },
        {
          "state": "paid",
          "kind": "atomic",
          "parent": "/scxml",
          "drawnAs": "atomic",
          "x": 413,
          "y": 298,
          "width": 78,
          "height": 34
        },
        {
          "state": "shipped",
          "kind": "final",
          "parent": "/scxml",
          "drawnAs": "final",
          "x": 414,
          "y": 384,
          "width": 77,
          "height": 34
        },
        {
          "state": "cancelled",
          "kind": "final",
          "parent": "/scxml",
          "drawnAs": "final",
          "x": 592,
          "y": 298,
          "width": 92,
          "height": 34
        }
      ],
      "edges": [
        {
          "source": "open",
          "target": "paying",
          "events": "checkout",
          "condition": "total > 0",
          "drawnAs": "forward",
          "route": "518,98 518,160"
        },
        {
          "source": "open",
          "target": "cancelled",
          "events": "cancel",
          "condition": "",
          "drawnAs": "forward",
          "route": "726,98 726,150 781,150 781,288 667,288 667,298"
        },
        {
          "source": "paying",
          "target": "paid",
          "events": "charge.ok",
          "condition": "",
          "drawnAs": "forward",
          "route": "398,194 398,278 452,278 452,298"
        },
        {
          "source": "paying",
          "target": "paying",
          "events": "charge.declined error.communication payment.timeout",
          "condition": "attempts < 3",
          "drawnAs": "self",
          "route": "463,194 463,210 573,210 573,194"
        },
        {
          "source": "paying",
          "target": "cancelled",
          "events": "charge.declined error.communication payment.timeout",
          "condition": "",
          "drawnAs": "forward",
          "route": "638,194 638,298"
        },
        {
          "source": "paid",
          "target": "shipped",
          "events": "shipped",
          "condition": "",
          "drawnAs": "forward",
          "route": "452,332 452,384"
        }
      ],
      "inside": [
        {
          "state": "open",
          "events": "item.added",
          "condition": "_event.data.price > 0",
          "targets": ""
        }
      ],
      "problems": [
        {
          "kind": "labelOnEdge",
          "subject": "paying → paying on charge.declined error.communication payment.timeout",
          "touches": "paying → paid on charge.ok"
        },
        {
          "kind": "labelOnEdge",
          "subject": "paying → cancelled on charge.declined error.communication payment.timeout",
          "touches": "open → cancelled on cancel"
        }
      ]
    },
    {
      "name": "payment",
      "width": 242,
      "height": 290,
      "boxes": [
        {
          "state": "/scxml",
          "kind": "compound",
          "parent": "",
          "drawnAs": "root",
          "x": 0,
          "y": 0,
          "width": 242,
          "height": 290
        },
        {
          "state": "pending",
          "kind": "atomic",
          "parent": "/scxml",
          "drawnAs": "atomic",
          "x": 64,
          "y": 40,
          "width": 164,
          "height": 34
        },
        {
          "state": "authorized",
          "kind": "atomic",
          "parent": "/scxml",
          "drawnAs": "atomic",
          "x": 37,
          "y": 136,
          "width": 130,
          "height": 34
        },
        {
          "state": "settled",
          "kind": "final",
          "parent": "/scxml",
          "drawnAs": "final",
          "x": 14,
          "y": 242,
          "width": 77,
          "height": 34
        },
        {
          "state": "declined",
          "kind": "final",
          "parent": "/scxml",
          "drawnAs": "final",
          "x": 109,
          "y": 242,
          "width": 85,
          "height": 34
        }
      ],
      "edges": [
        {
          "source": "pending",
          "target": "authorized",
          "events": "authorize",
          "condition": "",
          "drawnAs": "forward",
          "route": "102,74 102,136"
        },
        {
          "source": "pending",
          "target": "declined",
          "events": "decline",
          "condition": "",
          "drawnAs": "forward",
          "route": "189,74 189,126 190,126 190,232 177,232 177,242"
        },
        {
          "source": "authorized",
          "target": "settled",
          "events": "capture",
          "condition": "",
          "drawnAs": "forward",
          "route": "53,170 53,242"
        },
        {
          "source": "authorized",
          "target": "declined",
          "events": "void",
          "condition": "",
          "drawnAs": "forward",
          "route": "138,170 138,242"
        }
      ],
      "inside": [],
      "problems": []
    }
  ]
}
```

List the boxes and edges of an image's charts as JSON.

<a id="exit-status"></a>

## Exit status

- **`1`**: An input is refused: it does not compile or verify, or it is damaged or of an unknown format.
- **`1`**: With `--path`, no path reaches the `--to` state in any chart drawn.
- **`3`**: A file cannot be read or written, or memory runs out.

<a id="see"></a>

## Related pages

- **[`tinyactors states`](https://tinyactors.dev/cli/commands/states/index.md)**: List each chart's states as a tree in document order.
- **[`tinyactors transitions`](https://tinyactors.dev/cli/commands/transitions/index.md)**: List each chart's transitions with events, conditions and targets.
- **[`tinyactors events`](https://tinyactors.dev/cli/commands/events/index.md)**: List every event name and the transitions, raises and sends using it.
- **[`tinyactors data`](https://tinyactors.dev/cli/commands/data/index.md)**: List each chart's data declarations.
- **[`tinyactors expressions`](https://tinyactors.dev/cli/commands/expressions/index.md)**: List each chart's expressions and scripts with where they are.
- **[`tinyactors path`](https://tinyactors.dev/cli/commands/path/index.md)**: Find the shortest path to a state: events, conditions and transitions.
- **[`tinyactors disassemble`](https://tinyactors.dev/cli/commands/disassemble/index.md)**: List each chart's executable content instruction by instruction.
- **[`tinyactors inspect`](https://tinyactors.dev/cli/commands/inspect/index.md)**: Show what an image, a snapshot or a blob holds.

## Commands

- [tinyactors compile](https://tinyactors.dev/cli/commands/compile/)
- [tinyactors check](https://tinyactors.dev/cli/commands/check/)
- [tinyactors inspect](https://tinyactors.dev/cli/commands/inspect/)
- [tinyactors states](https://tinyactors.dev/cli/commands/states/)
- [tinyactors transitions](https://tinyactors.dev/cli/commands/transitions/)
- [tinyactors events](https://tinyactors.dev/cli/commands/events/)
- [tinyactors data](https://tinyactors.dev/cli/commands/data/)
- [tinyactors expressions](https://tinyactors.dev/cli/commands/expressions/)
- [tinyactors disassemble](https://tinyactors.dev/cli/commands/disassemble/)
- [tinyactors graph](https://tinyactors.dev/cli/commands/graph/)
- [tinyactors diff](https://tinyactors.dev/cli/commands/diff/)
- [tinyactors lint](https://tinyactors.dev/cli/commands/lint/)
- [tinyactors path](https://tinyactors.dev/cli/commands/path/)
- [tinyactors fmt](https://tinyactors.dev/cli/commands/fmt/)
- [tinyactors actors](https://tinyactors.dev/cli/commands/actors/)
- [tinyactors run](https://tinyactors.dev/cli/commands/run/)
- [tinyactors help](https://tinyactors.dev/cli/commands/help/)
- [tinyactors version](https://tinyactors.dev/cli/commands/version/)
