react-native-livechart 4.27.0 → 4.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/LiveChart.d.ts.map +1 -1
- package/dist/components/LiveChartSeries.d.ts.map +1 -1
- package/dist/components/MultiSeriesDots.d.ts +1 -1
- package/dist/components/MultiSeriesDots.d.ts.map +1 -1
- package/dist/components/MultiSeriesValueLabels.d.ts +1 -1
- package/dist/components/MultiSeriesValueLabels.d.ts.map +1 -1
- package/dist/components/MultiSeriesValueLines.d.ts +1 -1
- package/dist/components/MultiSeriesValueLines.d.ts.map +1 -1
- package/dist/core/liveChartSeriesEngineTick.d.ts +13 -2
- package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
- package/dist/core/resolveConfig.d.ts.map +1 -1
- package/dist/core/useLiveChartEngine.d.ts +2 -0
- package/dist/core/useLiveChartEngine.d.ts.map +1 -1
- package/dist/core/useLiveChartSeriesEngine.d.ts +16 -4
- package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
- package/dist/draw/grid.d.ts +4 -2
- package/dist/draw/grid.d.ts.map +1 -1
- package/dist/draw/line.d.ts +6 -2
- package/dist/draw/line.d.ts.map +1 -1
- package/dist/hooks/crosshairSeries.d.ts +2 -2
- package/dist/hooks/crosshairSeries.d.ts.map +1 -1
- package/dist/hooks/resolveChartLayout.d.ts +10 -2
- package/dist/hooks/resolveChartLayout.d.ts.map +1 -1
- package/dist/hooks/useCrosshairSeries.d.ts +3 -1
- package/dist/hooks/useCrosshairSeries.d.ts.map +1 -1
- package/dist/hooks/useMultiSeriesDegen.d.ts +1 -1
- package/dist/hooks/useMultiSeriesDegen.d.ts.map +1 -1
- package/dist/hooks/useMultiSeriesLinePaths.d.ts.map +1 -1
- package/dist/hooks/usePinchZoom.d.ts +7 -4
- package/dist/hooks/usePinchZoom.d.ts.map +1 -1
- package/dist/hooks/useReferenceDrag.d.ts.map +1 -1
- package/dist/hooks/useYAxis.d.ts +1 -1
- package/dist/hooks/useYAxis.d.ts.map +1 -1
- package/dist/hooks/useYAxisLabelWidth.d.ts +6 -0
- package/dist/hooks/useYAxisLabelWidth.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/math/referenceLines.d.ts.map +1 -1
- package/dist/types.d.ts +61 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/LiveChart.tsx +20 -0
- package/src/components/LiveChartSeries.tsx +26 -6
- package/src/components/MultiSeriesDots.tsx +4 -2
- package/src/components/MultiSeriesValueLabels.tsx +4 -2
- package/src/components/MultiSeriesValueLines.tsx +4 -2
- package/src/core/liveChartSeriesEngineTick.ts +70 -14
- package/src/core/resolveConfig.ts +8 -5
- package/src/core/useLiveChartEngine.ts +2 -0
- package/src/core/useLiveChartSeriesEngine.ts +42 -6
- package/src/draw/grid.ts +15 -11
- package/src/draw/line.ts +23 -4
- package/src/hooks/crosshairSeries.ts +37 -5
- package/src/hooks/resolveChartLayout.ts +34 -3
- package/src/hooks/useCrosshairSeries.ts +28 -10
- package/src/hooks/useMultiSeriesDegen.ts +10 -5
- package/src/hooks/useMultiSeriesLinePaths.ts +2 -0
- package/src/hooks/usePinchZoom.ts +11 -4
- package/src/hooks/useReferenceDrag.ts +21 -3
- package/src/hooks/useYAxis.ts +1 -1
- package/src/hooks/useYAxisLabelWidth.ts +26 -0
- package/src/index.ts +1 -0
- package/src/math/referenceLines.ts +5 -0
- package/src/types.ts +57 -6
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
import { scheduleOnRN } from "react-native-worklets";
|
|
11
11
|
import type { ResolvedPerSeriesTooltipConfig } from "../core/resolveConfig";
|
|
12
12
|
import type { MultiEngineState } from "../core/useLiveChartEngine";
|
|
13
|
-
import { type ChartPadding } from "../draw/line";
|
|
13
|
+
import { lineTipX, type ChartPadding } from "../draw/line";
|
|
14
14
|
import type { ScrubPointMulti } from "../types";
|
|
15
15
|
import {
|
|
16
16
|
computePerSeriesTooltipLayout,
|
|
@@ -77,9 +77,20 @@ export function useCrosshairSeries(
|
|
|
77
77
|
markerOptions?: ScrubMarkerOptions,
|
|
78
78
|
/** Price-axis ownership also guards against stale native long-press events. */
|
|
79
79
|
axisScaleActive?: SharedValue<boolean>,
|
|
80
|
+
/** Bottom strip reserved for the time-axis drag gesture, in layout points. */
|
|
81
|
+
scrubBottomExclude = 0,
|
|
80
82
|
): CrosshairState {
|
|
81
|
-
const
|
|
83
|
+
const pointerX = useSharedValue(-1);
|
|
82
84
|
const scrubActive = useSharedValue(false);
|
|
85
|
+
const scrubX = useDerivedValue(() => {
|
|
86
|
+
const x = pointerX.get();
|
|
87
|
+
const head = engine.tipTime?.get();
|
|
88
|
+
if (x < 0 || head === undefined) return x;
|
|
89
|
+
const end = engine.timestamp.get();
|
|
90
|
+
const window = engine.displayWindow.get();
|
|
91
|
+
if (head < end - window) return -1;
|
|
92
|
+
return Math.min(x, lineTipX(end, window, head, engine.canvasWidth.get(), padding));
|
|
93
|
+
});
|
|
83
94
|
// Tracks whether the active scrub phase actually began, so a tap that never
|
|
84
95
|
// activates doesn't emit a spurious onGestureEnd.
|
|
85
96
|
const gestureStarted = useSharedValue(false);
|
|
@@ -100,22 +111,26 @@ export function useCrosshairSeries(
|
|
|
100
111
|
const noScrollActive = useSharedValue(false);
|
|
101
112
|
const scrollActiveSV = scrollActive ?? noScrollActive;
|
|
102
113
|
|
|
103
|
-
const scrubTime = useDerivedValue(() =>
|
|
104
|
-
|
|
114
|
+
const scrubTime = useDerivedValue(() => {
|
|
115
|
+
const head = engine.tipTime?.get();
|
|
116
|
+
if (head !== undefined && head < engine.timestamp.get() - engine.displayWindow.get()) return -1;
|
|
117
|
+
return Math.min(head ?? Infinity, computeScrubTime(
|
|
105
118
|
scrubActive.get(),
|
|
106
119
|
scrubX.get(),
|
|
107
120
|
padding,
|
|
108
121
|
engine.canvasWidth.get(),
|
|
109
122
|
engine.timestamp.get(),
|
|
110
123
|
engine.displayWindow.get(),
|
|
111
|
-
)
|
|
112
|
-
);
|
|
124
|
+
));
|
|
125
|
+
});
|
|
113
126
|
|
|
114
127
|
const scrubValue = useDerivedValue(() =>
|
|
115
128
|
deriveScrubValueSeries(
|
|
116
129
|
scrubActive.get(),
|
|
117
130
|
scrubTime.get(),
|
|
118
131
|
engine.series.get(),
|
|
132
|
+
engine.tipTime?.get(),
|
|
133
|
+
engine.displaySeriesValues.get(),
|
|
119
134
|
),
|
|
120
135
|
);
|
|
121
136
|
|
|
@@ -190,7 +205,10 @@ export function useCrosshairSeries(
|
|
|
190
205
|
const x = scrubX.get();
|
|
191
206
|
const chartW = engine.canvasWidth.get() - padding.left - padding.right;
|
|
192
207
|
if (chartW <= 0) return "__pending__";
|
|
193
|
-
|
|
208
|
+
if (time < 0) return "__pending__";
|
|
209
|
+
const r = interpolateSeriesAtTime(
|
|
210
|
+
engine.series.get(), time, engine.tipTime?.get(), engine.displaySeriesValues.get(),
|
|
211
|
+
);
|
|
194
212
|
if (r.primary === null) return "__pending__";
|
|
195
213
|
const dotY = computeScrubDotY(
|
|
196
214
|
r.primary,
|
|
@@ -320,7 +338,7 @@ export function useCrosshairSeries(
|
|
|
320
338
|
padding,
|
|
321
339
|
engine.canvasWidth.get(),
|
|
322
340
|
clampToPlot,
|
|
323
|
-
|
|
341
|
+
pointerX,
|
|
324
342
|
scrubActive,
|
|
325
343
|
gestureStarted,
|
|
326
344
|
);
|
|
@@ -337,7 +355,7 @@ export function useCrosshairSeries(
|
|
|
337
355
|
padding,
|
|
338
356
|
engine.canvasWidth.get(),
|
|
339
357
|
clampToPlot,
|
|
340
|
-
|
|
358
|
+
pointerX,
|
|
341
359
|
scrubActive,
|
|
342
360
|
);
|
|
343
361
|
},
|
|
@@ -368,7 +386,7 @@ export function useCrosshairSeries(
|
|
|
368
386
|
// Gate by touch-down position so outside starts fail before activation and
|
|
369
387
|
// remain available to competing/parent gestures. Accepted pans keep tracking
|
|
370
388
|
// outside because `shouldCancelWhenOutside(false)` is set above.
|
|
371
|
-
const scrubHitSlop = resolveScrubHitSlop(padding, clampToPlot);
|
|
389
|
+
const scrubHitSlop = resolveScrubHitSlop(padding, clampToPlot, scrubBottomExclude);
|
|
372
390
|
if (scrubHitSlop) gesture = gesture.hitSlop(scrubHitSlop);
|
|
373
391
|
|
|
374
392
|
return {
|
|
@@ -10,7 +10,7 @@ import { runOnJS } from "react-native-worklets";
|
|
|
10
10
|
import { DEGEN_STRIDE } from "../constants";
|
|
11
11
|
import type { ResolvedDegenConfig } from "../core/resolveConfig";
|
|
12
12
|
import type { MultiEngineState } from "../core/useLiveChartEngine";
|
|
13
|
-
import type
|
|
13
|
+
import { lineTipX, type ChartPadding } from "../draw/line";
|
|
14
14
|
import { computeShake, spawnBurst, tickParticles } from "../math/degenTick";
|
|
15
15
|
import { detectMomentum } from "../math/momentum";
|
|
16
16
|
import type { DegenShakePayload } from "../types";
|
|
@@ -164,19 +164,24 @@ export function useMultiSeriesDegen(
|
|
|
164
164
|
|
|
165
165
|
const cw = engine.canvasWidth.get();
|
|
166
166
|
const ch = engine.canvasHeight.get();
|
|
167
|
-
const
|
|
167
|
+
const end = engine.timestamp.get();
|
|
168
|
+
const window = engine.displayWindow.get();
|
|
169
|
+
const head = engine.tipTime?.get() ?? end;
|
|
170
|
+
const ox = lineTipX(end, window, head, cw, padding);
|
|
171
|
+
const canSpawn = cw >= 1 && ch >= 1 && window > 0 &&
|
|
172
|
+
ox >= padding.left && ox <= cw - padding.right;
|
|
168
173
|
const dMin = engine.displayMin.get();
|
|
169
174
|
const dMax = engine.displayMax.get();
|
|
170
175
|
const valRange = dMax - dMin;
|
|
171
176
|
const chartH = ch - padding.top - padding.bottom;
|
|
172
|
-
const ox = cw - padding.right;
|
|
173
177
|
const allowDown = downSV.get() > 0.5;
|
|
174
178
|
|
|
175
179
|
// Each visible series fires a burst off its own dot on a fresh swing.
|
|
176
180
|
let firedDir = 0; // 0 none, 1 up, 2 down
|
|
177
181
|
for (let i = 0; i < n; i++) {
|
|
178
|
-
const visible = (ops[i] ?? 0) >= 0.5
|
|
179
|
-
|
|
182
|
+
const visible = (ops[i] ?? 0) >= 0.5 &&
|
|
183
|
+
s[i].data.length > 0 && s[i].data[0].time <= head;
|
|
184
|
+
const m = visible ? detectMomentum(s[i].data, 20, 0.12, head) : "flat";
|
|
180
185
|
const code = m === "up" ? 1 : m === "down" ? 2 : 0;
|
|
181
186
|
const prev = moms[i];
|
|
182
187
|
moms[i] = code;
|
|
@@ -60,6 +60,8 @@ export interface UsePinchZoomOptions {
|
|
|
60
60
|
minTime: SharedValue<number>;
|
|
61
61
|
/** The configured `timeWindow` prop (seconds) — the anchor for the zoom bounds. */
|
|
62
62
|
timeWindow: number;
|
|
63
|
+
/** Current unzoomed history span, including breathing room; independent of retained samples. */
|
|
64
|
+
fullHistoryWindow?: SharedValue<number | null>;
|
|
63
65
|
/** Master switch. When false the gesture is disabled. */
|
|
64
66
|
enabled: boolean;
|
|
65
67
|
/** Tightest window (max zoom-in), seconds. Default `timeWindow / 8`. */
|
|
@@ -91,8 +93,9 @@ export function clampWindow(
|
|
|
91
93
|
|
|
92
94
|
/**
|
|
93
95
|
* Resolve the zoom bounds for a gesture. `maxWin` defaults to the data span but
|
|
94
|
-
*
|
|
95
|
-
* starting view); `minWin` defaults
|
|
96
|
+
* includes the configured window and authoritative full-history span (so you can
|
|
97
|
+
* restore the starting view). Explicit maxima take precedence; `minWin` defaults
|
|
98
|
+
* to an 8× zoom-in of the configured window.
|
|
96
99
|
* Guards against an inverted range (min ≤ max).
|
|
97
100
|
*/
|
|
98
101
|
export function zoomWindowBounds(
|
|
@@ -100,9 +103,10 @@ export function zoomWindowBounds(
|
|
|
100
103
|
span: number,
|
|
101
104
|
minCfg: number | undefined,
|
|
102
105
|
maxCfg: number | undefined,
|
|
106
|
+
fullHistoryWindow?: number | null,
|
|
103
107
|
): [number, number] {
|
|
104
108
|
"worklet";
|
|
105
|
-
const maxWin = Math.max(
|
|
109
|
+
const maxWin = maxCfg ?? Math.max(span, configWindow, fullHistoryWindow ?? 0);
|
|
106
110
|
let minWin = minCfg ?? configWindow / 8;
|
|
107
111
|
if (minWin > maxWin) minWin = maxWin;
|
|
108
112
|
return [minWin, maxWin];
|
|
@@ -158,6 +162,7 @@ export function usePinchZoom({
|
|
|
158
162
|
padding,
|
|
159
163
|
minTime,
|
|
160
164
|
timeWindow,
|
|
165
|
+
fullHistoryWindow,
|
|
161
166
|
enabled,
|
|
162
167
|
minTimeWindow,
|
|
163
168
|
maxTimeWindow,
|
|
@@ -184,7 +189,7 @@ export function usePinchZoom({
|
|
|
184
189
|
cancelAnimation(viewEnd);
|
|
185
190
|
cancelAnimation(viewWindow);
|
|
186
191
|
const edge = liveEdge.get();
|
|
187
|
-
startWindow.set(
|
|
192
|
+
startWindow.set(displayWindow.get());
|
|
188
193
|
startViewEnd.set(viewEnd.get() ?? edge);
|
|
189
194
|
onZoomStart?.();
|
|
190
195
|
};
|
|
@@ -210,6 +215,7 @@ export function usePinchZoom({
|
|
|
210
215
|
span,
|
|
211
216
|
minTimeWindow,
|
|
212
217
|
maxTimeWindow,
|
|
218
|
+
fullHistoryWindow?.get(),
|
|
213
219
|
);
|
|
214
220
|
// Pinch out (scale > 1) ⇒ narrower window ⇒ zoom in.
|
|
215
221
|
const newWin = clampWindow(sWin / e.scale, minWin, maxWin);
|
|
@@ -245,6 +251,7 @@ export function usePinchZoom({
|
|
|
245
251
|
canvasWidth,
|
|
246
252
|
displayWindow,
|
|
247
253
|
enabled,
|
|
254
|
+
fullHistoryWindow,
|
|
248
255
|
liveEdge,
|
|
249
256
|
maxTimeWindow,
|
|
250
257
|
minTime,
|
|
@@ -2,6 +2,7 @@ import { stackedTagAt, type ReferenceTagStack } from "../math/referenceTagStack"
|
|
|
2
2
|
import { useCallback, useMemo } from "react";
|
|
3
3
|
import { Gesture } from "react-native-gesture-handler";
|
|
4
4
|
import {
|
|
5
|
+
isSharedValue,
|
|
5
6
|
useAnimatedReaction,
|
|
6
7
|
useDerivedValue,
|
|
7
8
|
useSharedValue,
|
|
@@ -40,7 +41,8 @@ const EMPTY: never[] = [];
|
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
* The value a drag at canvas `y` gives `line` against the current range: the
|
|
43
|
-
* price at that Y, snapped to `line.snap` and clamped to `
|
|
44
|
+
* price at that Y, snapped to `line.snap` and clamped to `bounds` (the line's
|
|
45
|
+
* `bounds`, read from its SharedValue when it has one). Null
|
|
44
46
|
* before the canvas is laid out. `atFinger`: the value the finger sets (what the
|
|
45
47
|
* range fits and `onChange` reports) — the nearest increment, rounded outward
|
|
46
48
|
* once the finger is past the plot's edge so even a coarse `snap` can widen the
|
|
@@ -49,6 +51,7 @@ const EMPTY: never[] = [];
|
|
|
49
51
|
*/
|
|
50
52
|
function dragValueAtY(
|
|
51
53
|
line: ReferenceLine,
|
|
54
|
+
bounds: [number, number] | undefined,
|
|
52
55
|
y: number,
|
|
53
56
|
displayMin: number,
|
|
54
57
|
displayMax: number,
|
|
@@ -74,7 +77,7 @@ function dragValueAtY(
|
|
|
74
77
|
y < padTop ? 1 : y > canvasHeight - padBottom ? -1 : 0,
|
|
75
78
|
)
|
|
76
79
|
: snapPriceWithin(raw, line.snap, displayMin, displayMax);
|
|
77
|
-
return clampToBounds(snapped,
|
|
80
|
+
return clampToBounds(snapped, bounds);
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
/**
|
|
@@ -177,6 +180,17 @@ export function useReferenceDrag(
|
|
|
177
180
|
return ranges;
|
|
178
181
|
});
|
|
179
182
|
|
|
183
|
+
// Per-line drag bounds (`ReferenceLine.bounds`), index-aligned with `lines`.
|
|
184
|
+
// The worklet captures the bounds themselves rather than `linesSV`, so a
|
|
185
|
+
// SharedValue bound is one of its inputs: moving it re-clamps the drag and
|
|
186
|
+
// re-checks onDragIn / onDragOut on the UI thread, without a render.
|
|
187
|
+
const boundsInputs = useMemo(() => lines.map((l) => l.bounds), [lines]);
|
|
188
|
+
const bounds = useDerivedValue(() => {
|
|
189
|
+
const out: ([number, number] | undefined)[] = [];
|
|
190
|
+
for (const b of boundsInputs) out.push(isSharedValue<[number, number]>(b) ? b.get() : b);
|
|
191
|
+
return out;
|
|
192
|
+
});
|
|
193
|
+
|
|
180
194
|
const dragIndex = useSharedValue(-1);
|
|
181
195
|
const startX = useSharedValue(0);
|
|
182
196
|
const startY = useSharedValue(0);
|
|
@@ -205,6 +219,7 @@ export function useReferenceDrag(
|
|
|
205
219
|
if (l === undefined || l.id !== grabbedId.get()) return values;
|
|
206
220
|
const v = dragValueAtY(
|
|
207
221
|
l,
|
|
222
|
+
bounds.get()[i],
|
|
208
223
|
lastY.get(),
|
|
209
224
|
displayMin.get(),
|
|
210
225
|
displayMax.get(),
|
|
@@ -309,7 +324,7 @@ export function useReferenceDrag(
|
|
|
309
324
|
continue;
|
|
310
325
|
}
|
|
311
326
|
const v = drawnValues.get()[i] ?? l.value;
|
|
312
|
-
out.push(referenceValueOut(v, dMin, dMax,
|
|
327
|
+
out.push(referenceValueOut(v, dMin, dMax, bounds.get()[i]));
|
|
313
328
|
}
|
|
314
329
|
return out;
|
|
315
330
|
},
|
|
@@ -412,6 +427,7 @@ export function useReferenceDrag(
|
|
|
412
427
|
}
|
|
413
428
|
const v = dragValueAtY(
|
|
414
429
|
l,
|
|
430
|
+
bounds.get()[i],
|
|
415
431
|
e.y - pointerOffsetY.get(),
|
|
416
432
|
displayMin.get(),
|
|
417
433
|
displayMax.get(),
|
|
@@ -442,6 +458,7 @@ export function useReferenceDrag(
|
|
|
442
458
|
const v =
|
|
443
459
|
dragValueAtY(
|
|
444
460
|
l,
|
|
461
|
+
bounds.get()[i],
|
|
445
462
|
lastY.get(),
|
|
446
463
|
displayMin.get(),
|
|
447
464
|
displayMax.get(),
|
|
@@ -511,6 +528,7 @@ export function useReferenceDrag(
|
|
|
511
528
|
}, [
|
|
512
529
|
activated,
|
|
513
530
|
anyDraggable,
|
|
531
|
+
bounds,
|
|
514
532
|
canvasHeight,
|
|
515
533
|
clearDrag,
|
|
516
534
|
displayMax,
|
package/src/hooks/useYAxis.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type { GridMetrics } from "../types";
|
|
|
15
15
|
export function useYAxis(
|
|
16
16
|
engine: ChartEngineLayout,
|
|
17
17
|
padding: ChartPadding,
|
|
18
|
-
formatValue: (v: number) => string,
|
|
18
|
+
formatValue: (v: number, tickStep?: number) => string,
|
|
19
19
|
font: SkFont,
|
|
20
20
|
minGap = 36,
|
|
21
21
|
gridMetrics: GridMetrics = GRID_METRICS_DEFAULTS,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { SkFont } from "@shopify/react-native-skia";
|
|
2
|
+
import { useAnimatedReaction, type SharedValue } from "react-native-reanimated";
|
|
3
|
+
import { scheduleOnRN } from "react-native-worklets";
|
|
4
|
+
import { widestYAxisLabelWidth, type YAxisEntry } from "../draw/grid";
|
|
5
|
+
|
|
6
|
+
/** Report the painted column width only when it changes, avoiding per-frame React work. */
|
|
7
|
+
export function useYAxisLabelWidth(
|
|
8
|
+
entries: SharedValue<YAxisEntry[]>,
|
|
9
|
+
font: SkFont,
|
|
10
|
+
enabled: boolean,
|
|
11
|
+
onWidthChange: (width: number | undefined) => void,
|
|
12
|
+
) {
|
|
13
|
+
useAnimatedReaction(
|
|
14
|
+
() => {
|
|
15
|
+
if (!enabled) return undefined;
|
|
16
|
+
const labels = entries.get();
|
|
17
|
+
return labels.length > 0 ? Math.ceil(widestYAxisLabelWidth(labels, font)) : undefined;
|
|
18
|
+
},
|
|
19
|
+
(width, previous) => {
|
|
20
|
+
if (width !== previous && (width !== undefined || previous != null)) {
|
|
21
|
+
scheduleOnRN(onWidthChange, width);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
[entries, font, enabled, onWidthChange],
|
|
25
|
+
);
|
|
26
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isSharedValue } from "react-native-reanimated";
|
|
2
|
+
|
|
1
3
|
import type {
|
|
2
4
|
FontWeight,
|
|
3
5
|
ReferenceLine,
|
|
@@ -94,6 +96,9 @@ export function referenceLineReactKeys(
|
|
|
94
96
|
|
|
95
97
|
/** Serializes render-relevant config without callback identity churn. */
|
|
96
98
|
function stableReferenceLineSignature(value: unknown): string {
|
|
99
|
+
// A SharedValue (e.g. live `bounds`) holds UI-thread data, not identity, and
|
|
100
|
+
// reading it here would read `.value` during render.
|
|
101
|
+
if (isSharedValue(value)) return "shared";
|
|
97
102
|
if (Array.isArray(value)) {
|
|
98
103
|
return `[${value.map(stableReferenceLineSignature).join(",")}]`;
|
|
99
104
|
}
|
package/src/types.ts
CHANGED
|
@@ -228,8 +228,13 @@ export interface ReferenceLine {
|
|
|
228
228
|
* can't be dragged past either end. Omit for unbounded (clamped only to the
|
|
229
229
|
* visible range). Reaching a bound fires {@link onDragOut}. Applies only while
|
|
230
230
|
* {@link draggable}.
|
|
231
|
+
*
|
|
232
|
+
* Pass a `SharedValue<[number, number]>` for a bound that follows a live value
|
|
233
|
+
* (e.g. a stop that can't cross the current price): the clamp and
|
|
234
|
+
* {@link onDragIn} / {@link onDragOut} read it on the UI thread, so moving it
|
|
235
|
+
* doesn't need a new `referenceLines` array or a re-render.
|
|
231
236
|
*/
|
|
232
|
-
bounds?: [number, number]
|
|
237
|
+
bounds?: [number, number] | SharedValue<[number, number]>;
|
|
233
238
|
/**
|
|
234
239
|
* Fired on the JS thread *while* dragging, each time the finger moves the line
|
|
235
240
|
* to a new (snapped, clamped) value. De-duplicated to value changes — not every
|
|
@@ -848,7 +853,9 @@ export interface YAxisConfig {
|
|
|
848
853
|
* Place price labels in a shared left-aligned column whose right edge sits
|
|
849
854
|
* this many pixels from the canvas edge. When omitted, labels keep the
|
|
850
855
|
* default centered-gutter placement. To line the live badge's value up with
|
|
851
|
-
* the column, set {@link BadgeConfig.textAlign} to `"yAxisColumn"`.
|
|
856
|
+
* the column, set {@link BadgeConfig.textAlign} to `"yAxisColumn"`. Automatic
|
|
857
|
+
* gutters use actual tick widths, this margin, dot-effect outset and 6px
|
|
858
|
+
* clearance. Explicit right insets and badge reservations retain priority.
|
|
852
859
|
*/
|
|
853
860
|
labelRightMargin?: number;
|
|
854
861
|
/**
|
|
@@ -2272,7 +2279,9 @@ export interface ZoomConfig {
|
|
|
2272
2279
|
minTimeWindow?: number;
|
|
2273
2280
|
/**
|
|
2274
2281
|
* Widest visible window in seconds (max zoom-out). Defaults to the full data
|
|
2275
|
-
* span (you can zoom out to all retained history), never below `timeWindow
|
|
2282
|
+
* span (you can zoom out to all retained history), never below `timeWindow`
|
|
2283
|
+
* unless explicitly set. LiveChartSeries also includes
|
|
2284
|
+
* its anchored full-history span when historyStartTime is supplied.
|
|
2276
2285
|
*/
|
|
2277
2286
|
maxTimeWindow?: number;
|
|
2278
2287
|
}
|
|
@@ -2280,7 +2289,8 @@ export interface ZoomConfig {
|
|
|
2280
2289
|
/** Imperative methods exposed by `LiveChart` and `LiveChartSeries`. */
|
|
2281
2290
|
export interface LiveChartHandle {
|
|
2282
2291
|
/**
|
|
2283
|
-
* Reset built-in pinch/time-window zoom to the configured `timeWindow`
|
|
2292
|
+
* Reset built-in pinch/time-window zoom to the configured `timeWindow`
|
|
2293
|
+
* (or LiveChartSeries historyStartTime span) and
|
|
2284
2294
|
* clear the focal-point offset so the chart follows the live edge again.
|
|
2285
2295
|
* On LiveChart with viewport, clears the supplied end/window shared values.
|
|
2286
2296
|
* Safe to call when already reset. A paused chart remains paused.
|
|
@@ -2400,6 +2410,21 @@ export interface RangeAnimationConfig {
|
|
|
2400
2410
|
contractionSmoothing?: number;
|
|
2401
2411
|
}
|
|
2402
2412
|
|
|
2413
|
+
/** Y-range easing and optional presentation transform for {@link LiveChartSeries}. */
|
|
2414
|
+
export interface SeriesRangeAnimationConfig extends RangeAnimationConfig {
|
|
2415
|
+
/**
|
|
2416
|
+
* UI-thread worklet applied after normal fitting/easing. Receives untransformed
|
|
2417
|
+
* display bounds and the visible Unix-second interval; may read SharedValues.
|
|
2418
|
+
* Returned finite, increasing bounds affect presentation only and never feed
|
|
2419
|
+
* back into fitting. Invalid results are ignored. Removing it restores the
|
|
2420
|
+
* untransformed range. Hard bounds are applied to the fit before this transform.
|
|
2421
|
+
*/
|
|
2422
|
+
transform?: (range: { min: number; max: number; from: number; to: number }) => {
|
|
2423
|
+
min: number;
|
|
2424
|
+
max: number;
|
|
2425
|
+
};
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2403
2428
|
/** Props shared between `LiveChart` and `LiveChartSeries`. */
|
|
2404
2429
|
export interface LiveChartCoreProps {
|
|
2405
2430
|
/** Color scheme. Default `"dark"`. */
|
|
@@ -2546,8 +2571,12 @@ export interface LiveChartCoreProps {
|
|
|
2546
2571
|
* points or committed candles. Default `"No data"`.
|
|
2547
2572
|
*/
|
|
2548
2573
|
emptyText?: string;
|
|
2549
|
-
/**
|
|
2550
|
-
|
|
2574
|
+
/**
|
|
2575
|
+
* Worklet formatter for value labels. Y-axis ticks pass their interval in
|
|
2576
|
+
* source units as `tickStep`; badges, tooltips and layout samples omit it.
|
|
2577
|
+
* Existing one-argument formatters remain valid. Default `v => v.toFixed(2)`.
|
|
2578
|
+
*/
|
|
2579
|
+
formatValue?: (v: number, tickStep?: number) => string;
|
|
2551
2580
|
/** Custom formatter for time labels. Default renders `HH:MM:SS`. */
|
|
2552
2581
|
formatTime?: (t: number) => string;
|
|
2553
2582
|
/** Y-axis grid lines + labels. `true` = defaults, `false` = hidden, or pass `YAxisConfig`. Default `true`. */
|
|
@@ -3029,6 +3058,28 @@ export interface LiveChartProps extends LiveChartCoreProps {
|
|
|
3029
3058
|
|
|
3030
3059
|
/** Props for the multi-series `LiveChartSeries` component. */
|
|
3031
3060
|
export interface LiveChartSeriesProps extends LiveChartCoreProps {
|
|
3061
|
+
/**
|
|
3062
|
+
* UI-thread presentation clock in Unix seconds. Each frame reads this head;
|
|
3063
|
+
* undefined falls back to nowOverride or wall time. Paths/dots end at the
|
|
3064
|
+
* earlier of the viewport edge and head, leaving windowBuffer empty. Samples
|
|
3065
|
+
* after this head are excluded from paths and range fitting. Scrub time limits
|
|
3066
|
+
* and values use the same cutoff, including callback payloads and tooltip
|
|
3067
|
+
* interpolation. Degen bursts originate at the presented dot. No React
|
|
3068
|
+
* render is required for clock updates.
|
|
3069
|
+
*/
|
|
3070
|
+
presentationTime?: SharedValue<number | undefined>;
|
|
3071
|
+
/**
|
|
3072
|
+
* Authoritative history start (Unix seconds). While following without a zoom
|
|
3073
|
+
* override, grows the window to keep this time at the left edge, including
|
|
3074
|
+
* `windowBuffer` (must be < 1). Pan/zoom overrides remain usable; resetZoom()
|
|
3075
|
+
* restores following. A non-finite or future start falls back to timeWindow.
|
|
3076
|
+
*/
|
|
3077
|
+
historyStartTime?: number;
|
|
3078
|
+
/**
|
|
3079
|
+
* Shared-range easing plus an optional reversible UI-thread presentation
|
|
3080
|
+
* transform. See {@link SeriesRangeAnimationConfig}; recorded values remain unchanged.
|
|
3081
|
+
*/
|
|
3082
|
+
rangeAnimation?: SeriesRangeAnimationConfig;
|
|
3032
3083
|
/** Array of series definitions. Must be a SharedValue for UI-thread reads. */
|
|
3033
3084
|
series: SharedValue<SeriesConfig[]>;
|
|
3034
3085
|
/**
|