useChartZoom

Chart
stable

Manages interactive zoom and pan state for OrigamChartCartesian. The zoom window is expressed as a closed [zoomStart, zoomEnd] range of category indices. Provides scroll-wheel zoom, drag-to-select zoom, and programmatic pan, all with clamping invariants.

API

Signature

Full TypeScript signature sourced from the composable file.

typescript

API

Parameters

Input parameters accepted by this composable.

options
required
{ dataLength: () => number }
options.dataLength
required
() => number
Reactive getter returning the total number of categories or data points. Must always return a value >= 1.

API

Return values

Properties and methods exposed by the composable return object.

zoomStart
Reactive start index of the current zoom window (category index, >= 0).
zoomEnd
Clamped end index of the current zoom window. Always <= dataLength - 1.
zoomEndRaw
Raw (unclamped) end index ref. Infinity when no zoom is active.
isDragging
True while the user is performing a drag-to-select zoom gesture.
dragStartPx
SVG X pixel where the current drag started. Null when not dragging.
dragEndPx
SVG X pixel at the current drag cursor position. Null when not dragging.
isZoomed
True when the window is narrower than the full data range.
zoomTo
Zoom to an explicit [start, end] category-index range, with clamping applied.
zoomReset
Restore the full data range (sets zoomStart = 0, zoomEnd = Infinity).
zoomBy
Zoom in or out by a fraction of the current visible window, anchored at a fractional position (0 = left edge, 1 = right edge). Positive delta zooms in.
panBy
Shift the visible window by N categories while preserving the window size.
pxToCategoryIndex
Convert an SVG X pixel offset to a fractional category index within the current zoom window.
categoryIndexToPx
Convert a category index to an SVG X pixel offset. Used to position the drag-selection overlay.
WHEEL_ZOOM_STEP
Scroll-wheel zoom speed constant (0.15 = ~15 % per notch). Exposed for consumers that need to replicate the feel in custom event handlers.

Usage

Examples

Ready-to-paste usage snippets.

Basic scroll-wheel zoom

vue

Programmatic pan

vue