react-native-livechart 4.31.1 → 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.
Files changed (82) hide show
  1. package/dist/components/CrosshairOverlay.d.ts +3 -1
  2. package/dist/components/CrosshairOverlay.d.ts.map +1 -1
  3. package/dist/components/CustomMarkerOverlay.d.ts +2 -2
  4. package/dist/components/CustomMarkerOverlay.d.ts.map +1 -1
  5. package/dist/components/FreeCrosshairOverlay.d.ts +25 -0
  6. package/dist/components/FreeCrosshairOverlay.d.ts.map +1 -0
  7. package/dist/components/LiveChart.d.ts.map +1 -1
  8. package/dist/components/LiveChartSeries.d.ts.map +1 -1
  9. package/dist/components/MarkerOverlay.d.ts +2 -2
  10. package/dist/components/MarkerOverlay.d.ts.map +1 -1
  11. package/dist/components/ScrubActionOverlay.d.ts +7 -1
  12. package/dist/components/ScrubActionOverlay.d.ts.map +1 -1
  13. package/dist/core/liveChartEngineTick.d.ts +2 -0
  14. package/dist/core/liveChartEngineTick.d.ts.map +1 -1
  15. package/dist/core/liveChartSeriesEngineTick.d.ts +6 -0
  16. package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
  17. package/dist/core/resolveConfig.d.ts +4 -0
  18. package/dist/core/resolveConfig.d.ts.map +1 -1
  19. package/dist/core/useLiveChartEngine.d.ts +7 -2
  20. package/dist/core/useLiveChartEngine.d.ts.map +1 -1
  21. package/dist/core/useLiveChartSeriesEngine.d.ts +9 -1
  22. package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
  23. package/dist/hooks/crosshairSeries.d.ts +1 -1
  24. package/dist/hooks/crosshairSeries.d.ts.map +1 -1
  25. package/dist/hooks/crosshairShared.d.ts +4 -2
  26. package/dist/hooks/crosshairShared.d.ts.map +1 -1
  27. package/dist/hooks/useCrosshair.d.ts +5 -1
  28. package/dist/hooks/useCrosshair.d.ts.map +1 -1
  29. package/dist/hooks/useCrosshairSeries.d.ts.map +1 -1
  30. package/dist/hooks/useMarkers.d.ts +2 -2
  31. package/dist/hooks/useMarkers.d.ts.map +1 -1
  32. package/dist/hooks/usePanScroll.d.ts +2 -0
  33. package/dist/hooks/usePanScroll.d.ts.map +1 -1
  34. package/dist/hooks/usePinchZoom.d.ts +2 -0
  35. package/dist/hooks/usePinchZoom.d.ts.map +1 -1
  36. package/dist/hooks/useReferenceLineSeries.d.ts +1 -1
  37. package/dist/hooks/useReferenceLineSeries.d.ts.map +1 -1
  38. package/dist/hooks/useScrubMarkers.d.ts +2 -1
  39. package/dist/hooks/useScrubMarkers.d.ts.map +1 -1
  40. package/dist/hooks/useVisibleRange.d.ts +8 -17
  41. package/dist/hooks/useVisibleRange.d.ts.map +1 -1
  42. package/dist/index.d.ts +1 -1
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/math/markers.d.ts +6 -0
  45. package/dist/math/markers.d.ts.map +1 -1
  46. package/dist/math/referenceLineSeries.d.ts +1 -1
  47. package/dist/math/referenceLineSeries.d.ts.map +1 -1
  48. package/dist/math/scrubMarkers.d.ts +1 -1
  49. package/dist/math/scrubMarkers.d.ts.map +1 -1
  50. package/dist/math/spline.d.ts +3 -2
  51. package/dist/math/spline.d.ts.map +1 -1
  52. package/dist/types.d.ts +47 -6
  53. package/dist/types.d.ts.map +1 -1
  54. package/package.json +1 -1
  55. package/src/components/CrosshairOverlay.tsx +7 -0
  56. package/src/components/CustomMarkerOverlay.tsx +5 -2
  57. package/src/components/FreeCrosshairOverlay.tsx +87 -0
  58. package/src/components/LiveChart.tsx +97 -73
  59. package/src/components/LiveChartSeries.tsx +33 -20
  60. package/src/components/MarkerOverlay.tsx +24 -14
  61. package/src/components/ScrubActionOverlay.tsx +24 -5
  62. package/src/core/liveChartEngineTick.ts +3 -0
  63. package/src/core/liveChartSeriesEngineTick.ts +25 -4
  64. package/src/core/resolveConfig.ts +13 -0
  65. package/src/core/useLiveChartEngine.ts +14 -2
  66. package/src/core/useLiveChartSeriesEngine.ts +44 -7
  67. package/src/hooks/crosshairSeries.ts +4 -4
  68. package/src/hooks/crosshairShared.ts +18 -12
  69. package/src/hooks/useCrosshair.ts +29 -5
  70. package/src/hooks/useCrosshairSeries.ts +10 -4
  71. package/src/hooks/useMarkers.ts +7 -4
  72. package/src/hooks/usePanScroll.ts +3 -1
  73. package/src/hooks/usePinchZoom.ts +8 -5
  74. package/src/hooks/useReferenceLineSeries.ts +8 -4
  75. package/src/hooks/useScrubMarkers.ts +5 -2
  76. package/src/hooks/useVisibleRange.ts +96 -66
  77. package/src/index.ts +1 -0
  78. package/src/math/markers.ts +25 -8
  79. package/src/math/referenceLineSeries.ts +4 -3
  80. package/src/math/scrubMarkers.ts +4 -1
  81. package/src/math/spline.ts +41 -25
  82. package/src/types.ts +45 -6
@@ -26,6 +26,8 @@ type CrosshairOverlayProps = {
26
26
  palette: LiveChartPalette;
27
27
  font: SkFont;
28
28
  showTooltip?: boolean;
29
+ /** Additional guides drawn under the selection dot with the same edge fade. */
30
+ guides?: ReactNode;
29
31
  /** Optional custom tooltip body rendered in place of the default value/time
30
32
  * text (e.g. the multi-line candle stack). Passed as children so it composes
31
33
  * instead of being threaded through as a JSX-valued prop. */
@@ -94,6 +96,7 @@ export function CrosshairOverlay({
94
96
  palette,
95
97
  font,
96
98
  showTooltip = true,
99
+ guides,
97
100
  children,
98
101
  renderTooltip,
99
102
  lineTop,
@@ -209,6 +212,7 @@ export function CrosshairOverlay({
209
212
  />
210
213
  <CrosshairVisibleLayer
211
214
  opacity={visibleOpacity}
215
+ guides={guides}
212
216
  p1={p1}
213
217
  p2={p2}
214
218
  palette={palette}
@@ -314,6 +318,7 @@ function CrosshairDimLayer({
314
318
 
315
319
  function CrosshairVisibleLayer({
316
320
  opacity,
321
+ guides,
317
322
  p1,
318
323
  p2,
319
324
  palette,
@@ -349,6 +354,7 @@ function CrosshairVisibleLayer({
349
354
  tooltipColor,
350
355
  }: {
351
356
  opacity: SharedValue<number>;
357
+ guides?: ReactNode;
352
358
  p1: SharedValue<{ x: number; y: number }>;
353
359
  p2: SharedValue<{ x: number; y: number }>;
354
360
  palette: LiveChartPalette;
@@ -385,6 +391,7 @@ function CrosshairVisibleLayer({
385
391
  }) {
386
392
  return (
387
393
  <Group opacity={opacity}>
394
+ {guides}
388
395
  <CrosshairLine
389
396
  show={showLine}
390
397
  p1={p1}
@@ -9,7 +9,7 @@ import Animated, {
9
9
  } from "react-native-reanimated";
10
10
  import { scheduleOnRN } from "react-native-worklets";
11
11
 
12
- import type { ChartEngineLayout } from "../core/useLiveChartEngine";
12
+ import type { MarkerEngineLayout } from "../core/useLiveChartEngine";
13
13
  import type { ChartPadding } from "../draw/line";
14
14
  import {
15
15
  markersSignature,
@@ -129,7 +129,7 @@ export function CustomMarkerOverlay({
129
129
  marker: Marker,
130
130
  ctx: MarkerRenderContext,
131
131
  ) => React.ReactElement | null | undefined;
132
- engine: ChartEngineLayout;
132
+ engine: MarkerEngineLayout;
133
133
  padding: ChartPadding;
134
134
  /** Multi-series data, used to anchor markers by `seriesId`. */
135
135
  series?: SharedValue<SeriesConfig[]>;
@@ -195,6 +195,9 @@ export function CustomMarkerOverlay({
195
195
  padLeft: padding.left,
196
196
  padRight: padding.right,
197
197
  timestamp: engine.timestamp.get(),
198
+ tipTime: engine.tipTime?.get(),
199
+ displaySeriesValues: engine.displaySeriesValues?.get(),
200
+ smoothRecordedTail: engine.smoothRecordedTail?.get(),
198
201
  displayWindow: engine.displayWindow.get(),
199
202
  displayMin: engine.displayMin.get(),
200
203
  displayMax: engine.displayMax.get(),
@@ -0,0 +1,87 @@
1
+ import type { SkFont } from "@shopify/react-native-skia";
2
+ import { useDerivedValue, type SharedValue } from "react-native-reanimated";
3
+ import { X_AXIS_LABEL_OFFSET_Y } from "../constants";
4
+ import type { ResolvedScrubConfig } from "../core/resolveConfig";
5
+ import type { ChartEngineLayout } from "../core/useLiveChartEngine";
6
+ import type { ChartPadding } from "../draw/line";
7
+ import {
8
+ computeActionBadgeLayout,
9
+ computeTimeBadgeLayout,
10
+ computeValueAtY,
11
+ HIDDEN_ACTION_BADGE,
12
+ HIDDEN_TIME_BADGE,
13
+ } from "../hooks/crosshairShared";
14
+ import type { BadgeMetrics, LiveChartPalette } from "../types";
15
+ import { ScrubActionOverlay } from "./ScrubActionOverlay";
16
+
17
+ const SOLID: number[] = [];
18
+
19
+ /** Mounted only while free scrubbing is configured. The parent draws the
20
+ * vertical guide and applies the same visible opacity to the whole crosshair. */
21
+ export function FreeCrosshairOverlay({
22
+ active, x, y, time, engine, padding, volumeBandHeight, side,
23
+ font, metrics, palette, scrub, formatValue, formatTime,
24
+ }: {
25
+ active: SharedValue<boolean>;
26
+ x: SharedValue<number>;
27
+ y: SharedValue<number>;
28
+ time: SharedValue<number>;
29
+ engine: ChartEngineLayout;
30
+ padding: ChartPadding;
31
+ volumeBandHeight: number;
32
+ side: "left" | "right";
33
+ font: SkFont;
34
+ metrics: BadgeMetrics;
35
+ palette: LiveChartPalette;
36
+ scrub: ResolvedScrubConfig;
37
+ formatValue: (value: number) => string;
38
+ formatTime: (time: number) => string;
39
+ }) {
40
+ const { canvasHeight, canvasWidth, displayMin, displayMax } = engine;
41
+ const { padX, padY, marginEdge } = metrics;
42
+ const priceBadge = useDerivedValue(() => {
43
+ const pointerY = y.get();
44
+ if (!active.get() || pointerY < 0) return HIDDEN_ACTION_BADGE;
45
+ const price = computeValueAtY(
46
+ pointerY, displayMin.get(), displayMax.get(), canvasHeight.get(),
47
+ padding.top, padding.bottom,
48
+ );
49
+ if (price === null) return HIDDEN_ACTION_BADGE;
50
+ const width = canvasWidth.get();
51
+ const plotEdge = side === "left" ? padding.left : width - padding.right;
52
+ return computeActionBadgeLayout(
53
+ true, pointerY, formatValue(price), "", width, plotEdge,
54
+ font, marginEdge, padX, padY, side,
55
+ );
56
+ });
57
+ const timeBadge = useDerivedValue(() => {
58
+ const selectedTime = time.get();
59
+ if (!active.get() || selectedTime < 0) return HIDDEN_TIME_BADGE;
60
+ const baseline = canvasHeight.get() - padding.bottom + volumeBandHeight + X_AXIS_LABEL_OFFSET_Y;
61
+ return computeTimeBadgeLayout(
62
+ true, x.get(), formatTime(selectedTime), canvasWidth.get(), baseline,
63
+ font, padX, padY, marginEdge,
64
+ );
65
+ });
66
+
67
+ return (
68
+ <ScrubActionOverlay
69
+ lockActive={active}
70
+ lockX={x}
71
+ lockY={y}
72
+ actionBadge={priceBadge}
73
+ timeBadge={timeBadge}
74
+ engine={engine}
75
+ padding={padding}
76
+ palette={palette}
77
+ font={font}
78
+ icon=""
79
+ lineColor={scrub.crosshairLineColor}
80
+ background={scrub.tooltipBackground ?? palette.tooltipBg}
81
+ iconColor={scrub.tooltipColor ?? palette.tooltipText}
82
+ showVerticalLine={false}
83
+ levelDash={scrub.crosshairDash ?? SOLID}
84
+ levelStrokeWidth={scrub.crosshairStrokeWidth}
85
+ />
86
+ );
87
+ }
@@ -204,6 +204,7 @@ import { CustomTooltipOverlay } from "./CustomTooltipOverlay";
204
204
  import { BadgeOverlay } from "./BadgeOverlay";
205
205
  import { ChartOverlayLayer } from "./ChartOverlayLayer";
206
206
  import { CrosshairOverlay } from "./CrosshairOverlay";
207
+ import { FreeCrosshairOverlay } from "./FreeCrosshairOverlay";
207
208
  import { DegenParticlesOverlay } from "./DegenParticlesOverlay";
208
209
  import { DotOverlay } from "./DotOverlay";
209
210
  import { LeftEdgeFade } from "./LeftEdgeFade";
@@ -945,26 +946,18 @@ function resolveLiveChartInteractionConfig({
945
946
  timeScrollEnabled: boolean;
946
947
  scrubCfg: ReturnType<typeof resolveScrub>;
947
948
  }) {
948
- const crosshairChartOpts = isCandle
949
- ? {
950
- mode,
951
- candles: candlesEngine,
952
- liveCandle: liveEngine,
953
- candleWidthSecs: candleWidth,
954
- gaps: candleGapsCfg?.gaps,
955
- bridgeNoTrades: Boolean(candleGapsCfg?.styles["no-trades"].bridge),
956
- bridgeUnavailable: Boolean(candleGapsCfg?.styles.unavailable.bridge),
957
- bridgeUnknown: Boolean(candleGapsCfg?.styles.unknown.bridge),
958
- }
959
- : lineGapsCfg
960
- ? {
961
- mode,
962
- gaps: lineGapsCfg.gaps,
963
- bridgeNoTrades: Boolean(lineGapsCfg.styles["no-trades"].bridge),
964
- bridgeUnavailable: Boolean(lineGapsCfg.styles.unavailable.bridge),
965
- bridgeUnknown: Boolean(lineGapsCfg.styles.unknown.bridge),
966
- }
967
- : undefined;
949
+ const gaps = isCandle ? candleGapsCfg : lineGapsCfg;
950
+ const crosshairChartOpts = {
951
+ mode,
952
+ candles: isCandle ? candlesEngine : undefined,
953
+ liveCandle: isCandle ? liveEngine : undefined,
954
+ candleWidthSecs: isCandle ? candleWidth : undefined,
955
+ gaps: gaps?.gaps,
956
+ bridgeNoTrades: Boolean(gaps?.styles["no-trades"].bridge),
957
+ bridgeUnavailable: Boolean(gaps?.styles.unavailable.bridge),
958
+ bridgeUnknown: Boolean(gaps?.styles.unknown.bridge),
959
+ freeCrosshair: scrubCfg?.freeCrosshair != null,
960
+ };
968
961
  const scrollGestureMode =
969
962
  typeof timeScroll === "object"
970
963
  ? (timeScroll.gesture ?? "holdToScrub")
@@ -2229,6 +2222,18 @@ function useLiveChartController({
2229
2222
  shouldOmitTipBeyondData,
2230
2223
  );
2231
2224
 
2225
+ // The locked badge may overlap both the Y-axis gutter and the time ruler.
2226
+ // Only defer to it where the scrub tap accepts a touch-down.
2227
+ const { hitTestActionBadge } = crosshair;
2228
+ const { scrubBottomExclude } = crosshairSettings;
2229
+ const { canvasHeight } = engine;
2230
+ const deferAxisScaleHit = useCallback((x: number, y: number): boolean => {
2231
+ "worklet";
2232
+ const canStartScrubTap =
2233
+ scrubBottomExclude === 0 || y < canvasHeight.get() - scrubBottomExclude;
2234
+ return (canStartScrubTap && hitTestActionBadge(x, y)) || deferTapHit(x, y);
2235
+ }, [scrubBottomExclude, canvasHeight, hitTestActionBadge, deferTapHit]);
2236
+
2232
2237
  // Capture only the shared value in the worklets below. Referencing
2233
2238
  // `crosshair.scrubActive` inside a worklet closes over the whole `crosshair`
2234
2239
  // object (which holds a non-serializable `gesture`), throwing
@@ -2431,7 +2436,7 @@ function useLiveChartController({
2431
2436
  resetButtonState,
2432
2437
  resetButtonCfg,
2433
2438
  renderResetButton,
2434
- deferAxisScaleHit: deferTapHit,
2439
+ deferAxisScaleHit,
2435
2440
  clearCrosshair,
2436
2441
  // passthrough props the render needs
2437
2442
  style,
@@ -3716,6 +3721,8 @@ function ChartScrubLayer({
3716
3721
  renderTooltip,
3717
3722
  canvasMode,
3718
3723
  } = model;
3724
+ if (!scrubCfg) return null;
3725
+
3719
3726
  // A custom tooltip is an RN overlay (sibling of <Canvas>), so the built-in
3720
3727
  // Skia tooltip is suppressed here while it's active — the line pill in line
3721
3728
  // mode, and the OHLC stack in candle mode (see the stack gate below).
@@ -3723,9 +3730,27 @@ function ChartScrubLayer({
3723
3730
  // `otherCandles` is candle-only. If a consumer switches this chart to line
3724
3731
  // mode without also rewriting its scrub config, preserve the standard line
3725
3732
  // scrub (guide, selection dot, and trailing fade).
3726
- const dimsFuture = !isCandle || scrubCfg?.dimTarget === "future";
3727
-
3728
- if (!scrubCfg) return null;
3733
+ const dimsFuture = !isCandle || scrubCfg.dimTarget === "future";
3734
+
3735
+ const showGuide = dimsFuture || crosshair.freeY !== undefined;
3736
+ const guides = crosshair.freeY ? (
3737
+ <FreeCrosshairOverlay
3738
+ active={crosshair.scrubActive}
3739
+ x={crosshair.scrubX}
3740
+ y={crosshair.freeY}
3741
+ time={crosshair.scrubTime}
3742
+ engine={model.engine}
3743
+ padding={effectivePadding}
3744
+ volumeBandHeight={model.volumeBandHeight}
3745
+ side={model.yAxisCfg?.side ?? "right"}
3746
+ font={skiaFont}
3747
+ metrics={model.metricsCfg.badge}
3748
+ palette={palette}
3749
+ scrub={scrubCfg}
3750
+ formatValue={model.formatValue}
3751
+ formatTime={scrubCfg.freeCrosshair?.formatTime ?? model.formatTime}
3752
+ />
3753
+ ) : null;
3729
3754
 
3730
3755
  // Extend the scrub dim past the plot's right edge to fully cover the live dot
3731
3756
  // (with its halo) and pulse ring, all centered on that edge. The gutter
@@ -3737,55 +3762,54 @@ function ChartScrubLayer({
3737
3762
 
3738
3763
  return (
3739
3764
  <Group transform={degen?.shakeTransform}>
3740
- {scrubCfg && (
3741
- <CrosshairOverlay
3742
- scrubX={crosshair.scrubX}
3743
- crosshairOpacity={crosshair.crosshairOpacity}
3744
- tooltipLayout={crosshair.tooltipLayout}
3745
- engine={model.engine}
3746
- padding={effectivePadding}
3747
- palette={palette}
3748
- font={skiaFont}
3749
- showTooltip={scrubCfg.tooltip && !customTooltipActive}
3750
- lineTop={crosshair.tooltipLineTop}
3751
- showLine={dimsFuture}
3752
- selectionDot={dimsFuture ? selectionDot : null}
3753
- selectionY={crosshair.scrubDotY}
3754
- scrubActive={crosshair.scrubActive}
3755
- selectionColor={selectionColor}
3756
- dimOpacity={dimsFuture ? scrubCfg.dimOpacity : 1}
3757
- liveDotExtent={liveDotExtent}
3758
- crosshairLineColor={scrubCfg.crosshairLineColor}
3759
- crosshairStrokeWidth={scrubCfg.crosshairStrokeWidth}
3760
- crosshairOvershoot={scrubCfg.crosshairOvershoot}
3761
- crosshairFade={scrubCfg.crosshairFade}
3762
- crosshairFadeDistance={scrubCfg.crosshairFadeDistance}
3763
- crosshairLineCap={scrubCfg.crosshairLineCap}
3764
- crosshairDash={scrubCfg.crosshairDash}
3765
- crosshairDimColor={
3766
- dimsFuture ? scrubCfg.crosshairDimColor : undefined
3767
- }
3768
- tooltipBackground={scrubCfg.tooltipBackground}
3769
- tooltipColor={scrubCfg.tooltipColor}
3770
- tooltipBorderColor={scrubCfg.tooltipBorderColor}
3771
- tooltipBorderRadius={scrubCfg.tooltipBorderRadius}
3772
- tooltipShowValue={scrubCfg.tooltipShowValue}
3773
- tooltipShowTime={scrubCfg.tooltipShowTime}
3774
- opaqueCanvas={canvasMode === "opaque"}
3775
- >
3776
- {/* Candle charts render a multi-line OHLC tooltip; the line
3777
- chart falls back to CrosshairOverlay's default value/time
3778
- body. Composed as children rather than a JSX-valued prop.
3779
- Suppressed when a custom `renderTooltip` owns the readout. */}
3780
- {isCandle && !customTooltipActive ? (
3781
- <MultiSeriesTooltipStack
3782
- tooltipLayout={crosshair.tooltipLayout}
3783
- font={skiaFont}
3784
- palette={palette}
3785
- />
3786
- ) : null}
3787
- </CrosshairOverlay>
3788
- )}
3765
+ <CrosshairOverlay
3766
+ scrubX={crosshair.scrubX}
3767
+ crosshairOpacity={crosshair.crosshairOpacity}
3768
+ tooltipLayout={crosshair.tooltipLayout}
3769
+ engine={model.engine}
3770
+ padding={effectivePadding}
3771
+ palette={palette}
3772
+ font={skiaFont}
3773
+ showTooltip={scrubCfg.tooltip && !customTooltipActive}
3774
+ lineTop={crosshair.tooltipLineTop}
3775
+ guides={guides}
3776
+ showLine={showGuide}
3777
+ selectionDot={showGuide ? selectionDot : null}
3778
+ selectionY={crosshair.freeY ?? crosshair.scrubDotY}
3779
+ scrubActive={crosshair.scrubActive}
3780
+ selectionColor={selectionColor}
3781
+ dimOpacity={dimsFuture ? scrubCfg.dimOpacity : 1}
3782
+ liveDotExtent={liveDotExtent}
3783
+ crosshairLineColor={scrubCfg.crosshairLineColor}
3784
+ crosshairStrokeWidth={scrubCfg.crosshairStrokeWidth}
3785
+ crosshairOvershoot={scrubCfg.crosshairOvershoot}
3786
+ crosshairFade={scrubCfg.crosshairFade}
3787
+ crosshairFadeDistance={scrubCfg.crosshairFadeDistance}
3788
+ crosshairLineCap={scrubCfg.crosshairLineCap}
3789
+ crosshairDash={scrubCfg.crosshairDash}
3790
+ crosshairDimColor={
3791
+ dimsFuture ? scrubCfg.crosshairDimColor : undefined
3792
+ }
3793
+ tooltipBackground={scrubCfg.tooltipBackground}
3794
+ tooltipColor={scrubCfg.tooltipColor}
3795
+ tooltipBorderColor={scrubCfg.tooltipBorderColor}
3796
+ tooltipBorderRadius={scrubCfg.tooltipBorderRadius}
3797
+ tooltipShowValue={scrubCfg.tooltipShowValue}
3798
+ tooltipShowTime={scrubCfg.tooltipShowTime}
3799
+ opaqueCanvas={canvasMode === "opaque"}
3800
+ >
3801
+ {/* Candle charts render a multi-line OHLC tooltip; the line
3802
+ chart falls back to CrosshairOverlay's default value/time
3803
+ body. Composed as children rather than a JSX-valued prop.
3804
+ Suppressed when a custom `renderTooltip` owns the readout. */}
3805
+ {isCandle && !customTooltipActive ? (
3806
+ <MultiSeriesTooltipStack
3807
+ tooltipLayout={crosshair.tooltipLayout}
3808
+ font={skiaFont}
3809
+ palette={palette}
3810
+ />
3811
+ ) : null}
3812
+ </CrosshairOverlay>
3789
3813
  </Group>
3790
3814
  );
3791
3815
  }
@@ -392,6 +392,30 @@ function composeSeriesRootGesture(
392
392
  : gesture;
393
393
  }
394
394
 
395
+ function useSeriesHistoryBounds(
396
+ renderedSeries: SharedValue<SeriesConfig[]>,
397
+ liveEdge: SharedValue<number>,
398
+ historyStartTime: number | undefined,
399
+ ) {
400
+ const historyFloor = historyStartTime != null && Number.isFinite(historyStartTime)
401
+ ? historyStartTime : null;
402
+ // The engine publishes retained samples and their viewport on the same measured frame.
403
+ const retainedMinTime = useDerivedValue(() => {
404
+ const s = renderedSeries.get();
405
+ let min = Infinity;
406
+ for (let i = 0; i < s.length; i++) {
407
+ const d = s[i].data;
408
+ if (d.length > 0 && d[0].time < min) min = d[0].time;
409
+ }
410
+ return min === Infinity ? null : Math.min(min, historyFloor ?? Infinity);
411
+ });
412
+ // Gestures still need a clamp while the chart has no rendered samples.
413
+ const scrollMinTime = useDerivedValue(() =>
414
+ retainedMinTime.get() ?? historyFloor ?? liveEdge.get(),
415
+ );
416
+ return { retainedMinTime, scrollMinTime };
417
+ }
418
+
395
419
  function useLiveChartSeriesController(props: LiveChartSeriesProps) {
396
420
  const {
397
421
  series,
@@ -581,6 +605,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
581
605
  nowOverride,
582
606
  presentationTime,
583
607
  historyStartTime,
608
+ timeHorizon: props.timeHorizon,
584
609
  });
585
610
  const { layoutHeight, onLayout } = useCanvasLayout(engine);
586
611
  const linePaths = useMultiSeriesLinePaths(
@@ -657,7 +682,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
657
682
  }
658
683
  : undefined,
659
684
  scrubCfg?.clampToPlot ?? false,
660
- resolveScrubMarkerOptions(scrubCfg, markersSV),
685
+ resolveScrubMarkerOptions(scrubCfg, markersSV, engine.tipTime),
661
686
  axisScaleActive,
662
687
  timeScrollEnabled && scrollGestureMode === "axisDrag"
663
688
  ? Math.max(effectivePadding.bottom, AXIS_GRAB_MIN_PX)
@@ -679,26 +704,16 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
679
704
  markersActive,
680
705
  markerHitRadius,
681
706
  onMarkerPress,
682
- series,
707
+ engine.series,
683
708
  undefined, // lineData — multi-series anchors by seriesId
684
709
  true, // autostart
685
710
  false, // lineLinear — per-series curve handled in projection
686
711
  markerClusterCfg,
687
712
  );
688
713
 
689
- // Earliest retained time across all series — clamps how far the window pans
690
- // back, and the `onReachStart` reference. Falls back to the live edge (no
691
- // scrollable history) so panning is a no-op.
692
- const scrollMinTime = useDerivedValue(() => {
693
- const s = engine.series.get();
694
- let min = historyStartTime != null && Number.isFinite(historyStartTime)
695
- ? historyStartTime : Infinity;
696
- for (let i = 0; i < s.length; i++) {
697
- const d = s[i].data;
698
- if (d.length > 0 && d[0].time < min) min = d[0].time;
699
- }
700
- return min === Infinity ? engine.liveEdge.get() : min;
701
- });
714
+ const { retainedMinTime, scrollMinTime } = useSeriesHistoryBounds(
715
+ engine.series, engine.liveEdge, historyStartTime,
716
+ );
702
717
 
703
718
  const panScrollGesture = usePanScroll({
704
719
  engine,
@@ -736,7 +751,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
736
751
 
737
752
  useVisibleRange({
738
753
  engine,
739
- minTime: scrollMinTime,
754
+ minTime: retainedMinTime,
740
755
  onVisibleRangeChange,
741
756
  onReachStart,
742
757
  });
@@ -948,7 +963,6 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
948
963
  markerGroupOpacity,
949
964
  overlayScrubFade,
950
965
  renderMarker,
951
- series,
952
966
  seriesOpacity,
953
967
  seriesIndicatorOpacity,
954
968
  emptyText,
@@ -1077,7 +1091,7 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
1077
1091
  padding={effectivePadding}
1078
1092
  palette={palette}
1079
1093
  font={skiaFont}
1080
- series={series}
1094
+ series={engine.series}
1081
1095
  renderMarker={renderMarker}
1082
1096
  cluster={markerClusterCfg}
1083
1097
  />
@@ -1426,7 +1440,6 @@ function SeriesNativeOverlays({ model }: { model: LiveChartSeriesModel }) {
1426
1440
  overlayScrubFade,
1427
1441
  engine,
1428
1442
  effectivePadding,
1429
- series,
1430
1443
  formatValue,
1431
1444
  seriesTooltipCfg,
1432
1445
  } = model;
@@ -1451,7 +1464,7 @@ function SeriesNativeOverlays({ model }: { model: LiveChartSeriesModel }) {
1451
1464
  renderMarker={renderMarker}
1452
1465
  engine={engine}
1453
1466
  padding={effectivePadding}
1454
- series={series}
1467
+ series={engine.series}
1455
1468
  cluster={markerClusterCfg}
1456
1469
  />
1457
1470
  ) : null}
@@ -15,7 +15,7 @@ import {
15
15
  type SharedValue,
16
16
  } from "react-native-reanimated";
17
17
  import { scheduleOnRN } from "react-native-worklets";
18
- import type { ChartEngineLayout } from "../core/useLiveChartEngine";
18
+ import type { MarkerEngineLayout } from "../core/useLiveChartEngine";
19
19
  import type { ChartPadding } from "../draw/line";
20
20
  import { usePathBuilder } from "../hooks/usePathBuilder";
21
21
  import {
@@ -129,6 +129,7 @@ function pushGroupCountBadge(
129
129
  */
130
130
  function ConnectorGlyph({
131
131
  marker,
132
+ markers,
132
133
  color,
133
134
  engine,
134
135
  padding,
@@ -138,21 +139,23 @@ function ConnectorGlyph({
138
139
  axisY,
139
140
  }: {
140
141
  marker: Marker;
142
+ markers: SharedValue<Marker[]>;
141
143
  color: string;
142
- engine: ChartEngineLayout;
144
+ engine: MarkerEngineLayout;
143
145
  padding: ChartPadding;
144
146
  seriesSV?: SharedValue<SeriesConfig[]>;
145
147
  lineDataSV?: SharedValue<LiveChartPoint[]>;
146
148
  lineLinear?: boolean;
147
149
  axisY: SharedValue<number>;
148
150
  }) {
149
- const { kind } = marker;
150
- const time = marker.time;
151
- const value = marker.value;
152
- const seriesId = marker.seriesId;
153
-
154
- const layout = useDerivedValue(() =>
155
- projectPoint(time, value, seriesId, {
151
+ const { id, kind } = marker;
152
+ // Snapshot identity controls the React tree. Read the current anchor on the
153
+ // UI thread, including same-ID edits and in-place SharedValue.modify updates.
154
+ const index = useDerivedValue(() => markers.get().findIndex(item => item.id === id));
155
+ const layout = useDerivedValue(() => {
156
+ const current = markers.get()[index.get()];
157
+ if (current?.id !== id || current.kind !== kind || !isConnectorMarker(current)) return null;
158
+ return projectPoint(current.time, current.value, current.seriesId, {
156
159
  canvasWidth: engine.canvasWidth.get(),
157
160
  canvasHeight: engine.canvasHeight.get(),
158
161
  padTop: padding.top,
@@ -160,23 +163,26 @@ function ConnectorGlyph({
160
163
  padLeft: padding.left,
161
164
  padRight: padding.right,
162
165
  timestamp: engine.timestamp.get(),
166
+ tipTime: engine.tipTime?.get(),
167
+ displaySeriesValues: engine.displaySeriesValues?.get(),
168
+ smoothRecordedTail: engine.smoothRecordedTail?.get(),
163
169
  displayWindow: engine.displayWindow.get(),
164
170
  displayMin: engine.displayMin.get(),
165
171
  displayMax: engine.displayMax.get(),
166
172
  series: seriesSV?.get(),
167
173
  lineData: lineDataSV?.get(),
168
174
  lineLinear,
169
- }),
170
- );
175
+ });
176
+ });
171
177
 
172
- const opacity = useDerivedValue(() => (layout.get().visible ? 1 : 0));
178
+ const opacity = useDerivedValue(() => (layout.get()?.visible ? 1 : 0));
173
179
 
174
180
  const glyphBuilder = usePathBuilder();
175
181
 
176
182
  const glyphPath = useDerivedValue(() => {
177
183
  const b = glyphBuilder.value;
178
184
  const l = layout.get();
179
- if (l.visible) {
185
+ if (l?.visible) {
180
186
  const x = l.x;
181
187
  const y = l.y;
182
188
  if (kind === "graduation") {
@@ -228,7 +234,7 @@ function ConnectorGlyph({
228
234
  */
229
235
  type MarkerOverlayProps = {
230
236
  markers: SharedValue<Marker[]>;
231
- engine: ChartEngineLayout;
237
+ engine: MarkerEngineLayout;
232
238
  padding: ChartPadding;
233
239
  palette: LiveChartPalette;
234
240
  font: SkFont;
@@ -432,6 +438,9 @@ function useMarkerOverlayModel({
432
438
  padLeft: padding.left,
433
439
  padRight: padding.right,
434
440
  timestamp: engine.timestamp.get(),
441
+ tipTime: engine.tipTime?.get(),
442
+ displaySeriesValues: engine.displaySeriesValues?.get(),
443
+ smoothRecordedTail: engine.smoothRecordedTail?.get(),
435
444
  displayWindow: engine.displayWindow.get(),
436
445
  displayMin: engine.displayMin.get(),
437
446
  displayMax: engine.displayMax.get(),
@@ -570,6 +579,7 @@ export function MarkerOverlay(props: MarkerOverlayProps) {
570
579
  <ConnectorGlyph
571
580
  key={m.id}
572
581
  marker={m}
582
+ markers={props.markers}
573
583
  color={m.color ?? defaultMarkerColor(m.kind, palette)}
574
584
  engine={engine}
575
585
  padding={padding}
@@ -17,6 +17,9 @@ import type {
17
17
  } from "../hooks/crosshairShared";
18
18
  import type { LiveChartPalette } from "../types";
19
19
 
20
+ /** Default dash for the horizontal level line. */
21
+ const LEVEL_DASH = [4, 4];
22
+
20
23
  /**
21
24
  * Scrub-action ("order ticket") overlay: the locked reticle (a horizontal price
22
25
  * level line + a faint vertical line crossing at the reticle) and the right-gutter
@@ -41,6 +44,9 @@ export function ScrubActionOverlay({
41
44
  lineColor,
42
45
  background,
43
46
  iconColor,
47
+ showVerticalLine = true,
48
+ levelDash = LEVEL_DASH,
49
+ levelStrokeWidth = 1,
44
50
  }: {
45
51
  lockActive: SharedValue<boolean>;
46
52
  lockX: SharedValue<number>;
@@ -55,6 +61,12 @@ export function ScrubActionOverlay({
55
61
  lineColor?: string;
56
62
  background?: string;
57
63
  iconColor?: string;
64
+ /** Draw the faint vertical line. Off when another crosshair already draws it. Default true. */
65
+ showVerticalLine?: boolean;
66
+ /** Dash intervals for the horizontal level line; omit for `[4, 4]`. */
67
+ levelDash?: number[];
68
+ /** Horizontal level line width in px. Default 1. */
69
+ levelStrokeWidth?: number;
58
70
  }) {
59
71
  const opacity = useDerivedValue(() => (lockActive.value ? 1 : 0), [lockActive]);
60
72
 
@@ -126,12 +138,19 @@ export function ScrubActionOverlay({
126
138
 
127
139
  return (
128
140
  <Group opacity={opacity}>
129
- <Line p1={hLeft} p2={hRight} color={levelColor} strokeWidth={1}>
130
- <DashPathEffect intervals={[4, 4]} />
131
- </Line>
132
- <Line p1={vTop} p2={vBottom} color={levelColor} strokeWidth={1}>
133
- <DashPathEffect intervals={[2, 4]} />
141
+ <Line
142
+ p1={hLeft}
143
+ p2={hRight}
144
+ color={levelColor}
145
+ strokeWidth={levelStrokeWidth}
146
+ >
147
+ {levelDash.length > 0 ? <DashPathEffect intervals={levelDash} /> : null}
134
148
  </Line>
149
+ {showVerticalLine ? (
150
+ <Line p1={vTop} p2={vBottom} color={levelColor} strokeWidth={1}>
151
+ <DashPathEffect intervals={[2, 4]} />
152
+ </Line>
153
+ ) : null}
135
154
 
136
155
  {/* Circular icon button (the action). */}
137
156
  <Group opacity={iconOpacity}>