Skip to main content

Module interaction

Module interaction 

Source
Expand description

Platform-independent input events and the interaction state machine: panning with kinetic scrolling, wheel and pinch zoom, axis dragging, keyboard navigation and the crosshair.

Bindings (winit, DOM, native) translate their events into InputEvents in CSS pixels; the chart multiplies by the device pixel ratio. Input never allocates: the state machine keeps a fixed-size velocity history.

Clock: kinetic scrolling compares time_ms of pointer events with the now_ms passed to Chart::build_frame, so both must come from the same clock (e.g. performance.now() or Instant since start).

With several panes, price-axis drags, wheel zoom over the axis and vertical panning act on the pane under the pointer; dragging a separator resizes the two panes next to it.

Drawings: with a tool armed, clicks create a drawing (click per anchor, or press-drag-release for the first two); otherwise a press on a drawing selects it and drags it (or the handle under the pointer) unless it is locked. Escape cancels, Delete removes the selection, Ctrl/⌘+Z undoes, Ctrl/⌘+Shift+Z and Ctrl/⌘+Y redo.

Structs§

InputResult
Result of Chart::handle_input.
Modifiers
Keyboard modifiers. Plain flags mirror the DOM/winit events they come from.
VelocityTracker
Release velocity of a drag along one axis, from a fixed number of recent pointer samples (no allocation). Used by the chart’s kinetic panning and by ferrochart-plot.

Enums§

Button
Mouse button.
CrosshairMode
Crosshair behavior.
CursorIcon
Mouse cursor the host should show.
GesturePhase
Phase of a continuous gesture.
InputEvent
A platform-independent input event. Positions are in CSS pixels relative to the chart’s top-left corner.
Key
Keys the chart reacts to.
WheelDelta
Scroll amount of a wheel event.

Constants§

KINETIC_MIN_SPEED
Kinetic scrolling starts above / stops below this speed (physical px per ms).
KINETIC_TAU_MS
Kinetic velocity decay time constant: after a release at speed v, the speed is v · exp(-t / KINETIC_TAU_MS).