UNPKG

recharts

Version:
49 lines (48 loc) • 2.74 kB
import { AxisViewport } from './viewport'; /** * Pure zoom "actions": given the current viewport of one axis and a gesture, compute the next * viewport. These hold all the zoom maths so the gesture modules (wheel, pointer, keyboard, ...) * stay thin DOM-only wrappers and the maths can be unit tested in isolation. * * `plotFocus` / `plotFraction` arguments are positions as a fraction `0..1` of the *visible* window * (e.g. the pointer's position across the plotting area), which is what the DOM layer can measure. */ export type ZoomLimits = { /** Furthest zoom-out (1 = full data). */ minZoom: number; /** Deepest zoom-in. */ maxZoom: number; }; /** * Zooms one axis by `factor` (>1 in, <1 out) keeping the point at `plotFocus` visually fixed. * The factor is clamped so the resulting width stays within the `[1/maxZoom, 1/minZoom]` bounds. */ export declare function zoomDimension(current: AxisViewport, factor: number, plotFocus: number, limits: ZoomLimits): AxisViewport; /** * Pans one axis by `deltaPlotFraction`, a fraction of the *visible* window * (e.g. dragging by half the plot width is `0.5`). Positive moves towards the end of the axis. */ export declare function panDimension(current: AxisViewport, deltaPlotFraction: number): AxisViewport; /** * Clamps one axis viewport into the width bounds the limits allow, keeping its centre (shifted * only as needed to stay inside `[0, 1]`). Use it on viewports that arrive from outside the * gesture maths - initial / controlled values, direct window edits - so they obey the same * `minZoom`/`maxZoom` as every gesture. */ export declare function clampDimensionToLimits(current: AxisViewport, limits: ZoomLimits): AxisViewport; /** * Same clamp, but anchored: whichever edge moved least compared to `previous` stays fixed and only * the other edge gives. This is what window editors (brush travellers, minimap resize handles) * want - the handle being dragged hits the limit while the opposite edge does not jump around. */ export declare function clampDimensionToLimitsAnchored(next: AxisViewport, previous: AxisViewport, limits: ZoomLimits): AxisViewport; /** * The most zoomed-out viewport the limits allow: the full axis, or a centered `1/minZoom` window * when `minZoom > 1`. This is what "reset" and an un-zoomed mount must land on. */ export declare function resetDimensionWithLimits(limits: ZoomLimits): AxisViewport; /** * Zooms one axis into the sub-window between two fractions of the current visible window * (drag-to-zoom selection). Order-independent; respects `maxZoom`. */ export declare function selectDimension(current: AxisViewport, fromPlotFraction: number, toPlotFraction: number, limits: ZoomLimits): AxisViewport;