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,5 @@
1
+ import { scheduleOnUI } from "react-native-worklets";
2
+ import { useEffect } from "react";
1
3
  import { StyleSheet, View, type LayoutChangeEvent } from "react-native";
2
4
  import Animated, {
3
5
  useAnimatedStyle,
@@ -6,6 +8,8 @@ import Animated, {
6
8
  type SharedValue,
7
9
  } from "react-native-reanimated";
8
10
 
11
+ import type { CustomTagSizes } from "../hooks/useReferenceTagStack";
12
+ import type { ReferenceTagStack } from "../math/referenceTagStack";
9
13
  import type { ChartEngineLayout } from "../core/useLiveChartEngine";
10
14
  import type { ChartPadding } from "../draw/line";
11
15
  import { computeScrubDotY } from "../hooks/crosshairShared";
@@ -17,6 +21,27 @@ import {
17
21
  } from "../math/referenceLines";
18
22
  import type { ReferenceLine, ReferenceLineRenderProps } from "../types";
19
23
 
24
+ /** Merge on the UI thread: multiple native onLayout events can arrive before
25
+ * JS observes an earlier SharedValue write. Keep every sibling's measurement. */
26
+ export function publishCustomTagSize(
27
+ sizes: SharedValue<CustomTagSizes> | undefined,
28
+ widths: SharedValue<number[]> | undefined,
29
+ key: string, index: number, width: number, height: number,
30
+ ) {
31
+ "worklet";
32
+ if (sizes) {
33
+ const previous = sizes.get();
34
+ if (previous[key]?.width !== width || previous[key]?.height !== height) {
35
+ sizes.set({ ...previous, [key]: { width, height } });
36
+ }
37
+ }
38
+ if (widths && widths.get()[index] !== width) {
39
+ const next = widths.get().slice();
40
+ next[index] = width;
41
+ widths.set(next);
42
+ }
43
+ }
44
+
20
45
  /** Horizontal anchor for the floated tag, mirroring the built-in badge/label. */
21
46
  type HAnchor = "left" | "center" | "right";
22
47
 
@@ -67,6 +92,7 @@ export function customReferenceLineFlags(
67
92
  value: stub(line.value ?? 0),
68
93
  valueStr: stub(""),
69
94
  y: stub(-1),
95
+ tagOffsetY: stub(0),
70
96
  inRange: stub(!offAxisOnly),
71
97
  edge: stub<"above" | "in" | "below">(
72
98
  offAxisOnly ? "above" : "in",
@@ -96,6 +122,9 @@ function CustomReferenceLineView({
96
122
  dragValues,
97
123
  dragActive,
98
124
  tagWidths,
125
+ tagSizes,
126
+ tagStack,
127
+ measurementKey,
99
128
  offAxisOnly,
100
129
  }: {
101
130
  line: ReferenceLine;
@@ -112,7 +141,10 @@ function CustomReferenceLineView({
112
141
  dragActive?: SharedValue<boolean[]>;
113
142
  /** Measured custom-tag widths, index-aligned for the Skia connector. */
114
143
  tagWidths?: SharedValue<number[]>;
144
+ tagSizes?: SharedValue<CustomTagSizes>;
145
+ tagStack?: SharedValue<ReferenceTagStack>;
115
146
  /** Show this custom tag only while its line is pinned above or below the plot. */
147
+ measurementKey: string;
116
148
  offAxisOnly: boolean;
117
149
  }) {
118
150
  const staticValue = line.value ?? 0;
@@ -158,18 +190,20 @@ function CustomReferenceLineView({
158
190
 
159
191
  // Measured element size, so the transform can center / pin it.
160
192
  const size = useSharedValue({ width: 0, height: 0 });
193
+ useEffect(() => {
194
+ if (!tagSizes) return;
195
+ const measured = size.get();
196
+ if (measured.width > 0 && measured.height > 0) {
197
+ scheduleOnUI(publishCustomTagSize, tagSizes, tagWidths, measurementKey, index, measured.width, measured.height);
198
+ }
199
+ }, [index, measurementKey, size, tagSizes, tagWidths]);
161
200
  const onLayout = (e: LayoutChangeEvent) => {
162
201
  const { width, height } = e.nativeEvent.layout;
163
202
  size.set({ width, height });
164
- if (tagWidths) {
165
- const previous = tagWidths.get();
166
- if (previous[index] === width) return;
167
- const widths = previous.slice();
168
- widths[index] = width;
169
- tagWidths.set(widths);
170
- }
203
+ scheduleOnUI(publishCustomTagSize, tagSizes, tagWidths, measurementKey, index, width, height);
171
204
  };
172
205
 
206
+ const tagOffsetY = useDerivedValue(() => tagStack?.get().offsets[index] ?? 0);
173
207
  const anchor = resolveAnchor(line);
174
208
  const animatedStyle = useAnimatedStyle(() => {
175
209
  const yy = y.get();
@@ -184,7 +218,7 @@ function CustomReferenceLineView({
184
218
  else tx = x1 + ANCHOR_INSET;
185
219
  return {
186
220
  opacity: visible ? 1 : 0,
187
- transform: [{ translateX: tx }, { translateY: yy - s.height / 2 }],
221
+ transform: [{ translateX: tx }, { translateY: yy + tagOffsetY.get() - s.height / 2 }],
188
222
  };
189
223
  });
190
224
 
@@ -194,6 +228,7 @@ function CustomReferenceLineView({
194
228
  value,
195
229
  valueStr,
196
230
  y,
231
+ tagOffsetY,
197
232
  inRange,
198
233
  edge,
199
234
  dragging,
@@ -229,6 +264,8 @@ export function CustomReferenceLineOverlay({
229
264
  dragValues,
230
265
  dragActive,
231
266
  tagWidths,
267
+ tagSizes,
268
+ tagStack,
232
269
  offAxisOnly = false,
233
270
  }: {
234
271
  lines: ReferenceLine[];
@@ -250,6 +287,8 @@ export function CustomReferenceLineOverlay({
250
287
  dragActive?: SharedValue<boolean[]>;
251
288
  /** Measured custom-tag widths, index-aligned for the Skia connector. */
252
289
  tagWidths?: SharedValue<number[]>;
290
+ tagSizes?: SharedValue<CustomTagSizes>;
291
+ tagStack?: SharedValue<ReferenceTagStack>;
253
292
  /** Keep the built-in in-range tag and show this RN tag only off-axis. */
254
293
  offAxisOnly?: boolean;
255
294
  }) {
@@ -269,6 +308,9 @@ export function CustomReferenceLineOverlay({
269
308
  dragValues={dragValues}
270
309
  dragActive={dragActive}
271
310
  tagWidths={tagWidths}
311
+ tagSizes={tagSizes}
312
+ tagStack={tagStack}
313
+ measurementKey={lineKeys[i]}
272
314
  offAxisOnly={offAxisOnly}
273
315
  />,
274
316
  );
@@ -10,7 +10,7 @@ import type { ChartEngineLayout } from "../core/useLiveChartEngine";
10
10
  import type { ChartPadding } from "../draw/line";
11
11
  import type { TooltipLayout } from "../hooks/crosshairShared";
12
12
  import { resolveCrosshairVisibleOpacity } from "../hooks/useCrosshairVisibleOpacity";
13
- import type { CandleGap, CandlePoint, TooltipRenderProps } from "../types";
13
+ import type { CandleGap, CandlePoint, Marker, TooltipRenderProps } from "../types";
14
14
 
15
15
  // Mirror the Skia tooltip's offsets (see crosshairShared.ts) so a custom pill
16
16
  // lines up with where the built-in one would sit. The vertical edge gap is
@@ -43,6 +43,7 @@ export function CustomTooltipOverlay({
43
43
  scrubActive,
44
44
  scrubCandle,
45
45
  scrubGap,
46
+ scrubMarkers,
46
47
  tooltipLayout,
47
48
  engine,
48
49
  padding,
@@ -62,6 +63,7 @@ export function CustomTooltipOverlay({
62
63
  scrubCandle?: SharedValue<CandlePoint | null>;
63
64
  /** Explicit line or candle gap under the crosshair; omitted/`null` outside one. */
64
65
  scrubGap?: SharedValue<CandleGap | null>;
66
+ scrubMarkers?: SharedValue<Marker[]>;
65
67
  tooltipLayout: SharedValue<TooltipLayout>;
66
68
  engine: ChartEngineLayout;
67
69
  padding: ChartPadding;
@@ -88,8 +90,10 @@ export function CustomTooltipOverlay({
88
90
  // Stable null SharedValues keep both fields present regardless of mode.
89
91
  const nullCandle = useSharedValue<CandlePoint | null>(null);
90
92
  const nullGap = useSharedValue<CandleGap | null>(null);
93
+ const emptyMarkers = useSharedValue<Marker[]>([]);
91
94
 
92
95
  const ctx: TooltipRenderProps = {
96
+ markers: scrubMarkers ?? emptyMarkers,
93
97
  value: scrubValue,
94
98
  time: scrubTime,
95
99
  valueStr,