react-native-livechart 4.26.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/CustomReferenceLineOverlay.d.ts +8 -1
- package/dist/components/CustomReferenceLineOverlay.d.ts.map +1 -1
- package/dist/components/CustomTooltipOverlay.d.ts +3 -2
- package/dist/components/CustomTooltipOverlay.d.ts.map +1 -1
- package/dist/components/LiveChart.d.ts +1 -1
- 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/components/ReferenceLineOverlay.d.ts +4 -0
- package/dist/components/ReferenceLineOverlay.d.ts.map +1 -1
- package/dist/components/ReferenceValueBadge.d.ts +15 -0
- package/dist/components/ReferenceValueBadge.d.ts.map +1 -0
- package/dist/components/XAxisOverlay.d.ts +17 -0
- package/dist/components/XAxisOverlay.d.ts.map +1 -1
- package/dist/core/liveChartEngineTick.d.ts +4 -0
- package/dist/core/liveChartEngineTick.d.ts.map +1 -1
- package/dist/core/liveChartSeriesEngineTick.d.ts +15 -2
- package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
- package/dist/core/resolveConfig.d.ts +28 -1
- package/dist/core/resolveConfig.d.ts.map +1 -1
- package/dist/core/useLiveChartEngine.d.ts +9 -0
- package/dist/core/useLiveChartEngine.d.ts.map +1 -1
- package/dist/core/useLiveChartSeriesEngine.d.ts +18 -4
- package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
- package/dist/draw/grid.d.ts +6 -4
- package/dist/draw/grid.d.ts.map +1 -1
- package/dist/draw/line.d.ts +21 -3
- 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/crosshairShared.d.ts +16 -1
- package/dist/hooks/crosshairShared.d.ts.map +1 -1
- package/dist/hooks/referenceBadgeFont.d.ts +5 -0
- package/dist/hooks/referenceBadgeFont.d.ts.map +1 -0
- package/dist/hooks/resolveChartLayout.d.ts +18 -2
- package/dist/hooks/resolveChartLayout.d.ts.map +1 -1
- package/dist/hooks/useBadge.d.ts +16 -1
- package/dist/hooks/useBadge.d.ts.map +1 -1
- package/dist/hooks/useChartSkiaFont.d.ts +1 -0
- package/dist/hooks/useChartSkiaFont.d.ts.map +1 -1
- package/dist/hooks/useCrosshair.d.ts +7 -2
- package/dist/hooks/useCrosshair.d.ts.map +1 -1
- package/dist/hooks/useCrosshairSeries.d.ts +6 -1
- package/dist/hooks/useCrosshairSeries.d.ts.map +1 -1
- package/dist/hooks/useLatestCallback.d.ts +6 -0
- package/dist/hooks/useLatestCallback.d.ts.map +1 -0
- package/dist/hooks/useMarkers.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/usePanScroll.d.ts +3 -1
- package/dist/hooks/usePanScroll.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 +20 -5
- package/dist/hooks/useReferenceDrag.d.ts.map +1 -1
- package/dist/hooks/useReferenceLine.d.ts +24 -12
- package/dist/hooks/useReferenceLine.d.ts.map +1 -1
- package/dist/hooks/useReferenceLinePress.d.ts +4 -2
- package/dist/hooks/useReferenceLinePress.d.ts.map +1 -1
- package/dist/hooks/useReferenceTagStack.d.ts +31 -0
- package/dist/hooks/useReferenceTagStack.d.ts.map +1 -0
- package/dist/hooks/useScrubMarkers.d.ts +12 -0
- package/dist/hooks/useScrubMarkers.d.ts.map +1 -0
- package/dist/hooks/useXAxis.d.ts +1 -1
- package/dist/hooks/useXAxis.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/hooks/useYAxisScaleGesture.d.ts +34 -0
- package/dist/hooks/useYAxisScaleGesture.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/math/axisBadgeLayout.d.ts +16 -0
- package/dist/math/axisBadgeLayout.d.ts.map +1 -0
- package/dist/math/markers.d.ts +3 -0
- package/dist/math/markers.d.ts.map +1 -1
- package/dist/math/range.d.ts +1 -1
- package/dist/math/range.d.ts.map +1 -1
- package/dist/math/referenceLines.d.ts.map +1 -1
- package/dist/math/referenceTagStack.d.ts +36 -0
- package/dist/math/referenceTagStack.d.ts.map +1 -0
- package/dist/math/scrubMarkers.d.ts +12 -0
- package/dist/math/scrubMarkers.d.ts.map +1 -0
- package/dist/types.d.ts +262 -37
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/CustomReferenceLineOverlay.tsx +50 -8
- package/src/components/CustomTooltipOverlay.tsx +5 -1
- package/src/components/LiveChart.tsx +580 -138
- package/src/components/LiveChartSeries.tsx +139 -19
- package/src/components/MultiSeriesDots.tsx +4 -2
- package/src/components/MultiSeriesValueLabels.tsx +4 -2
- package/src/components/MultiSeriesValueLines.tsx +4 -2
- package/src/components/ReferenceLineOverlay.tsx +62 -26
- package/src/components/ReferenceValueBadge.tsx +102 -0
- package/src/components/XAxisOverlay.tsx +104 -1
- package/src/core/liveChartEngineTick.ts +49 -4
- package/src/core/liveChartSeriesEngineTick.ts +107 -14
- package/src/core/resolveConfig.ts +103 -7
- package/src/core/useLiveChartEngine.ts +45 -9
- package/src/core/useLiveChartSeriesEngine.ts +47 -6
- package/src/draw/grid.ts +17 -13
- package/src/draw/line.ts +46 -5
- package/src/hooks/crosshairSeries.ts +37 -5
- package/src/hooks/crosshairShared.ts +56 -1
- package/src/hooks/referenceBadgeFont.ts +35 -0
- package/src/hooks/resolveChartLayout.ts +51 -3
- package/src/hooks/useBadge.ts +44 -5
- package/src/hooks/useChartSkiaFont.ts +1 -1
- package/src/hooks/useCrosshair.ts +444 -310
- package/src/hooks/useCrosshairSeries.ts +57 -20
- package/src/hooks/useLatestCallback.ts +15 -0
- package/src/hooks/useMarkers.ts +51 -39
- package/src/hooks/useMultiSeriesDegen.ts +10 -5
- package/src/hooks/useMultiSeriesLinePaths.ts +2 -0
- package/src/hooks/usePanScroll.ts +155 -127
- package/src/hooks/usePinchZoom.ts +94 -66
- package/src/hooks/useReferenceDrag.ts +409 -156
- package/src/hooks/useReferenceLine.ts +453 -277
- package/src/hooks/useReferenceLineGrouping.ts +1 -1
- package/src/hooks/useReferenceLinePress.ts +121 -53
- package/src/hooks/useReferenceTagStack.ts +81 -0
- package/src/hooks/useScrubMarkers.ts +79 -0
- package/src/hooks/useXAxis.ts +11 -2
- package/src/hooks/useYAxis.ts +1 -1
- package/src/hooks/useYAxisLabelWidth.ts +26 -0
- package/src/hooks/useYAxisScaleGesture.ts +263 -0
- package/src/index.ts +11 -0
- package/src/math/axisBadgeLayout.ts +37 -0
- package/src/math/markers.ts +28 -3
- package/src/math/range.ts +35 -0
- package/src/math/referenceLines.ts +5 -0
- package/src/math/referenceTagStack.ts +112 -0
- package/src/math/scrubMarkers.ts +55 -0
- package/src/types.ts +263 -37
|
@@ -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,
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
resetDelayedPanGuard,
|
|
38
38
|
shouldStartDelayedPan,
|
|
39
39
|
} from "./delayedPanGuard";
|
|
40
|
+
import { useScrubMarkers, type ScrubMarkerOptions } from "./useScrubMarkers";
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
* LiveChartSeries crosshair + scrub. The optional per-series tooltip is
|
|
@@ -73,9 +74,23 @@ export function useCrosshairSeries(
|
|
|
73
74
|
* drags to those bounds. Default `false`.
|
|
74
75
|
*/
|
|
75
76
|
clampToPlot = false,
|
|
77
|
+
markerOptions?: ScrubMarkerOptions,
|
|
78
|
+
/** Price-axis ownership also guards against stale native long-press events. */
|
|
79
|
+
axisScaleActive?: SharedValue<boolean>,
|
|
80
|
+
/** Bottom strip reserved for the time-axis drag gesture, in layout points. */
|
|
81
|
+
scrubBottomExclude = 0,
|
|
76
82
|
): CrosshairState {
|
|
77
|
-
const
|
|
83
|
+
const pointerX = useSharedValue(-1);
|
|
78
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
|
+
});
|
|
79
94
|
// Tracks whether the active scrub phase actually began, so a tap that never
|
|
80
95
|
// activates doesn't emit a spurious onGestureEnd.
|
|
81
96
|
const gestureStarted = useSharedValue(false);
|
|
@@ -96,22 +111,26 @@ export function useCrosshairSeries(
|
|
|
96
111
|
const noScrollActive = useSharedValue(false);
|
|
97
112
|
const scrollActiveSV = scrollActive ?? noScrollActive;
|
|
98
113
|
|
|
99
|
-
const scrubTime = useDerivedValue(() =>
|
|
100
|
-
|
|
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(
|
|
101
118
|
scrubActive.get(),
|
|
102
119
|
scrubX.get(),
|
|
103
120
|
padding,
|
|
104
121
|
engine.canvasWidth.get(),
|
|
105
122
|
engine.timestamp.get(),
|
|
106
123
|
engine.displayWindow.get(),
|
|
107
|
-
)
|
|
108
|
-
);
|
|
124
|
+
));
|
|
125
|
+
});
|
|
109
126
|
|
|
110
127
|
const scrubValue = useDerivedValue(() =>
|
|
111
128
|
deriveScrubValueSeries(
|
|
112
129
|
scrubActive.get(),
|
|
113
130
|
scrubTime.get(),
|
|
114
131
|
engine.series.get(),
|
|
132
|
+
engine.tipTime?.get(),
|
|
133
|
+
engine.displaySeriesValues.get(),
|
|
115
134
|
),
|
|
116
135
|
);
|
|
117
136
|
|
|
@@ -169,6 +188,10 @@ export function useCrosshairSeries(
|
|
|
169
188
|
onGestureEnd?.();
|
|
170
189
|
}
|
|
171
190
|
|
|
191
|
+
const scrubMarkers = useScrubMarkers(
|
|
192
|
+
markerOptions, scrubActive, scrubTime, engine.timestamp, engine.displayWindow,
|
|
193
|
+
engine.canvasWidth, padding.left + padding.right,
|
|
194
|
+
);
|
|
172
195
|
const hasOnScrub = onScrub != null;
|
|
173
196
|
const hasOnGestureStart = onGestureStart != null;
|
|
174
197
|
const hasOnGestureEnd = onGestureEnd != null;
|
|
@@ -182,7 +205,10 @@ export function useCrosshairSeries(
|
|
|
182
205
|
const x = scrubX.get();
|
|
183
206
|
const chartW = engine.canvasWidth.get() - padding.left - padding.right;
|
|
184
207
|
if (chartW <= 0) return "__pending__";
|
|
185
|
-
|
|
208
|
+
if (time < 0) return "__pending__";
|
|
209
|
+
const r = interpolateSeriesAtTime(
|
|
210
|
+
engine.series.get(), time, engine.tipTime?.get(), engine.displaySeriesValues.get(),
|
|
211
|
+
);
|
|
186
212
|
if (r.primary === null) return "__pending__";
|
|
187
213
|
const dotY = computeScrubDotY(
|
|
188
214
|
r.primary,
|
|
@@ -192,26 +218,33 @@ export function useCrosshairSeries(
|
|
|
192
218
|
padding.top,
|
|
193
219
|
padding.bottom,
|
|
194
220
|
);
|
|
195
|
-
return
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
221
|
+
return {
|
|
222
|
+
point: JSON.stringify({
|
|
223
|
+
time,
|
|
224
|
+
x,
|
|
225
|
+
y: dotY,
|
|
226
|
+
primary: r.primary,
|
|
227
|
+
series: r.seriesValues,
|
|
228
|
+
}),
|
|
229
|
+
markers: markerOptions ? scrubMarkers.get() : undefined,
|
|
230
|
+
};
|
|
202
231
|
},
|
|
203
232
|
(curr, prev) => {
|
|
204
233
|
"worklet";
|
|
205
234
|
if (!hasOnScrub) return;
|
|
206
235
|
if (curr === "__inactive__") {
|
|
207
|
-
onScrub!(null);
|
|
236
|
+
if (curr !== prev) onScrub!(null);
|
|
208
237
|
return;
|
|
209
238
|
}
|
|
210
239
|
if (curr === "__idle__" || curr === "__pending__") {
|
|
240
|
+
if (markerOptions && curr === "__pending__" && prev && typeof prev === "object") {
|
|
241
|
+
onScrub!(null);
|
|
242
|
+
}
|
|
211
243
|
return;
|
|
212
244
|
}
|
|
213
|
-
|
|
214
|
-
|
|
245
|
+
const previous = typeof prev === "object" ? prev : null;
|
|
246
|
+
if (curr.point === previous?.point && curr.markers === previous?.markers) return;
|
|
247
|
+
const p = JSON.parse(curr.point) as {
|
|
215
248
|
time: number;
|
|
216
249
|
x: number;
|
|
217
250
|
y: number;
|
|
@@ -224,6 +257,7 @@ export function useCrosshairSeries(
|
|
|
224
257
|
x: p.x,
|
|
225
258
|
y: p.y,
|
|
226
259
|
seriesValues: p.series,
|
|
260
|
+
...(markerOptions ? { markers: curr.markers } : {}),
|
|
227
261
|
});
|
|
228
262
|
},
|
|
229
263
|
);
|
|
@@ -286,6 +320,7 @@ export function useCrosshairSeries(
|
|
|
286
320
|
.onStart(
|
|
287
321
|
/* istanbul ignore next */ (e) => {
|
|
288
322
|
"worklet";
|
|
323
|
+
if (axisScaleActive?.get()) return;
|
|
289
324
|
if (
|
|
290
325
|
!shouldStartDelayedPan(
|
|
291
326
|
panGestureDelay,
|
|
@@ -303,7 +338,7 @@ export function useCrosshairSeries(
|
|
|
303
338
|
padding,
|
|
304
339
|
engine.canvasWidth.get(),
|
|
305
340
|
clampToPlot,
|
|
306
|
-
|
|
341
|
+
pointerX,
|
|
307
342
|
scrubActive,
|
|
308
343
|
gestureStarted,
|
|
309
344
|
);
|
|
@@ -313,13 +348,14 @@ export function useCrosshairSeries(
|
|
|
313
348
|
.onUpdate(
|
|
314
349
|
/* istanbul ignore next */ (e) => {
|
|
315
350
|
"worklet";
|
|
351
|
+
if (axisScaleActive?.get()) return;
|
|
316
352
|
if (!enabled) return;
|
|
317
353
|
updatePlainScrub(
|
|
318
354
|
e.x,
|
|
319
355
|
padding,
|
|
320
356
|
engine.canvasWidth.get(),
|
|
321
357
|
clampToPlot,
|
|
322
|
-
|
|
358
|
+
pointerX,
|
|
323
359
|
scrubActive,
|
|
324
360
|
);
|
|
325
361
|
},
|
|
@@ -350,10 +386,11 @@ export function useCrosshairSeries(
|
|
|
350
386
|
// Gate by touch-down position so outside starts fail before activation and
|
|
351
387
|
// remain available to competing/parent gestures. Accepted pans keep tracking
|
|
352
388
|
// outside because `shouldCancelWhenOutside(false)` is set above.
|
|
353
|
-
const scrubHitSlop = resolveScrubHitSlop(padding, clampToPlot);
|
|
389
|
+
const scrubHitSlop = resolveScrubHitSlop(padding, clampToPlot, scrubBottomExclude);
|
|
354
390
|
if (scrubHitSlop) gesture = gesture.hitSlop(scrubHitSlop);
|
|
355
391
|
|
|
356
392
|
return {
|
|
393
|
+
scrubMarkers,
|
|
357
394
|
scrubX,
|
|
358
395
|
scrubActive,
|
|
359
396
|
scrubTime,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
/** Stable JS-thread dispatcher for callbacks scheduled by gesture worklets.
|
|
4
|
+
* Commit the new callback in an effect; an abandoned render must not replace it.
|
|
5
|
+
* Never call this dispatcher directly from the UI thread — use scheduleOnRN.
|
|
6
|
+
*/
|
|
7
|
+
export function useLatestCallback<Args extends unknown[], Result>(
|
|
8
|
+
callback: (...args: Args) => Result,
|
|
9
|
+
): (...args: Args) => Result {
|
|
10
|
+
const latest = useRef(callback);
|
|
11
|
+
useLayoutEffect(() => {
|
|
12
|
+
latest.current = callback;
|
|
13
|
+
}, [callback]);
|
|
14
|
+
return useCallback((...args: Args) => latest.current(...args), []);
|
|
15
|
+
}
|
package/src/hooks/useMarkers.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
1
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
2
2
|
import { Gesture } from "react-native-gesture-handler";
|
|
3
3
|
import {
|
|
4
4
|
useAnimatedReaction,
|
|
@@ -23,6 +23,8 @@ import type {
|
|
|
23
23
|
SeriesConfig,
|
|
24
24
|
} from "../types";
|
|
25
25
|
|
|
26
|
+
import { useLatestCallback } from "./useLatestCallback";
|
|
27
|
+
|
|
26
28
|
const ANCHORED_CLUSTER: ResolvedMarkerCluster = {
|
|
27
29
|
mode: "anchored",
|
|
28
30
|
direction: "horizontal",
|
|
@@ -76,11 +78,12 @@ export function useMarkers(
|
|
|
76
78
|
cacheRef.current = { a: [] as ProjectedMarker[], b: [] as ProjectedMarker[], tick: false };
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
const emitPress =
|
|
81
|
+
const emitPress = useLatestCallback(
|
|
80
82
|
/* istanbul ignore next -- invoked only from the UI-thread tap worklet */
|
|
81
83
|
(event: MarkerPressEvent | null) => {
|
|
82
84
|
onMarkerPress?.(event);
|
|
83
|
-
}
|
|
85
|
+
},
|
|
86
|
+
);
|
|
84
87
|
|
|
85
88
|
const project =
|
|
86
89
|
/* istanbul ignore next -- worklet runs on UI thread, not in Jest */ () => {
|
|
@@ -133,43 +136,52 @@ export function useMarkers(
|
|
|
133
136
|
markerFrameCallback.setActive(legacyActive);
|
|
134
137
|
}, [legacyActive, markerFrameCallback]);
|
|
135
138
|
|
|
136
|
-
const tapGesture =
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
139
|
+
const { tapGesture, hitTest } = useMemo(() => {
|
|
140
|
+
const tapGesture = Gesture.Tap().onEnd(
|
|
141
|
+
/* istanbul ignore next -- gesture worklet runs on UI thread, not in Jest */ (
|
|
142
|
+
e,
|
|
143
|
+
) => {
|
|
144
|
+
"worklet";
|
|
145
|
+
const proj = projected.get();
|
|
146
|
+
const idx = nearestMarkerIndex(proj, e.x, e.y, hitRadius);
|
|
147
|
+
if (idx < 0) {
|
|
148
|
+
runOnJS(emitPress)(null);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const ms = markers.get();
|
|
152
|
+
const m = ms[idx];
|
|
153
|
+
const p = proj[idx];
|
|
154
|
+
const isGrouped = p.isGrouped;
|
|
155
|
+
// Collapsed cluster: surface the whole bucket so the consumer can list it.
|
|
156
|
+
const members = isGrouped ? clusterMembers(ms, proj, idx) : undefined;
|
|
157
|
+
runOnJS(emitPress)({
|
|
158
|
+
marker: m,
|
|
159
|
+
point: { x: p.x, y: p.y },
|
|
160
|
+
index: idx,
|
|
161
|
+
isGrouped,
|
|
162
|
+
members,
|
|
163
|
+
});
|
|
164
|
+
},
|
|
165
|
+
);
|
|
162
166
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
167
|
+
// Lets a coexisting gesture (e.g. the scrub-action tap) defer to a marker
|
|
168
|
+
// under the finger instead of acting on it.
|
|
169
|
+
const hitTest =
|
|
170
|
+
/* istanbul ignore next -- worklet, runs on the UI thread, not in Jest */ (
|
|
171
|
+
x: number,
|
|
172
|
+
y: number,
|
|
173
|
+
) => {
|
|
174
|
+
"worklet";
|
|
175
|
+
return nearestMarkerIndex(projected.get(), x, y, hitRadius) >= 0;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
return { tapGesture, hitTest };
|
|
179
|
+
}, [
|
|
180
|
+
emitPress,
|
|
181
|
+
hitRadius,
|
|
182
|
+
markers,
|
|
183
|
+
projected,
|
|
184
|
+
]);
|
|
173
185
|
|
|
174
186
|
return { projected, tapGesture, hitTest };
|
|
175
187
|
}
|
|
@@ -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;
|