react-native-livechart 4.26.0 → 4.27.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/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 +2 -0
- 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 +7 -0
- package/dist/core/useLiveChartEngine.d.ts.map +1 -1
- package/dist/core/useLiveChartSeriesEngine.d.ts +2 -0
- package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
- package/dist/draw/grid.d.ts +2 -2
- package/dist/draw/line.d.ts +15 -1
- package/dist/draw/line.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 +8 -0
- 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 +4 -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/usePanScroll.d.ts +3 -1
- package/dist/hooks/usePanScroll.d.ts.map +1 -1
- 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/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/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 +202 -32
- 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 +560 -138
- package/src/components/LiveChartSeries.tsx +113 -13
- 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 +37 -0
- package/src/core/resolveConfig.ts +95 -2
- package/src/core/useLiveChartEngine.ts +43 -9
- package/src/core/useLiveChartSeriesEngine.ts +5 -0
- package/src/draw/grid.ts +2 -2
- package/src/draw/line.ts +23 -1
- package/src/hooks/crosshairShared.ts +56 -1
- package/src/hooks/referenceBadgeFont.ts +35 -0
- package/src/hooks/resolveChartLayout.ts +17 -0
- 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 +29 -10
- package/src/hooks/useLatestCallback.ts +15 -0
- package/src/hooks/useMarkers.ts +51 -39
- package/src/hooks/usePanScroll.ts +155 -127
- package/src/hooks/usePinchZoom.ts +84 -63
- package/src/hooks/useReferenceDrag.ts +390 -155
- 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/useYAxisScaleGesture.ts +263 -0
- package/src/index.ts +10 -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/referenceTagStack.ts +112 -0
- package/src/math/scrubMarkers.ts +55 -0
- package/src/types.ts +207 -32
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
1
2
|
import { Gesture } from "react-native-gesture-handler";
|
|
2
3
|
import {
|
|
3
4
|
cancelAnimation,
|
|
@@ -174,69 +175,89 @@ export function usePinchZoom({
|
|
|
174
175
|
|
|
175
176
|
const wakeEngine = engine.wake;
|
|
176
177
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
178
|
+
return useMemo(() => {
|
|
179
|
+
const onStart =
|
|
180
|
+
/* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
|
|
181
|
+
() => {
|
|
182
|
+
"worklet";
|
|
183
|
+
wakeEngine?.();
|
|
184
|
+
cancelAnimation(viewEnd);
|
|
185
|
+
cancelAnimation(viewWindow);
|
|
186
|
+
const edge = liveEdge.get();
|
|
187
|
+
startWindow.set(viewWindow.get() ?? timeWindow);
|
|
188
|
+
startViewEnd.set(viewEnd.get() ?? edge);
|
|
189
|
+
onZoomStart?.();
|
|
190
|
+
};
|
|
189
191
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
192
|
+
const onChange =
|
|
193
|
+
/* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
|
|
194
|
+
(e: { scale: number; focalX: number; numberOfPointers: number }) => {
|
|
195
|
+
"worklet";
|
|
196
|
+
// When a finger lifts at the end of the pinch, the recognizer's focal
|
|
197
|
+
// point jumps from the two-finger midpoint to the remaining finger. A
|
|
198
|
+
// change event computed from that jumped focal throws the window
|
|
199
|
+
// sideways (and can even snap it back to following live). Ignore
|
|
200
|
+
// change events once fewer than two pointers remain.
|
|
201
|
+
if (e.numberOfPointers < 2) return;
|
|
202
|
+
const chartW = canvasWidth.get() - padLeft - padRight;
|
|
203
|
+
if (chartW <= 0 || e.scale <= 0) return;
|
|
204
|
+
const edge = liveEdge.get();
|
|
205
|
+
const sWin = startWindow.get();
|
|
206
|
+
const sEnd = startViewEnd.get();
|
|
207
|
+
const span = edge - minTime.get();
|
|
208
|
+
const [minWin, maxWin] = zoomWindowBounds(
|
|
209
|
+
timeWindow,
|
|
210
|
+
span,
|
|
211
|
+
minTimeWindow,
|
|
212
|
+
maxTimeWindow,
|
|
213
|
+
);
|
|
214
|
+
// Pinch out (scale > 1) ⇒ narrower window ⇒ zoom in.
|
|
215
|
+
const newWin = clampWindow(sWin / e.scale, minWin, maxWin);
|
|
216
|
+
// Time under the fingers, mapped through the START window so the anchor
|
|
217
|
+
// doesn't compound; the right edge then keeps it under the (live) focal.
|
|
218
|
+
const focalT = focalTime(e.focalX, padLeft, chartW, sEnd - sWin, sWin);
|
|
219
|
+
let newEnd = zoomViewEnd(focalT, e.focalX, padLeft, chartW, newWin);
|
|
220
|
+
const lo = panLowerBound(minTime.get(), newWin, edge, overscroll);
|
|
221
|
+
if (newEnd < lo) newEnd = lo;
|
|
222
|
+
const hi = overscroll > 0 ? panUpperBound(newWin, edge, overscroll) : edge;
|
|
223
|
+
if (newEnd > hi) newEnd = hi;
|
|
224
|
+
viewWindow.set(newWin);
|
|
225
|
+
// Track the displayed window 1:1 (bypass the frame-loop lerp lag) so the
|
|
226
|
+
// focal anchor is pixel-accurate during the gesture.
|
|
227
|
+
displayWindow.set(newWin);
|
|
228
|
+
// Unlike the pan (see nextViewEnd), snapping to `null` mid-gesture is safe
|
|
229
|
+
// here: the pinch maps cumulative scale/focal from a gesture-START snapshot
|
|
230
|
+
// (`startViewEnd`), not per-frame deltas, so a snap can't re-anchor it.
|
|
231
|
+
// With overscroll, snap within the FOLLOW_SNAP zone; without, at the edge.
|
|
232
|
+
viewEnd.set(
|
|
233
|
+
overscroll > 0
|
|
234
|
+
? Math.abs(newEnd - edge) <= newWin * FOLLOW_SNAP
|
|
235
|
+
? null
|
|
236
|
+
: newEnd
|
|
237
|
+
: newEnd >= edge
|
|
238
|
+
? null
|
|
239
|
+
: newEnd,
|
|
240
|
+
);
|
|
241
|
+
};
|
|
240
242
|
|
|
241
|
-
|
|
243
|
+
return Gesture.Pinch().enabled(enabled).onStart(onStart).onChange(onChange);
|
|
244
|
+
}, [
|
|
245
|
+
canvasWidth,
|
|
246
|
+
displayWindow,
|
|
247
|
+
enabled,
|
|
248
|
+
liveEdge,
|
|
249
|
+
maxTimeWindow,
|
|
250
|
+
minTime,
|
|
251
|
+
minTimeWindow,
|
|
252
|
+
onZoomStart,
|
|
253
|
+
overscroll,
|
|
254
|
+
padLeft,
|
|
255
|
+
padRight,
|
|
256
|
+
startViewEnd,
|
|
257
|
+
startWindow,
|
|
258
|
+
timeWindow,
|
|
259
|
+
viewEnd,
|
|
260
|
+
viewWindow,
|
|
261
|
+
wakeEngine,
|
|
262
|
+
]);
|
|
242
263
|
}
|