import { type SharedValue } from "react-native-reanimated"; import type { CandleGap, CandlePoint, LiveChartPoint, SeriesConfig } from "../types"; import { type EngineTickInput, type EngineTickMutable } from "./liveChartEngineTick"; export interface EngineConfig { data: SharedValue; value: SharedValue; timeWindow: number; smoothing: number; /** Extra catch-up speed added to `smoothing` when the live value lags. */ adaptiveSpeedBoost?: number; exaggerate?: boolean; referenceValue?: number; referenceValues?: number[]; /** * Live, per-frame Y values to fold into the axis-range fit on top of the static * {@link referenceValues} — used so a *dragging* reference line expands the range * and the axis follows the finger smoothly (the committed values already sit in * `referenceValues`). Read on the UI thread each frame; omit for non-draggable charts. */ liveReferenceValues?: SharedValue; /** * Time-varying threshold series folded into the axis-range fit * (`threshold.includeInRange`): each tick contributes the series' min/max over * the visible window — like {@link referenceValues}, but windowed. A * `SharedValue` for the live `threshold.series` form, a plain array for the * `LiveChartPoint[]` form. */ thresholdRangePoints?: SharedValue | LiveChartPoint[]; /** With {@link thresholdRangePoints}: whether the series extends flat before * its first point to the visible window start. Default `true`. */ thresholdRangeExtendToStart?: boolean; /** With {@link thresholdRangePoints}: whether the series extends flat past its * last point to "now" (`threshold.extendToNow`). Default `true`. */ thresholdRangeExtendToNow?: boolean; nonNegative?: boolean; maxValue?: number; /** Positive, finite live Y-range multiplier (1 = auto-fit); read each frame. */ yRangeScale?: SharedValue; nowOverride?: number; windowBuffer?: number; paused?: boolean; /** * Whether the `timeScroll` gesture is active. Flipping this to `false` while * scrolled back clears {@link ChartEngineScroll.viewEnd} and **glides** the * window back to the live edge (a brief eased animation, not an instant jump), * so disabling time-scroll — or a mode switch that turns it off — never strands * the chart at a past position. See #164. */ scrollEnabled?: boolean; /** * Honor a `viewEnd` parked at or past the live edge — set when * `timeScroll.overscroll` is active so the pan/pinch gestures can drag into * blank future space. See {@link EngineTickInput.allowFutureViewEnd}. */ allowFutureViewEnd?: boolean; /** * Duration (ms) of the return-to-live glide when {@link scrollEnabled} flips to * `false` while scrolled back. `0` snaps instantly (no animation). Defaults to * {@link RETURN_TO_LIVE_MS}. Resolved from `timeScroll.returnToLive`. See #164. */ returnToLiveMs?: number; /** * Loop-free render: settle the display state once (smoothing forced to 1, no * per-frame frame callback) for many small charts in a list. See * {@link LiveChartProps.static}. */ static?: boolean; /** * Opaque key that snaps the framing to its target in one frame whenever it * changes (the next tick bypasses `smoothing` for the window, Y-range, and * value, then normal easing resumes). Lets a timeframe / dataset switch land * instantly while live ticks stay smooth. See {@link LiveChartProps.snapKey}. */ snapKey?: string | number; mode?: "line" | "candle"; candles?: SharedValue; liveCandle?: SharedValue; candleGaps?: CandleGap[]; candleGapBridgeNoTrades?: boolean; candleGapBridgeUnavailable?: boolean; candleGapBridgeUnknown?: boolean; } /** Canvas, time window, and Y-range — shared by single- and multi-series engines. */ export interface ChartEngineLayout { displayMin: SharedValue; displayMax: SharedValue; /** Animating window (lerps toward {@link timeWindow}); use for positioning. */ displayWindow: SharedValue; /** * The *effective* target window — the value `displayWindow` eases toward: the * pinch-zoom override ({@link ChartEngineScroll.viewWindow}) when active, else * the `timeWindow` prop. Tick *selection* (which X-axis labels exist) must read * this, not `displayWindow`: the lerp is asymptotic and never reaches the * target, so it settles just above or just below it depending on the prior * window. Bucketing that off-by-epsilon value (e.g. via `niceTimeInterval`) * would otherwise make the tick cadence depend on where you came from. See * issue #126. */ timeWindow: SharedValue; canvasWidth: SharedValue; canvasHeight: SharedValue; timestamp: SharedValue; } /** * Live extrema (value + time of the lowest / highest data point in the visible * window) — the raw data high/low, not the smoothed display bounds. Each field * is `NaN` when the window holds no data. Provided by both engines so an * `"extrema"`-positioned `topLabel` / `bottomLabel` can be pinned at the point. */ export interface ChartEngineExtrema { extremaMinValue: SharedValue; extremaMaxValue: SharedValue; extremaMinTime: SharedValue; extremaMaxTime: SharedValue; } /** * Time-scroll state: lets a pan gesture freeze the window at an absolute time * and resume following the live edge. Returned by both engines (intersected onto * the state) but kept off {@link ChartEngineLayout} so overlay components — which * only read the layout — don't have to carry it. */ export interface ChartEngineScroll { /** * Absolute right-edge time (unix seconds) to freeze at, or `null` to follow * the live edge. Written by the pan-scroll gesture; read by the engine tick. */ viewEnd: SharedValue; /** * The right-edge time the engine would use if following live — advances each * frame even while {@link ChartEngineLayout.timestamp} is frozen by a pan. */ liveEdge: SharedValue; /** * Absolute visible-window width (seconds) to freeze at, or `null` to follow * the configured `timeWindow`. Written by the pinch-zoom gesture; the * symmetric counterpart of {@link viewEnd} (width vs. right edge). Folded into * {@link ChartEngineLayout.timeWindow}, so downstream selection/positioning * picks up the zoom for free. */ viewWindow: SharedValue; } /** Single-series only: smoothed price at the visible window's right edge. */ export interface ChartEngineEdge { /** * Smoothed value at the window's right edge — the live value while following, * the price at `viewEnd` while scrolled back. For a `followViewEdge` badge. */ edgeValue: SharedValue; } export interface SingleEngineState extends ChartEngineLayout, ChartEngineExtrema { data: SharedValue; value: SharedValue; displayValue: SharedValue; } export interface MultiEngineState extends ChartEngineLayout, ChartEngineExtrema { data: SharedValue; value: SharedValue; displayValue: SharedValue; series: SharedValue; displaySeriesValues: SharedValue; seriesOpacities: SharedValue; } export type EngineState = SingleEngineState | MultiEngineState; /** Canvas, range, and animated live value (badge / value line). */ export type ChartEngineWithLiveValue = ChartEngineLayout & { displayValue: SharedValue; }; export interface EngineFrameRefs { data: SharedValue; value: SharedValue; displayValue: SharedValue; displayMin: SharedValue; displayMax: SharedValue; displayWindow: SharedValue; canvasWidth: SharedValue; canvasHeight: SharedValue; timestamp: SharedValue; timeWindow: SharedValue; smoothing: SharedValue; adaptiveSpeedBoostSV?: SharedValue; exaggerateSV: SharedValue; referenceValue: SharedValue; referenceValues?: SharedValue; /** Series threshold folded into the range fit (`threshold.includeInRange`). */ thresholdRangePoints?: SharedValue; thresholdRangeExtendToStart?: SharedValue; thresholdRangeExtendToNow?: SharedValue; nonNegativeSV?: SharedValue; maxValueSV?: SharedValue; yRangeScaleSV?: SharedValue; nowOverrideSV?: SharedValue; windowBufferSV?: SharedValue; pausedSV: SharedValue; /** Pan-scroll right-edge override (null = follow live). Optional for callers/tests. */ viewEndSV?: SharedValue; /** Honor a `viewEnd` past the live edge (timeScroll.overscroll). Optional. */ allowFutureViewEndSV?: SharedValue; /** "Return to live" glide progress (0→1); the right edge eases to live. Optional. */ returnTSV?: SharedValue; /** Frozen right-edge time the return glide starts from. Optional. */ returnFromSV?: SharedValue; /** Pinch-zoom window-width override (null = follow timeWindow). Optional for callers/tests. */ viewWindowSV?: SharedValue; /** Receives the computed live edge each frame. Optional for callers/tests. */ liveEdgeSV?: SharedValue; /** Receives the smoothed right-edge value each frame. Optional for callers/tests. */ edgeValueSV?: SharedValue; /** * One-shot "snap the framing this frame" flag (set by the `snapKey` effect). * Consumed and cleared by {@link applyLiveChartEngineFrame} after the tick. * Optional for callers/tests. */ snapSV?: SharedValue; modeSV: SharedValue<"line" | "candle">; candles?: SharedValue; liveCandle?: SharedValue; candleGapsSV?: SharedValue; candleGapBridgeNoTradesSV?: SharedValue; candleGapBridgeUnavailableSV?: SharedValue; candleGapBridgeUnknownSV?: SharedValue; extremaMinValue: SharedValue; extremaMaxValue: SharedValue; extremaMinTime: SharedValue; extremaMaxTime: SharedValue; } /** Stable state/input containers reused by the UI-thread frame callback. */ export interface EngineFrameScratch { state: EngineTickMutable; input: EngineTickInput; } /** Allocate one single-series frame scratch. Call once per engine instance. */ export declare function makeEngineFrameScratch(): EngineFrameScratch; /** * Shared between the `useFrameCallback` worklet and unit tests. * Mutates shared values from a snapshot tick (`tickLiveChartEngineFrame`). */ export declare function applyLiveChartEngineFrame(frameInfo: { timeSincePreviousFrame?: number | null; }, sv: EngineFrameRefs, scratch?: EngineFrameScratch): void; export declare function useLiveChartEngine(config: EngineConfig): SingleEngineState & ChartEngineScroll & ChartEngineEdge; //# sourceMappingURL=useLiveChartEngine.d.ts.map