react-native-livechart 4.31.0 → 4.32.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/README.md +3 -0
- package/dist/components/ChartOverlayLayer.d.ts +3 -1
- package/dist/components/ChartOverlayLayer.d.ts.map +1 -1
- package/dist/components/CrosshairOverlay.d.ts +3 -1
- package/dist/components/CrosshairOverlay.d.ts.map +1 -1
- package/dist/components/CustomMarkerOverlay.d.ts +2 -2
- package/dist/components/CustomMarkerOverlay.d.ts.map +1 -1
- package/dist/components/FreeCrosshairOverlay.d.ts +25 -0
- package/dist/components/FreeCrosshairOverlay.d.ts.map +1 -0
- package/dist/components/LiveChart.d.ts.map +1 -1
- package/dist/components/LiveChartSeries.d.ts.map +1 -1
- package/dist/components/MarkerOverlay.d.ts +2 -2
- package/dist/components/MarkerOverlay.d.ts.map +1 -1
- package/dist/components/ScrubActionOverlay.d.ts +7 -1
- package/dist/components/ScrubActionOverlay.d.ts.map +1 -1
- package/dist/core/liveChartEngineTick.d.ts +2 -0
- package/dist/core/liveChartEngineTick.d.ts.map +1 -1
- package/dist/core/liveChartSeriesEngineTick.d.ts +6 -0
- package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
- package/dist/core/resolveConfig.d.ts +4 -0
- package/dist/core/resolveConfig.d.ts.map +1 -1
- package/dist/core/useLiveChartEngine.d.ts +7 -2
- package/dist/core/useLiveChartEngine.d.ts.map +1 -1
- package/dist/core/useLiveChartSeriesEngine.d.ts +9 -1
- package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
- package/dist/hooks/crosshairSeries.d.ts +1 -1
- package/dist/hooks/crosshairSeries.d.ts.map +1 -1
- package/dist/hooks/crosshairShared.d.ts +4 -2
- package/dist/hooks/crosshairShared.d.ts.map +1 -1
- package/dist/hooks/useCrosshair.d.ts +5 -1
- package/dist/hooks/useCrosshair.d.ts.map +1 -1
- package/dist/hooks/useCrosshairSeries.d.ts.map +1 -1
- package/dist/hooks/useMarkers.d.ts +2 -2
- package/dist/hooks/useMarkers.d.ts.map +1 -1
- package/dist/hooks/usePanScroll.d.ts +2 -0
- package/dist/hooks/usePanScroll.d.ts.map +1 -1
- package/dist/hooks/usePinchZoom.d.ts +2 -0
- package/dist/hooks/usePinchZoom.d.ts.map +1 -1
- package/dist/hooks/useReferenceLineSeries.d.ts +1 -1
- package/dist/hooks/useReferenceLineSeries.d.ts.map +1 -1
- package/dist/hooks/useScrubMarkers.d.ts +2 -1
- package/dist/hooks/useScrubMarkers.d.ts.map +1 -1
- package/dist/hooks/useVisibleRange.d.ts +8 -17
- package/dist/hooks/useVisibleRange.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/math/markers.d.ts +6 -0
- package/dist/math/markers.d.ts.map +1 -1
- package/dist/math/referenceLineSeries.d.ts +1 -1
- package/dist/math/referenceLineSeries.d.ts.map +1 -1
- package/dist/math/scrubMarkers.d.ts +1 -1
- package/dist/math/scrubMarkers.d.ts.map +1 -1
- package/dist/math/spline.d.ts +3 -2
- package/dist/math/spline.d.ts.map +1 -1
- package/dist/types.d.ts +51 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/ChartOverlayLayer.tsx +9 -3
- package/src/components/CrosshairOverlay.tsx +7 -0
- package/src/components/CustomMarkerOverlay.tsx +5 -2
- package/src/components/FreeCrosshairOverlay.tsx +87 -0
- package/src/components/LiveChart.tsx +105 -75
- package/src/components/LiveChartSeries.tsx +41 -22
- package/src/components/MarkerOverlay.tsx +24 -14
- package/src/components/ScrubActionOverlay.tsx +24 -5
- package/src/core/liveChartEngineTick.ts +3 -0
- package/src/core/liveChartSeriesEngineTick.ts +25 -4
- package/src/core/resolveConfig.ts +13 -0
- package/src/core/useLiveChartEngine.ts +14 -2
- package/src/core/useLiveChartSeriesEngine.ts +44 -7
- package/src/hooks/crosshairSeries.ts +4 -4
- package/src/hooks/crosshairShared.ts +18 -12
- package/src/hooks/useCrosshair.ts +29 -5
- package/src/hooks/useCrosshairSeries.ts +10 -4
- package/src/hooks/useMarkers.ts +7 -4
- package/src/hooks/usePanScroll.ts +3 -1
- package/src/hooks/usePinchZoom.ts +8 -5
- package/src/hooks/useReferenceLineSeries.ts +8 -4
- package/src/hooks/useScrubMarkers.ts +5 -2
- package/src/hooks/useVisibleRange.ts +96 -66
- package/src/index.ts +1 -0
- package/src/math/markers.ts +25 -8
- package/src/math/referenceLineSeries.ts +4 -3
- package/src/math/scrubMarkers.ts +4 -1
- package/src/math/spline.ts +41 -25
- package/src/types.ts +49 -7
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
type SharedValue,
|
|
11
11
|
} from "react-native-reanimated";
|
|
12
12
|
import { MS_PER_FRAME_60FPS, RETURN_TO_LIVE_MS } from "../constants";
|
|
13
|
-
import type { LiveChartPoint, SeriesRangeAnimationConfig, SeriesConfig } from "../types";
|
|
13
|
+
import type { LiveChartSeriesProps, LiveChartPoint, SeriesRangeAnimationConfig, SeriesConfig } from "../types";
|
|
14
14
|
import {
|
|
15
15
|
tickLiveChartSeriesEngineFrame,
|
|
16
16
|
type MultiEngineTickInput,
|
|
@@ -36,6 +36,7 @@ export interface MultiSeriesEngineConfig {
|
|
|
36
36
|
yRangeScale?: SharedValue<number>;
|
|
37
37
|
nowOverride?: number;
|
|
38
38
|
presentationTime?: SharedValue<number | undefined>;
|
|
39
|
+
timeHorizon?: LiveChartSeriesProps["timeHorizon"];
|
|
39
40
|
windowBuffer?: number;
|
|
40
41
|
/** Right-edge buffer in seconds. Does not scale with the visible window. */
|
|
41
42
|
windowBufferSeconds?: number;
|
|
@@ -100,6 +101,10 @@ export interface MultiEngineFrameRefs {
|
|
|
100
101
|
yRangeScaleSV?: SharedValue<number>;
|
|
101
102
|
nowOverrideSV?: FrameParameter<number | undefined>;
|
|
102
103
|
presentationTimeSV?: SharedValue<number | undefined>;
|
|
104
|
+
timeHorizon?: LiveChartSeriesProps["timeHorizon"];
|
|
105
|
+
horizonExtensionSV?: SharedValue<number>;
|
|
106
|
+
/** Drawn viewport, including the horizon. Frame easing and gestures use the ordinary pair. */
|
|
107
|
+
presentedViewport?: Pick<MultiEngineState, "timestamp" | "displayWindow">;
|
|
103
108
|
historyStartTimeSV?: FrameParameter<number | undefined>;
|
|
104
109
|
currentTimeSV?: SharedValue<number>;
|
|
105
110
|
fullHistoryWindowSV?: SharedValue<number | null>;
|
|
@@ -119,6 +124,7 @@ export interface MultiEngineFrameRefs {
|
|
|
119
124
|
viewWindowSV?: SharedValue<number | null>;
|
|
120
125
|
/** Receives the computed live edge each frame. Optional for callers/tests. */
|
|
121
126
|
liveEdgeSV?: SharedValue<number>;
|
|
127
|
+
followingSV?: SharedValue<boolean>;
|
|
122
128
|
/**
|
|
123
129
|
* One-shot "snap the framing this frame" flag (set by the `snapKey` effect).
|
|
124
130
|
* Consumed and cleared by {@link applyLiveChartSeriesEngineFrame} after the
|
|
@@ -250,7 +256,10 @@ export function applyLiveChartSeriesEngineFrame(
|
|
|
250
256
|
state.displayMax = sv.displayMax.value;
|
|
251
257
|
state.fittedMin = sv.fittedMinSV?.value ?? state.fittedMin;
|
|
252
258
|
state.fittedMax = sv.fittedMaxSV?.value ?? state.fittedMax;
|
|
253
|
-
|
|
259
|
+
// A pinch supplies the exact width for its focal edge. Apply both on this
|
|
260
|
+
// frame so drawing and paging always read a complete viewport.
|
|
261
|
+
const requestedWindow = sv.viewWindowSV?.value;
|
|
262
|
+
state.displayWindow = requestedWindow ?? sv.displayWindow.value;
|
|
254
263
|
state.timestamp = sv.timestamp.value;
|
|
255
264
|
state.liveEdge = sv.liveEdgeSV?.value ?? 0;
|
|
256
265
|
state.displayValues = displayValues;
|
|
@@ -286,6 +295,8 @@ export function applyLiveChartSeriesEngineFrame(
|
|
|
286
295
|
input.yRangeScale = sv.yRangeScaleSV?.value ?? 1;
|
|
287
296
|
input.nowOverride = sv.nowOverrideSV?.value;
|
|
288
297
|
input.presentationTime = sv.presentationTimeSV?.value;
|
|
298
|
+
input.timeHorizonAt = sv.timeHorizon?.at;
|
|
299
|
+
input.timeHorizonProgress = sv.timeHorizon?.progress.value;
|
|
289
300
|
input.historyStartTime = sv.historyStartTimeSV?.value;
|
|
290
301
|
input.windowBuffer = sv.windowBufferSV?.value ?? 0;
|
|
291
302
|
input.windowBufferSeconds = sv.windowBufferSecondsSV?.value ?? 0;
|
|
@@ -297,7 +308,7 @@ export function applyLiveChartSeriesEngineFrame(
|
|
|
297
308
|
input.allowFutureViewEnd = sv.allowFutureViewEndSV?.value ?? false;
|
|
298
309
|
input.returnT = sv.returnTSV?.value;
|
|
299
310
|
input.returnFrom = sv.returnFromSV?.value;
|
|
300
|
-
input.viewWindow =
|
|
311
|
+
input.viewWindow = requestedWindow;
|
|
301
312
|
tickLiveChartSeriesEngineFrame(state, input);
|
|
302
313
|
sv.displayMin.value = state.displayMin;
|
|
303
314
|
sv.displayMax.value = state.displayMax;
|
|
@@ -305,7 +316,14 @@ export function applyLiveChartSeriesEngineFrame(
|
|
|
305
316
|
if (sv.fittedMaxSV) sv.fittedMaxSV.value = state.fittedMax;
|
|
306
317
|
sv.displayWindow.value = state.displayWindow;
|
|
307
318
|
sv.timestamp.value = state.timestamp;
|
|
319
|
+
const extension = state.horizonExtension!;
|
|
320
|
+
if (sv.horizonExtensionSV) sv.horizonExtensionSV.value = extension;
|
|
321
|
+
if (sv.presentedViewport) {
|
|
322
|
+
sv.presentedViewport.timestamp.value = state.timestamp + extension;
|
|
323
|
+
sv.presentedViewport.displayWindow.value = state.displayWindow + extension;
|
|
324
|
+
}
|
|
308
325
|
if (sv.liveEdgeSV) sv.liveEdgeSV.value = state.liveEdge;
|
|
326
|
+
if (sv.followingSV) sv.followingSV.value = state.following!;
|
|
309
327
|
if (sv.currentTimeSV) sv.currentTimeSV.value = state.currentTime!;
|
|
310
328
|
if (sv.fullHistoryWindowSV) sv.fullHistoryWindowSV.value = state.fullHistoryWindow ?? null;
|
|
311
329
|
sv.displaySeriesValues.value = state.displayValues;
|
|
@@ -343,13 +361,24 @@ export function useLiveChartSeriesEngine(
|
|
|
343
361
|
config: MultiSeriesEngineConfig,
|
|
344
362
|
): MultiEngineState & ChartEngineScroll & {
|
|
345
363
|
currentTime: SharedValue<number>;
|
|
364
|
+
navigationWindow: SharedValue<number>;
|
|
365
|
+
navigationEnd: SharedValue<number>;
|
|
346
366
|
fullHistoryWindow: SharedValue<number | null>;
|
|
347
367
|
} {
|
|
348
368
|
// Pinch-zoom window-width override (null = follow the configured window).
|
|
349
369
|
// Declared first so `timeWindow` folds it in — see useLiveChartEngine.
|
|
350
370
|
const viewWindow = useSharedValue<number | null>(null);
|
|
351
371
|
const fullHistoryWindow = useSharedValue<number | null>(null);
|
|
352
|
-
const
|
|
372
|
+
const navigationWindow = useSharedValue(config.timeWindow);
|
|
373
|
+
const horizonExtension = useSharedValue(0);
|
|
374
|
+
const displayWindow = useSharedValue(config.timeWindow);
|
|
375
|
+
const baseTimeWindow = config.timeWindow;
|
|
376
|
+
const timeWindow = useDerivedValue(() => {
|
|
377
|
+
// During a reveal, select ticks across the whole painted span. Ordinary
|
|
378
|
+
// zoom and preset transitions select ticks from their destination (#126).
|
|
379
|
+
if (horizonExtension.value > 0) return displayWindow.value;
|
|
380
|
+
return viewWindow.value ?? fullHistoryWindow.value ?? baseTimeWindow;
|
|
381
|
+
});
|
|
353
382
|
// These are React props, not UI-thread signals. The registered frame and
|
|
354
383
|
// return-to-live worklets capture a fresh snapshot when props change. Keeping
|
|
355
384
|
// them as plain values avoids one native mutable and mapper per parameter.
|
|
@@ -380,11 +409,11 @@ export function useLiveChartSeriesEngine(
|
|
|
380
409
|
const displayMax = useSharedValue(1);
|
|
381
410
|
const fittedMinSV = useSharedValue<number | undefined>(undefined);
|
|
382
411
|
const fittedMaxSV = useSharedValue<number | undefined>(undefined);
|
|
383
|
-
const displayWindow = useSharedValue(config.timeWindow);
|
|
384
412
|
const canvasWidth = useSharedValue(0);
|
|
385
413
|
const canvasHeight = useSharedValue(0);
|
|
386
414
|
// Seed once; overwritten by the frame callback on the first tick.
|
|
387
415
|
const [initialTimestamp] = useState(() => Date.now() / 1000);
|
|
416
|
+
const navigationEnd = useSharedValue(initialTimestamp);
|
|
388
417
|
const timestamp = useSharedValue(initialTimestamp);
|
|
389
418
|
const currentTime = useSharedValue(initialTimestamp);
|
|
390
419
|
const tipTime = useDerivedValue(() => Math.min(timestamp.value, currentTime.value));
|
|
@@ -392,6 +421,7 @@ export function useLiveChartSeriesEngine(
|
|
|
392
421
|
// Pan-scroll state (see useLiveChartEngine). Defaults to following live.
|
|
393
422
|
const viewEnd = useSharedValue<number | null>(null);
|
|
394
423
|
const liveEdge = useSharedValue(initialTimestamp);
|
|
424
|
+
const following = useSharedValue(!config.paused);
|
|
395
425
|
// "Return to live" glide (see #164) — `returnT` rests at 1; the reaction below
|
|
396
426
|
// animates it 0→1 from `returnFrom` when time-scroll is disabled while scrolled.
|
|
397
427
|
const returnT = useSharedValue(1);
|
|
@@ -447,8 +477,9 @@ export function useLiveChartSeriesEngine(
|
|
|
447
477
|
displayMax,
|
|
448
478
|
fittedMinSV,
|
|
449
479
|
fittedMaxSV,
|
|
450
|
-
displayWindow,
|
|
451
|
-
timestamp,
|
|
480
|
+
displayWindow: navigationWindow,
|
|
481
|
+
timestamp: navigationEnd,
|
|
482
|
+
presentedViewport: { timestamp, displayWindow },
|
|
452
483
|
canvasWidth,
|
|
453
484
|
canvasHeight,
|
|
454
485
|
timeWindow: configuredTimeWindow,
|
|
@@ -466,6 +497,8 @@ export function useLiveChartSeriesEngine(
|
|
|
466
497
|
yRangeScaleSV: config.yRangeScale,
|
|
467
498
|
nowOverrideSV,
|
|
468
499
|
presentationTimeSV: config.presentationTime,
|
|
500
|
+
timeHorizon: config.timeHorizon,
|
|
501
|
+
horizonExtensionSV: horizonExtension,
|
|
469
502
|
currentTimeSV: currentTime,
|
|
470
503
|
windowBufferSV,
|
|
471
504
|
windowBufferSecondsSV,
|
|
@@ -476,6 +509,7 @@ export function useLiveChartSeriesEngine(
|
|
|
476
509
|
returnFromSV: returnFrom,
|
|
477
510
|
viewWindowSV: viewWindow,
|
|
478
511
|
liveEdgeSV: liveEdge,
|
|
512
|
+
followingSV: following,
|
|
479
513
|
snapSV,
|
|
480
514
|
initialFitPendingSV,
|
|
481
515
|
extremaMinValue,
|
|
@@ -529,12 +563,15 @@ export function useLiveChartSeriesEngine(
|
|
|
529
563
|
displayMin,
|
|
530
564
|
displayMax,
|
|
531
565
|
displayWindow,
|
|
566
|
+
navigationWindow,
|
|
567
|
+
navigationEnd,
|
|
532
568
|
timeWindow,
|
|
533
569
|
canvasWidth,
|
|
534
570
|
canvasHeight,
|
|
535
571
|
timestamp,
|
|
536
572
|
viewEnd,
|
|
537
573
|
viewWindow,
|
|
574
|
+
following,
|
|
538
575
|
liveEdge,
|
|
539
576
|
currentTime,
|
|
540
577
|
tipTime,
|
|
@@ -107,7 +107,7 @@ function clamp(value: number, min: number, max: number): number {
|
|
|
107
107
|
*/
|
|
108
108
|
export function computePerSeriesTooltipLayout(
|
|
109
109
|
scrubActive: boolean,
|
|
110
|
-
|
|
110
|
+
projectedX: number,
|
|
111
111
|
scrubTime: number,
|
|
112
112
|
series: SeriesConfig[],
|
|
113
113
|
displaySeriesValues: number[],
|
|
@@ -135,9 +135,8 @@ export function computePerSeriesTooltipLayout(
|
|
|
135
135
|
const plotBottom = canvasHeight - padding.bottom;
|
|
136
136
|
if (plotRight <= plotLeft || plotBottom <= plotTop) return HIDDEN_TOOLTIP;
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
: clamp(scrubX, plotLeft, plotRight);
|
|
138
|
+
if (pinned && projectedX < plotLeft) return HIDDEN_TOOLTIP;
|
|
139
|
+
const anchorX = clamp(projectedX, plotLeft, plotRight);
|
|
141
140
|
const activeTime = Math.min(scrubTime, maxTime);
|
|
142
141
|
if (!pinned && activeTime < 0) return HIDDEN_TOOLTIP;
|
|
143
142
|
|
|
@@ -155,6 +154,7 @@ export function computePerSeriesTooltipLayout(
|
|
|
155
154
|
for (let i = 0; i < renderedSeriesCount; i++) {
|
|
156
155
|
const item = series[i];
|
|
157
156
|
if (item.visible === false || item.data.length === 0) continue;
|
|
157
|
+
if (pinned && item.data[0].time > maxTime) continue;
|
|
158
158
|
const value = pinned
|
|
159
159
|
? (displaySeriesValues[i] ?? item.value)
|
|
160
160
|
: valueAtTime(item, activeTime, maxTime, displaySeriesValues[i]);
|
|
@@ -220,6 +220,10 @@ export interface CrosshairState {
|
|
|
220
220
|
timeBadge?: SharedValue<TimeBadgeLayout>;
|
|
221
221
|
/** Tap gesture that places/moves the reticle, presses the badge, or dismisses. */
|
|
222
222
|
tapGesture?: ReturnType<typeof Gesture.Tap>;
|
|
223
|
+
|
|
224
|
+
// ── Free X/Y crosshair (`scrub.freeCrosshair`) — single-series only. ───────
|
|
225
|
+
/** Finger Y in canvas px, clamped to the plot (-1 when not scrubbing). */
|
|
226
|
+
freeY?: SharedValue<number>;
|
|
223
227
|
}
|
|
224
228
|
|
|
225
229
|
/**
|
|
@@ -840,12 +844,13 @@ export function computeActionBadgeLayout(
|
|
|
840
844
|
priceText: string,
|
|
841
845
|
icon: string,
|
|
842
846
|
canvasWidth: number,
|
|
843
|
-
/** Plot
|
|
844
|
-
|
|
847
|
+
/** Plot edge adjacent to the price axis. */
|
|
848
|
+
plotEdge: number,
|
|
845
849
|
font: SkFont,
|
|
846
850
|
marginEdge: number,
|
|
847
851
|
padX: number,
|
|
848
852
|
padY: number,
|
|
853
|
+
side: "left" | "right" = "right",
|
|
849
854
|
): ActionBadgeLayout {
|
|
850
855
|
"worklet";
|
|
851
856
|
if (!locked || canvasWidth <= 0) return HIDDEN_ACTION_BADGE;
|
|
@@ -857,15 +862,16 @@ export function computeActionBadgeLayout(
|
|
|
857
862
|
const pillH = font.getSize() + padY * 2;
|
|
858
863
|
const r = pillH / 2;
|
|
859
864
|
const top = lockY - pillH / 2;
|
|
860
|
-
const
|
|
865
|
+
const leftAxis = side === "left";
|
|
866
|
+
const edge = leftAxis ? marginEdge : canvasWidth - marginEdge;
|
|
861
867
|
|
|
862
868
|
const fm = font.getMetrics();
|
|
863
869
|
const textY = lockY - (fm.ascent + fm.descent) / 2;
|
|
864
870
|
|
|
865
871
|
// Price pill (the readout) sits in the price-axis gutter, anchored to the edge.
|
|
866
872
|
let priceW = 0;
|
|
867
|
-
let priceX =
|
|
868
|
-
let priceTextX =
|
|
873
|
+
let priceX = edge;
|
|
874
|
+
let priceTextX = edge;
|
|
869
875
|
if (hasPrice) {
|
|
870
876
|
// Size the pill to the text's ACTUAL visual bounds (+ pad each side), then
|
|
871
877
|
// position the text origin so the *ink* — not the advance box — is centered:
|
|
@@ -881,19 +887,19 @@ export function computeActionBadgeLayout(
|
|
|
881
887
|
// while a reticle is shown). See the price-pill centering tests.
|
|
882
888
|
const bounds = font.measureText(priceText);
|
|
883
889
|
priceW = bounds.width + padX * 2;
|
|
884
|
-
priceX =
|
|
890
|
+
priceX = leftAxis ? edge : edge - priceW;
|
|
885
891
|
priceTextX = priceX + padX - bounds.x;
|
|
886
892
|
}
|
|
887
893
|
|
|
888
|
-
//
|
|
889
|
-
|
|
890
|
-
let iconCx = plotRight;
|
|
894
|
+
// The action button sits on the plot-facing side of the pill.
|
|
895
|
+
let iconCx = plotEdge;
|
|
891
896
|
if (hasIcon && hasPrice) {
|
|
892
|
-
|
|
897
|
+
const gapToCenter = ACTION_BADGE_GAP + r;
|
|
898
|
+
iconCx = leftAxis ? priceX + priceW + gapToCenter : priceX - gapToCenter;
|
|
893
899
|
}
|
|
894
900
|
|
|
895
|
-
const unionLeft = hasIcon ? iconCx - r
|
|
896
|
-
const unionRight = hasPrice ?
|
|
901
|
+
const unionLeft = hasPrice && (leftAxis || !hasIcon) ? priceX : iconCx - r;
|
|
902
|
+
const unionRight = hasPrice && (!leftAxis || !hasIcon) ? priceX + priceW : iconCx + r;
|
|
897
903
|
|
|
898
904
|
return {
|
|
899
905
|
x: unionLeft,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SkFont } from "@shopify/react-native-skia";
|
|
2
|
-
import { useMemo, useRef } from "react";
|
|
2
|
+
import { useCallback, useMemo, useRef } from "react";
|
|
3
3
|
import { Gesture } from "react-native-gesture-handler";
|
|
4
4
|
import {
|
|
5
5
|
useAnimatedReaction,
|
|
@@ -110,6 +110,8 @@ export {
|
|
|
110
110
|
} from "./crosshairShared";
|
|
111
111
|
|
|
112
112
|
export interface CrosshairChartOpts {
|
|
113
|
+
/** Track finger Y for the optional free-crosshair guides. */
|
|
114
|
+
freeCrosshair?: boolean;
|
|
113
115
|
mode: "line" | "candle";
|
|
114
116
|
candles?: SharedValue<CandlePoint[]>;
|
|
115
117
|
liveCandle?: SharedValue<CandlePoint | null>;
|
|
@@ -221,7 +223,7 @@ export function useCrosshair(
|
|
|
221
223
|
axisScaleActive?: SharedValue<boolean>,
|
|
222
224
|
/** Buffered line charts must not expose synthetic prices in future space. */
|
|
223
225
|
shouldClampToLatestPoint = false,
|
|
224
|
-
): CrosshairState {
|
|
226
|
+
): CrosshairState & { hitTestActionBadge: (x: number, y: number) => boolean } {
|
|
225
227
|
// Config objects may be recreated without changing the plot geometry. Keep
|
|
226
228
|
// worklet closures and gestures stable until an actual inset changes.
|
|
227
229
|
const { top, right, bottom, left } = paddingInput;
|
|
@@ -230,6 +232,8 @@ export function useCrosshair(
|
|
|
230
232
|
[top, right, bottom, left],
|
|
231
233
|
);
|
|
232
234
|
const scrubPointerX = useSharedValue(-1);
|
|
235
|
+
const scrubPointerY = useSharedValue(-1);
|
|
236
|
+
const hasFreeCrosshair = chartOpts?.freeCrosshair ?? false;
|
|
233
237
|
const scrubGestureActive = useSharedValue(false);
|
|
234
238
|
// Tracks whether the active scrub phase actually began, so a tap that never
|
|
235
239
|
// activates doesn't emit a spurious onGestureEnd.
|
|
@@ -486,6 +490,12 @@ export function useCrosshair(
|
|
|
486
490
|
const lockCandle = useSharedValue<CandlePoint | null>(null);
|
|
487
491
|
const actionBadge = useSharedValue(HIDDEN_ACTION_BADGE);
|
|
488
492
|
const timeBadge = useSharedValue(HIDDEN_TIME_BADGE);
|
|
493
|
+
const hitTestActionBadge = useCallback((x: number, y: number): boolean => {
|
|
494
|
+
"worklet";
|
|
495
|
+
if (!enabled || !hasScrubAction || !lockActive.get()) return false;
|
|
496
|
+
const rect = actionBadge.get();
|
|
497
|
+
return rect.visible && pointInRect(x, y, rect, ACTION_HIT_SLOP);
|
|
498
|
+
}, [enabled, hasScrubAction, lockActive, actionBadge]);
|
|
489
499
|
|
|
490
500
|
// The lock price, projected coordinates, candle and both badges are one
|
|
491
501
|
// coherent reticle snapshot. Publishing them from one reaction replaces six
|
|
@@ -877,6 +887,11 @@ export function useCrosshair(
|
|
|
877
887
|
deferTapHit(downX.get(), downY.get())
|
|
878
888
|
)
|
|
879
889
|
return;
|
|
890
|
+
if (hasFreeCrosshair) {
|
|
891
|
+
scrubPointerY.set(
|
|
892
|
+
clampPlotY(e.y, padding.top, canvasHeightSV.get(), padding.bottom),
|
|
893
|
+
);
|
|
894
|
+
}
|
|
880
895
|
startPlainScrub(
|
|
881
896
|
snapCandleX(e.x),
|
|
882
897
|
padding,
|
|
@@ -918,6 +933,11 @@ export function useCrosshair(
|
|
|
918
933
|
}
|
|
919
934
|
return;
|
|
920
935
|
}
|
|
936
|
+
if (hasFreeCrosshair && scrubGestureActive.get()) {
|
|
937
|
+
scrubPointerY.set(
|
|
938
|
+
clampPlotY(e.y, padding.top, canvasHeightSV.get(), padding.bottom),
|
|
939
|
+
);
|
|
940
|
+
}
|
|
921
941
|
updatePlainScrub(
|
|
922
942
|
snapCandleX(e.x),
|
|
923
943
|
padding,
|
|
@@ -934,6 +954,7 @@ export function useCrosshair(
|
|
|
934
954
|
resetDelayedPanGuard(fingerDown, panActivated, holdBroken);
|
|
935
955
|
// A lock-adjust drag leaves the reticle in place. End the gesture even
|
|
936
956
|
// when its visible selection is hidden outside the recorded window.
|
|
957
|
+
scrubPointerY.set(-1);
|
|
937
958
|
if (scrubGestureActive.get()) {
|
|
938
959
|
scrubGestureActive.set(false);
|
|
939
960
|
if (hasOnScrub) scheduleOnRN(handleScrubEnd);
|
|
@@ -982,8 +1003,7 @@ export function useCrosshair(
|
|
|
982
1003
|
if (!enabled || !hasScrubAction || !success) return;
|
|
983
1004
|
if (lockActive.get()) {
|
|
984
1005
|
// 1. Action-badge press → fire onScrubAction with the chosen price.
|
|
985
|
-
|
|
986
|
-
if (rect.visible && pointInRect(e.x, e.y, rect, ACTION_HIT_SLOP)) {
|
|
1006
|
+
if (hitTestActionBadge(e.x, e.y)) {
|
|
987
1007
|
const price = lockPrice.get();
|
|
988
1008
|
if (price !== null) {
|
|
989
1009
|
let candleJson: string | null = null;
|
|
@@ -1052,7 +1072,6 @@ export function useCrosshair(
|
|
|
1052
1072
|
if (tapGesture && tapHitSlop) tapGesture = tapGesture.hitSlop(tapHitSlop);
|
|
1053
1073
|
return { gesture, tapGesture };
|
|
1054
1074
|
}, [
|
|
1055
|
-
actionBadge,
|
|
1056
1075
|
axisScaleActive,
|
|
1057
1076
|
candleWidthSecs,
|
|
1058
1077
|
candlesSV,
|
|
@@ -1076,11 +1095,13 @@ export function useCrosshair(
|
|
|
1076
1095
|
handleGestureStart,
|
|
1077
1096
|
handleScrubAction,
|
|
1078
1097
|
handleScrubEnd,
|
|
1098
|
+
hasFreeCrosshair,
|
|
1079
1099
|
hasOnGestureEnd,
|
|
1080
1100
|
hasOnGestureStart,
|
|
1081
1101
|
hasOnScrub,
|
|
1082
1102
|
hasOnScrubAction,
|
|
1083
1103
|
hasScrubAction,
|
|
1104
|
+
hitTestActionBadge,
|
|
1084
1105
|
holdBroken,
|
|
1085
1106
|
isCandleMode,
|
|
1086
1107
|
liveCandleSV,
|
|
@@ -1098,6 +1119,7 @@ export function useCrosshair(
|
|
|
1098
1119
|
scrubGestureActive,
|
|
1099
1120
|
scrubBottomExclude,
|
|
1100
1121
|
scrubPointerX,
|
|
1122
|
+
scrubPointerY,
|
|
1101
1123
|
snapToCandles,
|
|
1102
1124
|
timestampSV,
|
|
1103
1125
|
]);
|
|
@@ -1120,7 +1142,9 @@ export function useCrosshair(
|
|
|
1120
1142
|
lockY,
|
|
1121
1143
|
lockPrice,
|
|
1122
1144
|
actionBadge,
|
|
1145
|
+
hitTestActionBadge,
|
|
1123
1146
|
timeBadge,
|
|
1124
1147
|
tapGesture,
|
|
1148
|
+
freeY: hasFreeCrosshair ? scrubPointerY : undefined,
|
|
1125
1149
|
};
|
|
1126
1150
|
}
|
|
@@ -158,9 +158,15 @@ export function useCrosshairSeries(
|
|
|
158
158
|
|
|
159
159
|
const tooltipLayout = useDerivedValue(() => {
|
|
160
160
|
if (!tooltip) return HIDDEN_TOOLTIP;
|
|
161
|
+
const active = scrubActive.get();
|
|
162
|
+
const canvasWidth = engine.canvasWidth.get();
|
|
163
|
+
const head = tooltip.maxTime.get();
|
|
164
|
+
const anchorX = !active && tooltip.config.alwaysShow
|
|
165
|
+
? lineTipX(engine.timestamp.get(), engine.displayWindow.get(), head, canvasWidth, padding)
|
|
166
|
+
: scrubX.get();
|
|
161
167
|
return computePerSeriesTooltipLayout(
|
|
162
|
-
|
|
163
|
-
|
|
168
|
+
active,
|
|
169
|
+
anchorX,
|
|
164
170
|
scrubTime.get(),
|
|
165
171
|
engine.series.get(),
|
|
166
172
|
engine.displaySeriesValues.get(),
|
|
@@ -168,9 +174,9 @@ export function useCrosshairSeries(
|
|
|
168
174
|
engine.displayMin.get(),
|
|
169
175
|
engine.displayMax.get(),
|
|
170
176
|
padding,
|
|
171
|
-
|
|
177
|
+
canvasWidth,
|
|
172
178
|
engine.canvasHeight.get(),
|
|
173
|
-
|
|
179
|
+
head,
|
|
174
180
|
tooltip.formatValue,
|
|
175
181
|
tooltip.formatTime,
|
|
176
182
|
tooltip.font,
|
package/src/hooks/useMarkers.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
type SharedValue,
|
|
8
8
|
} from "react-native-reanimated";
|
|
9
9
|
import { runOnJS } from "react-native-worklets";
|
|
10
|
-
import type {
|
|
10
|
+
import type { MarkerEngineLayout } from "../core/useLiveChartEngine";
|
|
11
11
|
import type { ChartPadding } from "../draw/line";
|
|
12
12
|
import { projectMarkers, type ProjectedMarker } from "../math/markers";
|
|
13
13
|
import { nearestMarkerIndex } from "../math/markers";
|
|
@@ -43,7 +43,7 @@ const ANCHORED_CLUSTER: ResolvedMarkerCluster = {
|
|
|
43
43
|
* drawn (stacked / collapsed) positions.
|
|
44
44
|
*/
|
|
45
45
|
export function useMarkers(
|
|
46
|
-
engine:
|
|
46
|
+
engine: MarkerEngineLayout,
|
|
47
47
|
padding: ChartPadding,
|
|
48
48
|
markers: SharedValue<Marker[]>,
|
|
49
49
|
active: boolean,
|
|
@@ -104,6 +104,9 @@ export function useMarkers(
|
|
|
104
104
|
padLeft: padding.left,
|
|
105
105
|
padRight: padding.right,
|
|
106
106
|
timestamp: engine.timestamp.get(),
|
|
107
|
+
tipTime: engine.tipTime?.get(),
|
|
108
|
+
displaySeriesValues: engine.displaySeriesValues?.get(),
|
|
109
|
+
smoothRecordedTail: engine.smoothRecordedTail?.get(),
|
|
107
110
|
displayWindow: engine.displayWindow.get(),
|
|
108
111
|
displayMin: engine.displayMin.get(),
|
|
109
112
|
displayMax: engine.displayMax.get(),
|
|
@@ -124,8 +127,8 @@ export function useMarkers(
|
|
|
124
127
|
() => {
|
|
125
128
|
if (!autoSleep || !autostart) return null;
|
|
126
129
|
return [active, markers.get(), engine.canvasWidth.get(), engine.canvasHeight.get(),
|
|
127
|
-
engine.timestamp.get(), engine.displayWindow.get(), engine.displayMin.get(),
|
|
128
|
-
engine.displayMax.get(), seriesSV?.get(), lineData?.get(), isFrameLoopActive?.get()];
|
|
130
|
+
engine.timestamp.get(), engine.tipTime?.get(), engine.displayWindow.get(), engine.displayMin.get(),
|
|
131
|
+
engine.displayMax.get(), engine.displaySeriesValues?.get(), engine.smoothRecordedTail?.get(), seriesSV?.get(), lineData?.get(), isFrameLoopActive?.get()];
|
|
129
132
|
},
|
|
130
133
|
(inputs) => {
|
|
131
134
|
if (inputs !== null) project();
|
|
@@ -35,6 +35,8 @@ export interface PanScrollEngineRefs {
|
|
|
35
35
|
liveEdge: SharedValue<number>;
|
|
36
36
|
/** Animating visible window width in seconds. */
|
|
37
37
|
displayWindow: SharedValue<number>;
|
|
38
|
+
/** Ordinary window before any presentation-only future horizon. */
|
|
39
|
+
navigationWindow?: SharedValue<number>;
|
|
38
40
|
/** Canvas width in px. */
|
|
39
41
|
canvasWidth: SharedValue<number>;
|
|
40
42
|
/** Canvas height in px (for the axis-drag band hit-test). */
|
|
@@ -307,7 +309,6 @@ export function usePanScroll({
|
|
|
307
309
|
const {
|
|
308
310
|
viewEnd,
|
|
309
311
|
liveEdge,
|
|
310
|
-
displayWindow,
|
|
311
312
|
canvasWidth,
|
|
312
313
|
canvasHeight,
|
|
313
314
|
viewRange,
|
|
@@ -318,6 +319,7 @@ export function usePanScroll({
|
|
|
318
319
|
fitMax,
|
|
319
320
|
viewWindow,
|
|
320
321
|
} = engine;
|
|
322
|
+
const displayWindow = engine.navigationWindow ?? engine.displayWindow;
|
|
321
323
|
const padLeft = padding.left;
|
|
322
324
|
const padRight = padding.right;
|
|
323
325
|
const padTop = padding.top;
|
|
@@ -25,6 +25,8 @@ export interface PinchZoomEngineRefs {
|
|
|
25
25
|
* `timeWindow` would otherwise lag a fast pinch and the focal anchor would drift).
|
|
26
26
|
*/
|
|
27
27
|
displayWindow: SharedValue<number>;
|
|
28
|
+
/** Frame-published navigation width on multi-series charts, before the future horizon. */
|
|
29
|
+
navigationWindow?: SharedValue<number>;
|
|
28
30
|
/** Canvas width in px. */
|
|
29
31
|
canvasWidth: SharedValue<number>;
|
|
30
32
|
}
|
|
@@ -169,7 +171,7 @@ export function usePinchZoom({
|
|
|
169
171
|
onZoomStart,
|
|
170
172
|
overscroll = 0,
|
|
171
173
|
}: UsePinchZoomOptions): ReturnType<typeof Gesture.Pinch> {
|
|
172
|
-
const { viewWindow, viewEnd, liveEdge, displayWindow, canvasWidth } = engine;
|
|
174
|
+
const { viewWindow, viewEnd, liveEdge, displayWindow, navigationWindow, canvasWidth } = engine;
|
|
173
175
|
const padLeft = padding.left;
|
|
174
176
|
const padRight = padding.right;
|
|
175
177
|
|
|
@@ -189,7 +191,7 @@ export function usePinchZoom({
|
|
|
189
191
|
cancelAnimation(viewEnd);
|
|
190
192
|
cancelAnimation(viewWindow);
|
|
191
193
|
const edge = liveEdge.get();
|
|
192
|
-
startWindow.set(displayWindow.get());
|
|
194
|
+
startWindow.set(navigationWindow ? viewWindow.get() ?? navigationWindow.get() : displayWindow.get());
|
|
193
195
|
startViewEnd.set(viewEnd.get() ?? edge);
|
|
194
196
|
onZoomStart?.();
|
|
195
197
|
};
|
|
@@ -228,9 +230,9 @@ export function usePinchZoom({
|
|
|
228
230
|
const hi = overscroll > 0 ? panUpperBound(newWin, edge, overscroll) : edge;
|
|
229
231
|
if (newEnd > hi) newEnd = hi;
|
|
230
232
|
viewWindow.set(newWin);
|
|
231
|
-
//
|
|
232
|
-
//
|
|
233
|
-
displayWindow.set(newWin);
|
|
233
|
+
// The multi-series frame publishes both viewport edges and widths together.
|
|
234
|
+
// The single-series engine uses this write to bypass its window easing.
|
|
235
|
+
if (!navigationWindow) displayWindow.set(newWin);
|
|
234
236
|
// Unlike the pan (see nextViewEnd), snapping to `null` mid-gesture is safe
|
|
235
237
|
// here: the pinch maps cumulative scale/focal from a gesture-START snapshot
|
|
236
238
|
// (`startViewEnd`), not per-frame deltas, so a snap can't re-anchor it.
|
|
@@ -250,6 +252,7 @@ export function usePinchZoom({
|
|
|
250
252
|
}, [
|
|
251
253
|
canvasWidth,
|
|
252
254
|
displayWindow,
|
|
255
|
+
navigationWindow,
|
|
253
256
|
enabled,
|
|
254
257
|
fullHistoryWindow,
|
|
255
258
|
liveEdge,
|
|
@@ -17,7 +17,7 @@ export interface ReferenceLineSeriesGeometry {
|
|
|
17
17
|
screenPts: SharedValue<number[]>;
|
|
18
18
|
/** Whether any series segment crosses the visible plot. */
|
|
19
19
|
visible: SharedValue<boolean>;
|
|
20
|
-
/** Series value at the
|
|
20
|
+
/** Series value at the presented data head. */
|
|
21
21
|
currentValue: SharedValue<number>;
|
|
22
22
|
/** Canvas Y coordinate of {@link currentValue}. */
|
|
23
23
|
currentY: SharedValue<number>;
|
|
@@ -46,6 +46,7 @@ export function useReferenceLineSeries(
|
|
|
46
46
|
cacheRef.current = { a: [], b: [], tick: false };
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
const headTime = engine.tipTime ?? engine.timestamp;
|
|
49
50
|
const screenPts = useDerivedValue(() => {
|
|
50
51
|
const cache = cacheRef.current!;
|
|
51
52
|
cache.tick = !cache.tick;
|
|
@@ -61,6 +62,7 @@ export function useReferenceLineSeries(
|
|
|
61
62
|
extendToStart,
|
|
62
63
|
extendToNow,
|
|
63
64
|
cache.tick ? cache.a : cache.b,
|
|
65
|
+
headTime.get(),
|
|
64
66
|
);
|
|
65
67
|
});
|
|
66
68
|
|
|
@@ -74,7 +76,7 @@ export function useReferenceLineSeries(
|
|
|
74
76
|
);
|
|
75
77
|
|
|
76
78
|
const currentValue = useDerivedValue(
|
|
77
|
-
() => interpolateAtTime(points,
|
|
79
|
+
() => interpolateAtTime(points, headTime.get()) ?? NaN,
|
|
78
80
|
);
|
|
79
81
|
const currentY = useDerivedValue(() =>
|
|
80
82
|
thresholdLineY(
|
|
@@ -88,10 +90,12 @@ export function useReferenceLineSeries(
|
|
|
88
90
|
);
|
|
89
91
|
const currentVisible = useDerivedValue(() => {
|
|
90
92
|
if (points.length === 0) return false;
|
|
91
|
-
|
|
93
|
+
const head = headTime.get();
|
|
94
|
+
if (head < engine.timestamp.get() - engine.displayWindow.get()) return false;
|
|
95
|
+
if (!extendToStart && points[0].time > head) {
|
|
92
96
|
return false;
|
|
93
97
|
}
|
|
94
|
-
if (!extendToNow && points[points.length - 1].time <
|
|
98
|
+
if (!extendToNow && points[points.length - 1].time < head) {
|
|
95
99
|
return false;
|
|
96
100
|
}
|
|
97
101
|
return thresholdVisible(
|
|
@@ -10,15 +10,17 @@ import type { CandlePoint, ChartGap, Marker } from "../types";
|
|
|
10
10
|
export interface ScrubMarkerOptions {
|
|
11
11
|
markers: SharedValue<Marker[]>;
|
|
12
12
|
radius: number;
|
|
13
|
+
tipTime?: SharedValue<number>;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
/** Adapt resolved config for both crosshair hooks. */
|
|
16
17
|
export function resolveScrubMarkerOptions(
|
|
17
18
|
config: ResolvedScrubConfig | null,
|
|
18
19
|
markers: SharedValue<Marker[]>,
|
|
20
|
+
tipTime?: SharedValue<number>,
|
|
19
21
|
): ScrubMarkerOptions | undefined {
|
|
20
22
|
if (!config?.markers) return undefined;
|
|
21
|
-
return { markers, radius: config.markers.radius };
|
|
23
|
+
return { markers, radius: config.markers.radius, tipTime };
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
/** Selection changes notify tooltip consumers; movement within a match does not. */
|
|
@@ -50,6 +52,7 @@ export function useScrubMarkers(
|
|
|
50
52
|
if (!options || !active.get() || gap?.get()) return null;
|
|
51
53
|
return {
|
|
52
54
|
markers: source.get(),
|
|
55
|
+
tipTime: options.tipTime?.get(),
|
|
53
56
|
range: scrubMarkerRange(
|
|
54
57
|
time.get(),
|
|
55
58
|
now.get(),
|
|
@@ -63,7 +66,7 @@ export function useScrubMarkers(
|
|
|
63
66
|
};
|
|
64
67
|
},
|
|
65
68
|
(input, previous) => {
|
|
66
|
-
const next = input ? matchScrubMarkers(input.markers, input.range) : [];
|
|
69
|
+
const next = input ? matchScrubMarkers(input.markers, input.range, input.tipTime) : [];
|
|
67
70
|
const current = selected.get();
|
|
68
71
|
// Refresh metadata when the input changes, but retain the result array
|
|
69
72
|
// through chart ticks / movement that select the same markers.
|