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

The crosshair's data arrays (spec/10 §7.4), copied from visualize's
`Visualize.Hooks.Crosshair` (its `attrs/3` and `at_resolution/3`): `FrameCrosshair` snaps
a rule and a marker per series to the nearest x of arrays the server wrote once, so it
serves SVG and canvas alike (visualize D-76).

`attrs(value, layer)` answers `{:ok, attrs}` for a cartesian layer with `x` and `y`
channels, `{:error, :not_cartesian}` for a layer of a polar, geographic, layout or
facet frame, `{:error, :no_xy}` for one without both channels or not drawn
(visualize raised `ArgumentError`):

- `data-mw-xs`: the distinct x pixels, ascending, plot coordinates, **at the frame's
  resolution** (`at_resolution/3`);
- `data-mw-ys`: one array per series parallel to them, `null` where a series has none;
- `data-mw-plot`: `left,top,width,height`; `data-mw-size`: the frame's size;
- `data-mw-hover` (`Macaw.Frame.Hooks.States`) and `data-mw-x` for the bus
  (`Macaw.Frame.Hit.attrs/1`).

The arrays are read from the layer's placement, the pixel columns the realization
placed once (`Macaw.Frame.Placements`), never from rows (spec/12 §3).

# `at_resolution`

```elixir
@spec at_resolution([number()], number(), number()) :: [number()]
```

Distinct ascending x pixels kept at `resolution` over a plot `width` (visualize #1065,
D-269): with more values than the plot has device-pixel columns, each column keeps the
x nearest its center, and its lowest when the column before it holds none and its
highest when the column after it holds none; with no more values than columns every one
is kept.

    iex> Macaw.Frame.Hooks.Crosshair.at_resolution([0.1, 0.4, 0.6, 2.2], 1, 1)
    [0.1, 0.6, 2.2]

# `attrs`

```elixir
@spec attrs(Macaw.Frame.Value.t(), non_neg_integer(), keyword()) ::
  {:ok, [{String.t(), String.t()}]} | {:error, :not_cartesian | :no_xy}
```

The crosshair's attributes for the layer of index `layer` of `value`'s drawing; with
`arrays: false` every attribute but `data-mw-xs` and `data-mw-ys`, reading no pixel: a
crosshair no client has armed (spec/10 §7, visualize #1066).

---

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