# Flame graph

A run's activity as nested blocks: the orchestrator over its subagents and their model and tool calls, each as wide as it took, with zoom, crumbs and a search.

Live variants: https://design.arcadia.is/components/flame-graph

```tsx
import { FlameGraph } from "@arcadia/ui/charts";
```

Compare time, tokens or cost. Select a parent span to zoom into its calls.

```tsx
import { FlameGraph } from "@arcadia/ui/charts";

<div {...sx("cmp-flame-graph-full", s.full)}>
  <FlameGraph label="Ship the release" root={RUN} formatCost={cost} />
</div>
```

## Accessibility

The plot is a grid, its rows the levels and its cells the spans. A cell's name is the span's whole line, its name, kind, parent, time and the tokens and cost recorded for it, with the reason where it failed, and the plot itself is named by the run's sentence. A span with nothing inside it is no button: it reads as its line and does nothing. A span that holds others is a button whose name ends with what pressing it does.

The grid is one Tab stop. Left and Right move along a row, Up goes to the span that holds the focused one, Down to its first child, and Home and End to the ends of its row; Enter or Space presses the focused span and Escape goes back a level. A span pressed with the keyboard keeps the focus after the view changes, and the crumb it returns through is a button in the toolbar.

The search's count is a live status, announced after a pause in typing, and its words are on the same line while the pointer is elsewhere. Every span's name carries its time, its tokens and its cost where recorded, so nothing depends on a block's width or on colour alone; a failed span's reason is in its name, and a match is a border as well as a lit fill. Under forced colours the blocks take the system's canvas and ink, and a match takes the highlight.

## API reference

### FlameGraph

- `label` (`string`, required): Its name: the run's ("Ship v2.4"). It names the chart to a reader and stands as the first crumb.
- `root` (`FlameSpan`): The run's first span, the one that holds the rest. Absent while loading or when nothing was recorded.
- `metric` (`"time" | "tokens" | "cost"`): The metric the blocks are as wide as, held by the product. A metric the data does not record is never drawn.
- `defaultMetric` (`"time" | "tokens" | "cost"`, default `"time"`): The metric it starts on, held by the part.
- `onMetricChange` (`(metric: FlameMetric) => void`): The metric chosen, by the control or by the product.
- `formatCost` (`(amount: number) => string`): Writes a cost, in the unit the data carries, such as dollars ($). Required to offer cost at all: without it, no cost is drawn.
- `query` (`string`): The search text, held by the product.
- `defaultQuery` (`string`, default `""`): The search it starts with, held by the part.
- `onQueryChange` (`(query: string) => void`): The search written.
- `loading` (`boolean`, default `false`): Loading: the toolbar, the crumbs and the field, and after 200ms a still block where the rows go.
- `empty` (`{ title: string; action?: ReactNode }`): Nothing given: the empty state's words, in the product's terms, and its one way to start.
- `error` (`{ message: string; readout?: string }`): It failed: what happened and what to do, and the machine's own message as a readout, with Retry (onRetry).
- `onRetry` (`() => void`): Retry after an error.
- `rootStyle` (`RootStyle<FlameGraphKnobs>`): Typed StyleX override: where it sits and its --flame-row and --flame-h knobs.

Rest props go to `HTMLAttributes<HTMLDivElement>`.
