# `Macaw.Frame.Hooks.Items`
[🔗](https://github.com/dcoai/macaw_frame/blob/v0.1.0/lib/macaw/frame/hooks/items.ex#L1)

The hit index of a canvas drawing (spec/10 §7.3), copied from visualize's
`Visualize.Hooks.Tooltip.Items`: what `FrameTooltip` reads on a canvas, where no element
carries an item, so a click at one point emits the same event on SVG, the canvas
commands and the binary canvas.

`index(scene)` answers one entry per layer with an event (`data-tooltip-event` or
`data-tooltip-context-event` on its group), `%{"event", "context", "frame", "items"}`,
each item the keyed element's (`data-mw-item`)
`[item, identity, value, "r", x, y, w, h]`, `[item, identity, value, "c", cx, cy, r]`
or `[item, identity, value, "p", x, y, w, h, d, [a, b, c, d, e, f], filled, width]`,
`identity` the declared identity (`data-mw-identity`) or `null` and `value` the
declared fields' pairs (`data-mw-value`), in the chart's user units under every
transform above it, grown by half its stroke width, built from the same scene the
canvas stream is. `json/1` writes it as `data-mw-items` takes it.

# `index`

```elixir
@spec index(Macaw.Draw.IR.Element.t()) :: [map()] | {:error, [Macaw.Base.Fault.t()]}
```

The hit index of a scene: one entry per layer with an event, in drawing order.

# `json`

```elixir
@spec json(Macaw.Draw.IR.Element.t()) :: String.t() | {:error, [Macaw.Base.Fault.t()]}
```

The hit index as the JSON text of `data-mw-items`.

    iex> Macaw.Frame.Hooks.Items.json(Macaw.Draw.IR.Element.group([]))
    "[]"

# `pieces`

```elixir
@spec pieces(Macaw.Draw.IR.Element.t(), map(), pos_integer()) ::
  {[{String.t(), String.t()}], map()} | {:error, [Macaw.Base.Fault.t()]}
```

The hit index as keyed pieces, `{[{key, json}], cache}`: each a JSON object of one
layer's entry, `{"layer", "event", "context", "frame", "items"}`, holding a run of at
most `size` of its items, keyed by the layer and the run. The hook joins a layer's pieces
back into one entry in order, so a move that changes one item resends one piece, never
the index (spec/10 §6). `cache` is the last call's: an item whose element, transform and
paint equal the last drawing's at its place reuses the text written then. It is an
economy only: the pieces are the same with `%{}`.

---

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