Browser interaction and animation
The chart-view interaction layer turns browser input and live chart changes into a stable visual view. It coordinates hover readouts, selections, annotations, view changes, transitions, and frame scheduling so that the chart stays aligned with its data while the browser, kernel, or host framework updates it. This page complements Browser rendering runtime, WebGL rendering resources, Browser worker and kernels, and Interaction and view state.
Interaction model
The chart uses the browser as the first owner of user input. Pointer, wheel, click, keyboard, resize, and focus events are interpreted against the current chart view, then produce local visuals and semantic events for the kernel or host framework when needed. The interaction policy enables or disables capabilities without creating a second view model. References: js/…/50_chartview.ts• L1556-1581, js/…/53_interaction.ts• L231-456, spec/…/interaction.md• L20-75
Gesture paths
The main plot supports navigation, selection, and inspection. A plain drag follows the active drag mode. Shift-drag or a selected tool starts a box, range, or lasso selection. Wheel input zooms around the cursor. A double click resets the configured axes unless the chart is in a selection mode. Axis bands provide the same navigation for one axis at a time.
Gesture coordinate conversion always reads the canvas that is currently attached to the chart. This keeps drag, lasso, and wheel geometry valid after the rendering surface is rebuilt.
References: js/…/53_interaction.ts• L57-76 js/…/53_interaction.ts• L161-173 js/…/53_interaction.ts• L231-456 js/…/57_viewstate.ts• L270-536 spec/…/interaction.md• L281-327
The modebar exposes the same capabilities for users who do not use direct gestures. It offers view history, zoom, reset, and selection tools when the chart policy allows them and when the controls fit inside the plot. The active drag tool is UI state; it does not change the durable view state.
References: js/…/53_interaction.ts• L1170-1181 js/…/53_interaction.ts• L1491-1535 js/…/53_interaction.ts• L1752-1882 spec/…/interaction.md• L348-355
When a gesture owns a pointer, the chart captures that pointer and watches for a lost release. A pan keeps the last view reached before the loss. A selection or box zoom restores its prior committed selection. Re-entering the chart does not resume the old gesture.
References: js/…/50_chartview.ts• L1528-1553 js/…/53_interaction.ts• L188-229 spec/…/interaction.md• L313-327
Hover and picking
Hover maps screen coordinates to a mark or rendered region. The chart uses the pick surface when available and a resident-data fallback for mark types that need geometric hit checks. The result identifies the trace and source row, so filtering or a lower-detail display does not change the meaning of a hover.
References: js/…/50_chartview.ts• L8606-8647 js/…/50_chartview.ts• L8770-8843 spec/…/interaction.md• L155-227
The hover path updates three related outputs: the highlighted mark, the tooltip, and the xy:hover event. A pointer exit clears them and emits xy:leave; a document-level exit check covers cases where the browser skips a canvas boundary event. Keyboard traversal uses the same row and tooltip path, follows data order, and uses Escape to close the readout.
References: js/…/50_chartview.ts• L8981-9079 js/…/53_interaction.ts• L478-616 spec/…/interaction.md• L164-170
The structured hover payload separates cursor position from mark identity. cursor.px is chart-root-relative, cursor.data has one value for each axis ID, and each point includes its trace binding and resolved row. Live charts can replace the first resident-value readout with an exact kernel reply. Static charts keep the resident readout and do not claim an exact upgrade.
References: js/…/53_interaction.ts• L538-585 js/…/52_tooltip.ts• L8-40 js/…/54_kernel.ts• L848-897 spec/…/view-state.md• L282-340
Tooltip and annotation layers
The chart separates data marks from browser chrome. Tooltips and annotation labels are DOM elements so the host can style or replace them. Annotation geometry is painted in a canvas overlay so it stays above the data marks and can use the same coordinate transform as the chart. References: js/…/50_chartview.ts• L7888-7892, js/…/51_annotations.ts• L5-8, js/…/52_tooltip.ts• L480-605
Tooltip placement
The built-in tooltip is a text-safe view of the hovered row. Its fields come from the mark's data channels and can include series, coordinate, color, size, or semantic flow values. A custom tooltip element uses the same container and placement rules, so custom content still follows the point through view changes and flips when it reaches a chart edge.
References: js/…/52_tooltip.ts• L300-472 js/…/52_tooltip.ts• L504-568 js/…/53_interaction.ts• L587-608 docs/…/tooltips.md• L10-16
The tooltip stores its anchor in data space and re-projects it after each draw. It hides when the anchor leaves the plot rather than moving the readout to a misleading edge. A kernel pick can refine the stored anchor from resident precision to exact data values.
For rectangular marks, the local and exact readouts use the same orientation-aware meaning: the category-band center is on the position axis and the value end is on the value axis. The exact reply therefore preserves the displayed label, value, and anchor instead of visibly rewriting the tooltip. If the mark no longer exists when the reply arrives, the chart treats the reply as a miss.
References: js/…/52_tooltip.ts• L64-118 js/…/52_tooltip.ts• L504-554 js/…/54_kernel.ts• L851-879 tests/test_ui_issue_regressions.py• L1134-1289 spec/…/interaction.md• L374-400
Annotation geometry
Annotations explain a chart without changing its data. Rules and bands mark reference values or ranges. Text, markers, arrows, and callouts point to data coordinates. Their data anchors move with pan and zoom, while text offsets remain in screen pixels so labels remain readable.
References: js/…/51_annotations.ts• L596-725 docs/…/annotations.md• L18-29 docs/…/annotations.md• L205-219
Labels use a separate DOM layer from the canvas-painted geometry. The browser places them by anchor, alignment, rotation, and offset. It keeps them inside the chart and uses deterministic spacing for automatic rule and band labels. A callout caches its final label position during motion so its connector remains attached to the label that the user can see.
References: js/…/51_annotations.ts• L727-733 js/…/51_annotations.ts• L811-960 js/…/51_annotations.ts• L963-1032
Annotations owned by a mark follow that mark's visibility. For example, a mark-owned label is suppressed when its trace or category is hidden. Author-written annotations have no such owner and remain visible.
References: js/…/51_annotations.ts• L596-608 js/…/51_annotations.ts• L622-645 spec/…/interaction.md• L463-527
View-state updates
The browser keeps one live view state for axis ranges and geometric selection. Every durable change follows the same validate, clamp, commit, and emit path, whether it comes from a gesture, modebar action, linked chart, history restore, or programmatic write. This makes user and application changes obey the same axis limits and containment rules. References: js/…/57_viewstate.ts• L38-50, js/…/57_viewstate.ts• L53-166, js/…/53_interaction.ts• L1986-2021, spec/…/view-state.md• L38-123
Range and selection state
Durable state stores ranges by exact axis ID and stores either a rectangular selection, a polygon selection, or no selection. It does not store hover or cursor state. Row-index selections are reported as an opaque marker because an arbitrary index set is not a small geometric state.
References: js/…/57_viewstate.ts• L19-50 js/…/57_viewstate.ts• L79-113 spec/…/view-state.md• L40-80
Range and selection updates can serve local rendering first and then receive an authoritative kernel result. A geometric brush can be re-projected after a view change or drill swap. A kernel row selection replaces old masks and is not treated as a durable geometric selection.
References: js/…/53_interaction.ts• L927-990 js/…/53_interaction.ts• L998-1081 js/…/57_viewstate.ts• L240-267 js/…/54_kernel.ts• L898-963
The chart emits semantic events for hover, leave, click, brush, select, and view change. View events name the source, the changed axes, the phase, and the interaction ID. Continuous changes are coalesced to one browser frame, while the final event provides the settled state to the kernel and linked charts.
References: js/…/50_chartview.ts• L1570-1629 spec/…/interaction.md• L155-197
History and linked views
History is local to each chart client. It records the state before a durable change, coalesces all phases of one gesture, and restores snapshots through the same state path. Linked charts share selected axes or selections through a same-origin browser channel, apply incoming state without echoing it, and do not add linked updates to local history.
References: js/…/57_viewstate.ts• L169-218 js/…/50_chartview.ts• L1632-1705 spec/…/view-state.md• L125-164 spec/…/interaction.md• L249-279
The view update flow keeps fast local movement separate from slower detail refresh. The browser changes the view at once, schedules a debounced view request for decimated or density data, and discards replies that no longer match the current sequence. In standalone HTML, the same refinement uses a bundled worker instead of a kernel.
References: js/…/53_interaction.ts• L1986-2110 js/…/54_kernel.ts• L26-153 js/…/54_kernel.ts• L237-389
This diagram shows how a browser gesture becomes a view, event, and optional detail refresh.
flowchart LR
A[Browser input] --> B[Resolve gesture and axis scope]
B --> C[Validate and clamp view or selection]
C --> D[Update local overlays and draw]
D --> E[Coalesce semantic event]
E --> F[Kernel or host transport]
F --> G[Admit current detail reply]
G --> D
C --> H[Linked chart or local history]
Animation scheduling
Animation is a declarative visual policy for chart entry and data replacement. The browser owns one monotonic clock and one animation-frame controller per chart. Python is not called for each frame, and the renderer keeps only the current scene plus the state needed to move from the prior scene. References: js/…/56_animation.ts• L4-6, js/…/56_animation.ts• L162-235, spec/…/animation.md• L128-147
Entrance and update transitions
Entrance motion uses a mark-aware default: paths reveal, bars and columns grow, and point marks scale. Data updates can interpolate position or the view domain when the two representations support a shared identity and layout. Unsupported or oversized representations snap to the new screen-bounded result instead of using a misleading fade.
References: js/…/56_animation.ts• L74-128 js/…/56_animation.ts• L275-325 spec/…/animation.md• L42-67
Stable identity lets a replacement preserve the meaning of rows when data reorders, inserts, or removes points. Index matching is the simple fallback. Key and append matching are bounded so a large or aggregated representation does not force the browser to materialize every source row for a cosmetic transition. Runtime fallbacks are exposed as an animation diagnostic rather than hidden.
References: js/…/56_animation.ts• L275-333 spec/…/animation.md• L69-126
Transition replacement
When a new payload arrives, the chart cancels the old frame loop, samples the currently displayed state, builds the next representation, and starts a latest-wins transition. Removed marks do not remain as a ghost scene. A new update replaces the pending transition instead of building an unbounded queue.
References: js/…/56_animation.ts• L162-235 js/…/56_animation.ts• L518-597 spec/…/animation.md• L135-153
Streaming append keeps its normal follow policy while it animates. A chart at home follows the new domain. A chart pinned to the live edge slides with constant width. A user inspecting an older range stays there. A later refinement can then improve the current decimated or density view.
References: js/…/54_kernel.ts• L406-455 js/…/54_kernel.ts• L496-513 docs/…/animations.md• L476-604
Motion and interaction coordination
The visible next scene remains the source of row identity and selection during data motion. Picking can follow interpolated direct points, while view animation and level-of-detail handoffs pause picking when the row space or screen mapping is changing. Tooltip and annotation anchors are re-projected during the draw cycle, and label layout is throttled during motion before a final settled rebuild.
References: js/…/50_chartview.ts• L6443-6455 js/…/50_chartview.ts• L6512-6538 js/…/50_chartview.ts• L7766-7788 spec/…/animation.md• L155-174
View animation is separate from data animation but uses the same frame discipline. It moves each axis range toward a clamped target, retargets an active motion when a new write arrives, and emits one final view event with the latest source. Reduced motion skips the loop and commits the final view immediately unless the application explicitly enables motion.
References: js/…/53_interaction.ts• L1971-2110 js/…/56_animation.ts• L82-87 spec/…/animation.md• L171-174
This diagram shows how a live data replacement shares the chart clock with view and overlay updates.
sequenceDiagram
participant Host as Host or kernel
participant View as Chart view
participant Clock as Browser frame clock
participant Scene as Current and next scene
Host->>View: New spec and payload
View->>Scene: Match rows and retain bounded transition state
View->>Clock: Schedule one animation loop
loop Each frame
Clock->>View: Progress and easing
View->>Scene: Mix visible geometry and optional view range
View->>View: Draw marks, tooltip, annotations, and chrome
end
View->>Host: animation_end and settled view event
View->>Scene: Release old and scratch state
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the event detail and transport payload aligned when changing
_emitViewChange, hover payload construction, or exact pick handling. - Keep local and exact pick rows aligned for mark orientation so a kernel refinement cannot change a tooltip label, value, or anchor.
- Keep data-space anchors and screen-space offsets aligned across tooltip placement, annotation labels, and view re-projection.
- Keep pointer-capture loss handling consistent for plot gestures, axis-band gestures, lasso handles, and modebar drags.
- Keep animation cancellation, latest-wins replacement, and old-scene release aligned so a new payload cannot revive stale geometry.
- Keep density or decimated reply sequence checks aligned with view animation and standalone worker results.
- Keep reduced-motion behavior aligned between view animation and data animation so a chart does not leave one motion path active.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Pointer release occurs outside an embedding frame | The chart can miss pointerup and leave a gesture active | Pointer capture loss detection finalizes pans or rolls back release-dependent gestures; re-entry does not resume them. |
| A view or density reply arrives after a newer view | Old geometry can cover the current view or restore the wrong detail tier | Sequence checks and current-window checks reject stale replies. |
| A tooltip anchor is kept as screen coordinates | The tooltip describes the old location after pan or zoom | The anchor is stored in data space and re-projected on each draw. |
| An exact pick reply uses a different bar orientation convention from the local readout | A category code or partial bar value replaces the label and moves the tooltip after hover | Both paths use the orientation-aware band-center and value-end convention; a reply for a removed trace is treated as a miss. |
| A custom tooltip bypasses the built-in container | Custom content can lose edge flipping and hide/show behavior | Custom content mounts inside the renderer-owned tooltip container. |
| An annotation label moves without its callout anchor | The connector can point to an invisible or old label position during motion | Final label positions are cached while DOM layout is throttled. |
| An active transition is replaced without sampling its displayed state | Points jump back to an old endpoint or leave ghost marks | Latest-wins replacement samples the currently displayed state and frees the older retained scene. |
| Animation is attempted for an aggregate or over-limit representation | Browser memory and matching work grow with source data | The renderer records a fallback and snaps to the new screen-bounded representation. |
Key files
| File | Why to read it |
|---|---|
| js/…/50_chartview.ts | Chart lifecycle, draw scheduling, picking, event dispatch, overlays, and the shared view-facing surface. |
| js/…/53_interaction.ts | Pointer, wheel, keyboard, axis-band, selection, modebar, and view-animation behavior. |
| js/…/57_viewstate.ts | Durable ranges and selection, validation, history, axis gesture scope, and structured hover support. |
| js/…/52_tooltip.ts | Hover row resolution, exact-readout replacement, tooltip anchoring, and custom tooltip placement. |
| js/…/51_annotations.ts | Canvas annotation geometry, DOM labels, collision placement, and mark-owned visibility. |
| js/…/56_animation.ts | Entrance and update policy, matching, frame lifecycle, cancellation, and bounded transition state. |
| js/…/54_kernel.ts | View refinement, stale-reply admission, append behavior, exact pick replies, and selection replies. |
| js/…/60_entries.ts | Browser and standalone entry points and the order that attaches the chart-view behavior. |
| spec/…/interaction.md | Shipped gesture, event, linking, tooltip, and selection contracts. |
| spec/…/view-state.md | The durable view-state model and its relationships to history, programmatic control, linking, and hover. |
| spec/…/animation.md | Animation policy, bounded matching, lifecycle events, interaction rules, and export behavior. |
| docs/…/animations.md | User-facing examples for entrance motion, keyed updates, streaming append, and lifecycle events. |