react-native-livechart 4.25.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.
Files changed (125) hide show
  1. package/dist/components/CustomReferenceLineOverlay.d.ts +8 -1
  2. package/dist/components/CustomReferenceLineOverlay.d.ts.map +1 -1
  3. package/dist/components/CustomTooltipOverlay.d.ts +3 -2
  4. package/dist/components/CustomTooltipOverlay.d.ts.map +1 -1
  5. package/dist/components/LiveChart.d.ts +1 -1
  6. package/dist/components/LiveChart.d.ts.map +1 -1
  7. package/dist/components/LiveChartSeries.d.ts.map +1 -1
  8. package/dist/components/ReferenceLineOverlay.d.ts +4 -0
  9. package/dist/components/ReferenceLineOverlay.d.ts.map +1 -1
  10. package/dist/components/ReferenceValueBadge.d.ts +15 -0
  11. package/dist/components/ReferenceValueBadge.d.ts.map +1 -0
  12. package/dist/components/XAxisOverlay.d.ts +17 -0
  13. package/dist/components/XAxisOverlay.d.ts.map +1 -1
  14. package/dist/core/liveChartEngineTick.d.ts +6 -1
  15. package/dist/core/liveChartEngineTick.d.ts.map +1 -1
  16. package/dist/core/liveChartSeriesEngineTick.d.ts +4 -1
  17. package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
  18. package/dist/core/resolveConfig.d.ts +28 -1
  19. package/dist/core/resolveConfig.d.ts.map +1 -1
  20. package/dist/core/useLiveChartEngine.d.ts +10 -1
  21. package/dist/core/useLiveChartEngine.d.ts.map +1 -1
  22. package/dist/core/useLiveChartSeriesEngine.d.ts +5 -1
  23. package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
  24. package/dist/draw/grid.d.ts +2 -2
  25. package/dist/draw/line.d.ts +15 -1
  26. package/dist/draw/line.d.ts.map +1 -1
  27. package/dist/hooks/crosshairShared.d.ts +24 -1
  28. package/dist/hooks/crosshairShared.d.ts.map +1 -1
  29. package/dist/hooks/referenceBadgeFont.d.ts +5 -0
  30. package/dist/hooks/referenceBadgeFont.d.ts.map +1 -0
  31. package/dist/hooks/resolveChartLayout.d.ts +8 -0
  32. package/dist/hooks/resolveChartLayout.d.ts.map +1 -1
  33. package/dist/hooks/useBadge.d.ts +16 -1
  34. package/dist/hooks/useBadge.d.ts.map +1 -1
  35. package/dist/hooks/useChartSkiaFont.d.ts +1 -0
  36. package/dist/hooks/useChartSkiaFont.d.ts.map +1 -1
  37. package/dist/hooks/useCrosshair.d.ts +7 -2
  38. package/dist/hooks/useCrosshair.d.ts.map +1 -1
  39. package/dist/hooks/useCrosshairSeries.d.ts +4 -1
  40. package/dist/hooks/useCrosshairSeries.d.ts.map +1 -1
  41. package/dist/hooks/useLatestCallback.d.ts +6 -0
  42. package/dist/hooks/useLatestCallback.d.ts.map +1 -0
  43. package/dist/hooks/useMarkers.d.ts.map +1 -1
  44. package/dist/hooks/usePanScroll.d.ts +3 -1
  45. package/dist/hooks/usePanScroll.d.ts.map +1 -1
  46. package/dist/hooks/usePinchZoom.d.ts.map +1 -1
  47. package/dist/hooks/useReferenceDrag.d.ts +23 -7
  48. package/dist/hooks/useReferenceDrag.d.ts.map +1 -1
  49. package/dist/hooks/useReferenceLine.d.ts +24 -12
  50. package/dist/hooks/useReferenceLine.d.ts.map +1 -1
  51. package/dist/hooks/useReferenceLineGrouping.d.ts +19 -0
  52. package/dist/hooks/useReferenceLineGrouping.d.ts.map +1 -0
  53. package/dist/hooks/useReferenceLinePress.d.ts +4 -2
  54. package/dist/hooks/useReferenceLinePress.d.ts.map +1 -1
  55. package/dist/hooks/useReferenceTagStack.d.ts +31 -0
  56. package/dist/hooks/useReferenceTagStack.d.ts.map +1 -0
  57. package/dist/hooks/useScrubMarkers.d.ts +12 -0
  58. package/dist/hooks/useScrubMarkers.d.ts.map +1 -0
  59. package/dist/hooks/useXAxis.d.ts +1 -1
  60. package/dist/hooks/useXAxis.d.ts.map +1 -1
  61. package/dist/hooks/useYAxisScaleGesture.d.ts +34 -0
  62. package/dist/hooks/useYAxisScaleGesture.d.ts.map +1 -0
  63. package/dist/index.d.ts +1 -1
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/math/axisBadgeLayout.d.ts +16 -0
  66. package/dist/math/axisBadgeLayout.d.ts.map +1 -0
  67. package/dist/math/markers.d.ts +3 -0
  68. package/dist/math/markers.d.ts.map +1 -1
  69. package/dist/math/range.d.ts +1 -1
  70. package/dist/math/range.d.ts.map +1 -1
  71. package/dist/math/rangeAnimation.d.ts +4 -0
  72. package/dist/math/rangeAnimation.d.ts.map +1 -0
  73. package/dist/math/referenceDrag.d.ts +17 -5
  74. package/dist/math/referenceDrag.d.ts.map +1 -1
  75. package/dist/math/referenceGroup.d.ts +2 -2
  76. package/dist/math/referenceTagStack.d.ts +36 -0
  77. package/dist/math/referenceTagStack.d.ts.map +1 -0
  78. package/dist/math/scrubMarkers.d.ts +12 -0
  79. package/dist/math/scrubMarkers.d.ts.map +1 -0
  80. package/dist/types.d.ts +240 -30
  81. package/dist/types.d.ts.map +1 -1
  82. package/package.json +1 -1
  83. package/src/components/CustomReferenceLineOverlay.tsx +50 -8
  84. package/src/components/CustomTooltipOverlay.tsx +5 -1
  85. package/src/components/LiveChart.tsx +563 -200
  86. package/src/components/LiveChartSeries.tsx +117 -13
  87. package/src/components/ReferenceLineOverlay.tsx +62 -26
  88. package/src/components/ReferenceValueBadge.tsx +102 -0
  89. package/src/components/XAxisOverlay.tsx +104 -1
  90. package/src/core/liveChartEngineTick.ts +66 -10
  91. package/src/core/liveChartSeriesEngineTick.ts +55 -5
  92. package/src/core/resolveConfig.ts +95 -2
  93. package/src/core/useLiveChartEngine.ts +53 -11
  94. package/src/core/useLiveChartSeriesEngine.ts +11 -1
  95. package/src/draw/grid.ts +2 -2
  96. package/src/draw/line.ts +23 -1
  97. package/src/hooks/crosshairShared.ts +85 -1
  98. package/src/hooks/referenceBadgeFont.ts +35 -0
  99. package/src/hooks/resolveChartLayout.ts +17 -0
  100. package/src/hooks/useBadge.ts +44 -5
  101. package/src/hooks/useChartSkiaFont.ts +1 -1
  102. package/src/hooks/useCrosshair.ts +446 -300
  103. package/src/hooks/useCrosshairSeries.ts +29 -10
  104. package/src/hooks/useLatestCallback.ts +15 -0
  105. package/src/hooks/useMarkers.ts +51 -39
  106. package/src/hooks/usePanScroll.ts +155 -127
  107. package/src/hooks/usePinchZoom.ts +84 -63
  108. package/src/hooks/useReferenceDrag.ts +395 -146
  109. package/src/hooks/useReferenceLine.ts +453 -277
  110. package/src/hooks/useReferenceLineGrouping.ts +72 -0
  111. package/src/hooks/useReferenceLinePress.ts +121 -53
  112. package/src/hooks/useReferenceTagStack.ts +81 -0
  113. package/src/hooks/useScrubMarkers.ts +79 -0
  114. package/src/hooks/useXAxis.ts +11 -2
  115. package/src/hooks/useYAxisScaleGesture.ts +263 -0
  116. package/src/index.ts +11 -0
  117. package/src/math/axisBadgeLayout.ts +37 -0
  118. package/src/math/markers.ts +28 -3
  119. package/src/math/range.ts +35 -0
  120. package/src/math/rangeAnimation.ts +28 -0
  121. package/src/math/referenceDrag.ts +21 -4
  122. package/src/math/referenceGroup.ts +2 -2
  123. package/src/math/referenceTagStack.ts +112 -0
  124. package/src/math/scrubMarkers.ts +55 -0
  125. package/src/types.ts +246 -30
@@ -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
- const onStart =
178
- /* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
179
- () => {
180
- "worklet";
181
- wakeEngine?.();
182
- cancelAnimation(viewEnd);
183
- cancelAnimation(viewWindow);
184
- const edge = liveEdge.get();
185
- startWindow.set(viewWindow.get() ?? timeWindow);
186
- startViewEnd.set(viewEnd.get() ?? edge);
187
- onZoomStart?.();
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
- const onChange =
191
- /* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
192
- (e: { scale: number; focalX: number; numberOfPointers: number }) => {
193
- "worklet";
194
- // When a finger lifts at the end of the pinch, the recognizer's focal
195
- // point jumps from the two-finger midpoint to the remaining finger. A
196
- // change event computed from that jumped focal throws the window
197
- // sideways (and can even snap it back to following live). Ignore
198
- // change events once fewer than two pointers remain.
199
- if (e.numberOfPointers < 2) return;
200
- const chartW = canvasWidth.get() - padLeft - padRight;
201
- if (chartW <= 0 || e.scale <= 0) return;
202
- const edge = liveEdge.get();
203
- const sWin = startWindow.get();
204
- const sEnd = startViewEnd.get();
205
- const span = edge - minTime.get();
206
- const [minWin, maxWin] = zoomWindowBounds(
207
- timeWindow,
208
- span,
209
- minTimeWindow,
210
- maxTimeWindow,
211
- );
212
- // Pinch out (scale > 1) ⇒ narrower window ⇒ zoom in.
213
- const newWin = clampWindow(sWin / e.scale, minWin, maxWin);
214
- // Time under the fingers, mapped through the START window so the anchor
215
- // doesn't compound; the right edge then keeps it under the (live) focal.
216
- const focalT = focalTime(e.focalX, padLeft, chartW, sEnd - sWin, sWin);
217
- let newEnd = zoomViewEnd(focalT, e.focalX, padLeft, chartW, newWin);
218
- const lo = panLowerBound(minTime.get(), newWin, edge, overscroll);
219
- if (newEnd < lo) newEnd = lo;
220
- const hi = overscroll > 0 ? panUpperBound(newWin, edge, overscroll) : edge;
221
- if (newEnd > hi) newEnd = hi;
222
- viewWindow.set(newWin);
223
- // Track the displayed window 1:1 (bypass the frame-loop lerp lag) so the
224
- // focal anchor is pixel-accurate during the gesture.
225
- displayWindow.set(newWin);
226
- // Unlike the pan (see nextViewEnd), snapping to `null` mid-gesture is safe
227
- // here: the pinch maps cumulative scale/focal from a gesture-START snapshot
228
- // (`startViewEnd`), not per-frame deltas, so a snap can't re-anchor it.
229
- // With overscroll, snap within the FOLLOW_SNAP zone; without, at the edge.
230
- viewEnd.set(
231
- overscroll > 0
232
- ? Math.abs(newEnd - edge) <= newWin * FOLLOW_SNAP
233
- ? null
234
- : newEnd
235
- : newEnd >= edge
236
- ? null
237
- : newEnd,
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
- return Gesture.Pinch().enabled(enabled).onStart(onStart).onChange(onChange);
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
  }