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

Hit-testing (spec/03 §4): keyed elements, the hit index, and the client inversion
attributes.

- **Keys** (§4.1): every element a layer draws from a row carries its key: the layer
  group's `data-frame` and `data-layer` (`key_layer/3`), the element's `data-row` (its
  row's ordinal in the layer's realized rows, `key_row/2`). `resolve/2` answers a key
  against the realized rows the Frame holds, typed as the delivery holds them, never
  from the attribute text; a key it no longer holds is `:none`.
- **The hit index** (§4.2, `index/1`): one entry per layer with keyed elements, in
  drawing order, each item its row and its shape in the frame's units with every group
  transform composed in: `[row, "r", x, y, w, h]`, `[row, "c", cx, cy, r]`, `[row, "p",
  x, y, w, h, d, [a, b, c, d, e, f], filled, stroke_width]`. It is model-independent,
  built after the bend, the projection or the layout. `topmost/2` is the item the client
  picks: the last entry's last item holding the point.
- **Inversion attributes** (§4.3, `attrs/1`): `data-mw-x` and `data-mw-y`,
  `d0,d1,x0,x1,width` of a linear or time scale in component pixels, and `data-mw-plot`.

Copied from visualize's `Visualize.Hooks.Tooltip.Items` (server side) and
`Visualize.Chart.Frame.sync_attrs/1` and `brush_attrs/1`.

# `key`

```elixir
@type key() :: %{required(String.t()) =&gt; String.t()}
```

A key as the client sends it: the frame, the layer and the row, as attribute text.

# `attrs`

```elixir
@spec attrs(term()) :: %{required(String.t()) =&gt; String.t()}
```

The inversion attributes a frame group carries (§4.3): `data-mw-x` and `data-mw-y`,
`d0,d1,x0,x1,width` of the frame's `x` and `y` when each is a linear or a time scale
(time in milliseconds since the epoch, pixels in the component's coordinates, the
frame's box offset and margin included), and `data-mw-plot`, `x0,y0,x1,y1` of the plot.

# `index`

```elixir
@spec index(term()) :: [map()]
```

The hit index of a scene (§4.2): `[%{frame, layer, items}]` in drawing order, items as
the module says, `[]` for a scene with no keyed element.

# `json`

```elixir
@spec json(term()) :: String.t()
```

The hit index as the JSON the client's hook reads.

# `key_layer`

```elixir
@spec key_layer(term(), term(), term()) ::
  Macaw.Draw.IR.Element.t() | {:error, list()}
```

A layer's group keyed with its frame's name and its position among the frame's layers.

# `key_row`

```elixir
@spec key_row(term(), term()) :: Macaw.Draw.IR.Element.t() | {:error, list()}
```

An element drawn from the row at `ordinal` of its layer's realized rows, keyed.

# `resolve`

```elixir
@spec resolve(term(), term()) :: {:ok, map()} | :none
```

The row a key names (§4.1): `{:ok, row}`, the typed row of the layer's realized rows
(`rows` is `%{{frame, layer} => table}`, the rows the Frame's contained value holds),
or `:none` for a key it no longer holds or cannot read.

# `topmost`

```elixir
@spec topmost(term(), term()) :: {non_neg_integer(), non_neg_integer()} | :none
```

The item a point in the frame's units lands on (§4.2): `{layer, row}` of the topmost
item holding it (the last entry, its last item), or `:none`. A path holds the point by
its box here; the client tests its `d`.

---

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