Phoenix LiveView hook that reaches a chart's points from the keyboard (spec/10 §17, spec/14 §21.5, D-142).
KeyboardHook makes the chart one tab stop. Inside it the arrow keys move between the
points of a series and between series, Home and End jump to a series' ends, and a polite
live region reads the point: y, 3 of 51: x 2, y 54.3. Like CrosshairHook it never
reads the chart's DOM: attrs/1 writes every point once on the server — its readout and
its position in the chart's pixels — so the same attributes serve a chart drawn as SVG
and one on a canvas. The live region and the focus marker are appended to
document.body, so a LiveView patch of the chart neither removes nor sees them.
A board adds the order across its cells one level up: each cell one stop, or, when the
board moves between cells with arrows, Escape inside a chart hands focus back to the
nearest element carrying data-vis-cell.
Usage
<div id="chart-keys" phx-hook="KeyboardHook" {Visualize.Hooks.Keyboard.attrs(applied)}>
{Phoenix.HTML.raw(@svg)}
</div>Configuration
Data attributes on the container, from attrs/1 (spec/10 §17.2):
data-keyboard-name- the chart's namedata-keyboard-points- per series,{"name", "points": [[x, y, readout], …]}data-size-width,heightof the chart
Set by the host:
data-keyboard-event- the event pushed with{series, index}when the focused point changes; unset, nothing is pusheddata-keyboard-pick-event- the event pushed with{series, index}when a point is picked: Enter at the reached point, or a click, which picks the point nearest to it (spec/10 §17.3, spec/15 §13); unset, nothing is pickeddata-keyboard-target- thephx-targetboth events go to withpushEventTo; unset, they go to the LiveView
Summary
Functions
The data attributes of spec/10 §17.2 for an applied chart, computed once: its name, its points by series with their readouts and positions, and its size.
Returns the JavaScript source of KeyboardHook.
Functions
@spec attrs(Visualize.Chart.Applied.t()) :: %{required(String.t()) => String.t()}
The data attributes of spec/10 §17.2 for an applied chart, computed once: its name, its points by series with their readouts and positions, and its size.
Returns the JavaScript source of KeyboardHook.