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
@@ -35,6 +35,8 @@ export interface EngineTickMutable {
35
35
  * can clamp against the live edge and detect catch-up.
36
36
  */
37
37
  liveEdge: number;
38
+ /** Whether the viewport actually follows live after resolving navigation. */
39
+ following?: boolean;
38
40
  /**
39
41
  * Smoothed value at the visible window's right edge: the live value while
40
42
  * following, or the price at `viewEnd` while scrolled back. Lets a badge track
@@ -321,6 +323,7 @@ export function tickLiveChartEngineFrame(
321
323
  viewEnd != null &&
322
324
  (viewRange !== undefined || viewEnd >= firstDataTime) &&
323
325
  (viewEnd < liveEdge || input.allowFutureViewEnd === true);
326
+ state.following = !scrolledBack && !input.paused && (input.returnT == null || input.returnT >= 1);
324
327
  const canvasChanged =
325
328
  state.lastCanvasWidth !== input.canvasWidth ||
326
329
  state.lastCanvasHeight !== input.canvasHeight;
@@ -1,6 +1,7 @@
1
1
  import { MOTION_METRICS_DEFAULTS } from "../constants";
2
2
  import { lerp } from "../math/lerp";
3
3
  import { rangeAnimationSpeed } from "../math/rangeAnimation";
4
+ import { smoothstep } from "../math/squiggly";
4
5
  import type { SeriesRangeAnimationConfig, SeriesConfig } from "../types";
5
6
 
6
7
  export interface MultiEngineTickMutable {
@@ -10,6 +11,8 @@ export interface MultiEngineTickMutable {
10
11
  currentTime?: number;
11
12
  /** Unzoomed authoritative-history span, including buffer. */
12
13
  fullHistoryWindow?: number | null;
14
+ /** Presentation-only seconds added to the ordinary edge and width when drawing. */
15
+ horizonExtension?: number;
13
16
  /** Untransformed eased bounds, kept separate from presentation output. */
14
17
  fittedMin?: number;
15
18
  fittedMax?: number;
@@ -21,6 +24,8 @@ export interface MultiEngineTickMutable {
21
24
  * stays frozen when scrolled back (see {@link MultiEngineTickInput.viewEnd}).
22
25
  */
23
26
  liveEdge: number;
27
+ /** Whether the viewport actually follows live after resolving navigation. */
28
+ following?: boolean;
24
29
  displayValues: number[];
25
30
  /** Ease the newest recorded sample with its live tip, without editing history. */
26
31
  smoothRecordedTail?: boolean;
@@ -68,6 +73,8 @@ export interface MultiEngineTickInput {
68
73
  nowOverride?: number;
69
74
  /** UI-thread presentation head, with precedence over nowOverride/wall time. */
70
75
  presentationTime?: number;
76
+ timeHorizonAt?: number;
77
+ timeHorizonProgress?: number;
71
78
  /** Right-edge buffer as a fraction of the time window. */
72
79
  windowBuffer?: number;
73
80
  /** Right-edge buffer in seconds. Does not scale with the visible window. */
@@ -137,6 +144,7 @@ export function tickLiveChartSeriesEngineFrame(
137
144
  state.fullHistoryWindow = fullWindow;
138
145
  const liveWindow = input.viewWindow ?? fullWindow ?? input.timeWindow;
139
146
  const liveEdge = baseNow + buffer * liveWindow + bufferSeconds;
147
+ state.horizonExtension = 0;
140
148
  state.liveEdge = liveEdge;
141
149
  const viewEnd = input.viewEnd;
142
150
  // Earliest first-point time across visible series — the floor a frozen edge
@@ -160,6 +168,7 @@ export function tickLiveChartSeriesEngineFrame(
160
168
  viewEnd != null &&
161
169
  viewEnd >= firstDataTime &&
162
170
  (viewEnd < liveEdge || input.allowFutureViewEnd === true);
171
+ state.following = !scrolledBack && !input.paused && (input.returnT == null || input.returnT >= 1);
163
172
  state.smoothRecordedTail = !scrolledBack && input.presentationTime == null;
164
173
  if (scrolledBack) {
165
174
  state.timestamp = viewEnd;
@@ -202,8 +211,8 @@ export function tickLiveChartSeriesEngineFrame(
202
211
 
203
212
  // Pinch-zoom: ease toward the zoom override when set, else the configured
204
213
  // window (mirrors the single-series tick).
205
- const anchoredFollowing = fullWindow != null && input.viewWindow == null &&
206
- !scrolledBack && !input.paused && (input.returnT == null || input.returnT >= 1);
214
+ const unzoomedFollowing = state.following && input.viewWindow == null;
215
+ const anchoredFollowing = fullWindow != null && unzoomedFollowing;
207
216
  // Park the unzoomed width with a frozen edge. Resuming live restores the exact
208
217
  // anchored span; easing a growing target would continuously lose the start.
209
218
  const targetWindow = input.viewWindow ??
@@ -212,7 +221,16 @@ export function tickLiveChartSeriesEngineFrame(
212
221
  ? targetWindow
213
222
  : lerp(state.displayWindow, targetWindow, speed, input.dt);
214
223
 
215
- const winStart = state.timestamp - state.displayWindow;
224
+ const at = input.timeHorizonAt;
225
+ const progress = input.timeHorizonProgress ?? 0;
226
+ if (at != null && Number.isFinite(at) && at > liveEdge && Number.isFinite(progress) &&
227
+ progress > 0 && unzoomedFollowing) {
228
+ state.horizonExtension = (at - liveEdge) * smoothstep(progress);
229
+ }
230
+
231
+ // Fit against the ordinary left edge. Reconstructing it from the extended
232
+ // edge and width can round past a sample sitting exactly on the boundary.
233
+ const winStart = anchoredFollowing ? start! : state.timestamp - state.displayWindow;
216
234
  const range = state.displayMax - state.displayMin;
217
235
 
218
236
  // Historical edges use recorded values. An edge parked in or beyond the
@@ -263,6 +281,7 @@ export function tickLiveChartSeriesEngineFrame(
263
281
  // into the Y range are snapshotted out before that).
264
282
  let minTime = 0;
265
283
  let maxTime = 0;
284
+ const tipTime = Math.min(state.timestamp, baseNow);
266
285
  let dataMin = Infinity;
267
286
  let dataMax = -Infinity;
268
287
 
@@ -289,6 +308,8 @@ export function tickLiveChartSeriesEngineFrame(
289
308
  if (v < tMin) tMin = v;
290
309
  /* istanbul ignore next -- trivial min/max */
291
310
  if (v > tMax) tMax = v;
311
+ // Keep feed-clock tolerance for fitting, but label only samples the path can draw.
312
+ if (points[j].time > tipTime) continue;
292
313
  if (v < dataMin) {
293
314
  dataMin = v;
294
315
  minTime = points[j].time;
@@ -447,7 +468,7 @@ export function tickLiveChartSeriesEngineFrame(
447
468
  min: state.fittedMin,
448
469
  max: state.fittedMax,
449
470
  from: winStart,
450
- to: state.timestamp,
471
+ to: state.timestamp + state.horizonExtension,
451
472
  });
452
473
  if (
453
474
  result &&
@@ -253,6 +253,8 @@ export interface ResolvedScrubConfig {
253
253
  clampToPlot: boolean;
254
254
  /** Candle mode: quantize the scrub X to the hovered candle's center. */
255
255
  snapToCandles: boolean;
256
+ /** Free X/Y crosshair; null keeps the vertical-only crosshair. */
257
+ freeCrosshair: { formatTime: ((time: number) => string) | undefined } | null;
256
258
  }
257
259
 
258
260
  export interface ResolvedPerSeriesTooltipConfig {
@@ -1107,6 +1109,7 @@ const SCRUB_DEFAULTS: ResolvedScrubConfig = {
1107
1109
  hideOverlaysOnScrub: false,
1108
1110
  clampToPlot: false,
1109
1111
  snapToCandles: false,
1112
+ freeCrosshair: null,
1110
1113
  };
1111
1114
 
1112
1115
  const PER_SERIES_TOOLTIP_DEFAULTS: ResolvedPerSeriesTooltipConfig = {
@@ -1196,6 +1199,16 @@ export function resolveScrub(
1196
1199
  0,
1197
1200
  resolved.crosshairFadeDistance,
1198
1201
  );
1202
+ const freeCrosshair =
1203
+ typeof prop === "object" ? prop.freeCrosshair : undefined;
1204
+ resolved.freeCrosshair = freeCrosshair
1205
+ ? {
1206
+ formatTime:
1207
+ typeof freeCrosshair === "object"
1208
+ ? freeCrosshair.formatTime
1209
+ : undefined,
1210
+ }
1211
+ : null;
1199
1212
  }
1200
1213
  return resolved;
1201
1214
  }
@@ -163,6 +163,8 @@ export interface ChartEngineLayout {
163
163
  canvasWidth: SharedValue<number>;
164
164
  canvasHeight: SharedValue<number>;
165
165
  timestamp: SharedValue<number>;
166
+ /** Presented tip time, clamped to the viewport edge; absent uses timestamp. */
167
+ tipTime?: SharedValue<number>;
166
168
  }
167
169
 
168
170
  /**
@@ -190,6 +192,8 @@ export interface ChartEngineScroll {
190
192
  * the live edge. Written by the pan-scroll gesture; read by the engine tick.
191
193
  */
192
194
  viewEnd: SharedValue<number | null>;
195
+ /** Resolved live-follow state of the drawn frame. */
196
+ following: SharedValue<boolean>;
193
197
  /**
194
198
  * The right-edge time the engine would use if following live — advances each
195
199
  * frame even while {@link ChartEngineLayout.timestamp} is frozen by a pan.
@@ -256,10 +260,12 @@ export interface MultiEngineState
256
260
  /** Live-tail presentation only; source history and explicit replay stay exact. */
257
261
  smoothRecordedTail?: SharedValue<boolean>;
258
262
  seriesOpacities: SharedValue<number[]>;
259
- /** Presented tip time, clamped to the viewport edge; absent uses timestamp. */
260
- tipTime?: SharedValue<number>;
261
263
  }
262
264
 
265
+ /** Marker projections share the presented vertices used by multi-series paths. */
266
+ export type MarkerEngineLayout = ChartEngineLayout &
267
+ Partial<Pick<MultiEngineState, "displaySeriesValues" | "smoothRecordedTail">>;
268
+
263
269
  export type EngineState = SingleEngineState | MultiEngineState;
264
270
 
265
271
  /** Canvas, range, and animated live value (badge / value line). */
@@ -320,6 +326,7 @@ export interface EngineFrameRefs {
320
326
  viewWindowSmoothingSV?: SharedValue<boolean>;
321
327
  /** Receives the computed live edge each frame. Optional for callers/tests. */
322
328
  liveEdgeSV?: SharedValue<number>;
329
+ followingSV?: SharedValue<boolean>;
323
330
  /** Receives the smoothed right-edge value each frame. Optional for callers/tests. */
324
331
  edgeValueSV?: SharedValue<number>;
325
332
  /**
@@ -511,6 +518,7 @@ export function applyLiveChartEngineFrame(
511
518
  sv.displayWindow.value = state.displayWindow;
512
519
  sv.timestamp.value = state.timestamp;
513
520
  if (sv.liveEdgeSV) sv.liveEdgeSV.value = state.liveEdge;
521
+ if (sv.followingSV) sv.followingSV.value = state.following!;
514
522
  if (sv.edgeValueSV) sv.edgeValueSV.value = state.edgeValue;
515
523
  sv.extremaMinValue.value = state.extremaMinValue;
516
524
  sv.extremaMaxValue.value = state.extremaMaxValue;
@@ -729,6 +737,7 @@ export function useLiveChartEngine(
729
737
  const internalViewEnd = useSharedValue<number | null>(null);
730
738
  const viewEnd = viewport?.end ?? internalViewEnd;
731
739
  const liveEdge = useSharedValue(initialTimestamp);
740
+ const following = useSharedValue(!paused);
732
741
  const edgeValue = useSharedValue(0);
733
742
  // "Return to live" glide (see #164). When time-scroll is disabled while scrolled
734
743
  // back, the reaction below clears `viewEnd`, snapshots the frozen edge into
@@ -812,6 +821,7 @@ export function useLiveChartEngine(
812
821
  viewWindowSV: viewWindow,
813
822
  viewWindowSmoothingSV,
814
823
  liveEdgeSV: liveEdge,
824
+ followingSV: following,
815
825
  edgeValueSV: edgeValue,
816
826
  snapSV,
817
827
  modeSV,
@@ -871,6 +881,7 @@ export function useLiveChartEngine(
871
881
  timestamp,
872
882
  value,
873
883
  viewEnd,
884
+ following,
874
885
  viewWindow,
875
886
  viewWindowSmoothingSV,
876
887
  viewRange,
@@ -1139,6 +1150,7 @@ export function useLiveChartEngine(
1139
1150
  fitMax,
1140
1151
  returnT,
1141
1152
  returnFrom,
1153
+ following,
1142
1154
  liveEdge,
1143
1155
  edgeValue,
1144
1156
  extremaMinValue,
@@ -10,7 +10,7 @@ import {
10
10
  type SharedValue,
11
11
  } from "react-native-reanimated";
12
12
  import { MS_PER_FRAME_60FPS, RETURN_TO_LIVE_MS } from "../constants";
13
- import type { LiveChartPoint, SeriesRangeAnimationConfig, SeriesConfig } from "../types";
13
+ import type { LiveChartSeriesProps, LiveChartPoint, SeriesRangeAnimationConfig, SeriesConfig } from "../types";
14
14
  import {
15
15
  tickLiveChartSeriesEngineFrame,
16
16
  type MultiEngineTickInput,
@@ -36,6 +36,7 @@ export interface MultiSeriesEngineConfig {
36
36
  yRangeScale?: SharedValue<number>;
37
37
  nowOverride?: number;
38
38
  presentationTime?: SharedValue<number | undefined>;
39
+ timeHorizon?: LiveChartSeriesProps["timeHorizon"];
39
40
  windowBuffer?: number;
40
41
  /** Right-edge buffer in seconds. Does not scale with the visible window. */
41
42
  windowBufferSeconds?: number;
@@ -100,6 +101,10 @@ export interface MultiEngineFrameRefs {
100
101
  yRangeScaleSV?: SharedValue<number>;
101
102
  nowOverrideSV?: FrameParameter<number | undefined>;
102
103
  presentationTimeSV?: SharedValue<number | undefined>;
104
+ timeHorizon?: LiveChartSeriesProps["timeHorizon"];
105
+ horizonExtensionSV?: SharedValue<number>;
106
+ /** Drawn viewport, including the horizon. Frame easing and gestures use the ordinary pair. */
107
+ presentedViewport?: Pick<MultiEngineState, "timestamp" | "displayWindow">;
103
108
  historyStartTimeSV?: FrameParameter<number | undefined>;
104
109
  currentTimeSV?: SharedValue<number>;
105
110
  fullHistoryWindowSV?: SharedValue<number | null>;
@@ -119,6 +124,7 @@ export interface MultiEngineFrameRefs {
119
124
  viewWindowSV?: SharedValue<number | null>;
120
125
  /** Receives the computed live edge each frame. Optional for callers/tests. */
121
126
  liveEdgeSV?: SharedValue<number>;
127
+ followingSV?: SharedValue<boolean>;
122
128
  /**
123
129
  * One-shot "snap the framing this frame" flag (set by the `snapKey` effect).
124
130
  * Consumed and cleared by {@link applyLiveChartSeriesEngineFrame} after the
@@ -250,7 +256,10 @@ export function applyLiveChartSeriesEngineFrame(
250
256
  state.displayMax = sv.displayMax.value;
251
257
  state.fittedMin = sv.fittedMinSV?.value ?? state.fittedMin;
252
258
  state.fittedMax = sv.fittedMaxSV?.value ?? state.fittedMax;
253
- state.displayWindow = sv.displayWindow.value;
259
+ // A pinch supplies the exact width for its focal edge. Apply both on this
260
+ // frame so drawing and paging always read a complete viewport.
261
+ const requestedWindow = sv.viewWindowSV?.value;
262
+ state.displayWindow = requestedWindow ?? sv.displayWindow.value;
254
263
  state.timestamp = sv.timestamp.value;
255
264
  state.liveEdge = sv.liveEdgeSV?.value ?? 0;
256
265
  state.displayValues = displayValues;
@@ -286,6 +295,8 @@ export function applyLiveChartSeriesEngineFrame(
286
295
  input.yRangeScale = sv.yRangeScaleSV?.value ?? 1;
287
296
  input.nowOverride = sv.nowOverrideSV?.value;
288
297
  input.presentationTime = sv.presentationTimeSV?.value;
298
+ input.timeHorizonAt = sv.timeHorizon?.at;
299
+ input.timeHorizonProgress = sv.timeHorizon?.progress.value;
289
300
  input.historyStartTime = sv.historyStartTimeSV?.value;
290
301
  input.windowBuffer = sv.windowBufferSV?.value ?? 0;
291
302
  input.windowBufferSeconds = sv.windowBufferSecondsSV?.value ?? 0;
@@ -297,7 +308,7 @@ export function applyLiveChartSeriesEngineFrame(
297
308
  input.allowFutureViewEnd = sv.allowFutureViewEndSV?.value ?? false;
298
309
  input.returnT = sv.returnTSV?.value;
299
310
  input.returnFrom = sv.returnFromSV?.value;
300
- input.viewWindow = sv.viewWindowSV?.value;
311
+ input.viewWindow = requestedWindow;
301
312
  tickLiveChartSeriesEngineFrame(state, input);
302
313
  sv.displayMin.value = state.displayMin;
303
314
  sv.displayMax.value = state.displayMax;
@@ -305,7 +316,14 @@ export function applyLiveChartSeriesEngineFrame(
305
316
  if (sv.fittedMaxSV) sv.fittedMaxSV.value = state.fittedMax;
306
317
  sv.displayWindow.value = state.displayWindow;
307
318
  sv.timestamp.value = state.timestamp;
319
+ const extension = state.horizonExtension!;
320
+ if (sv.horizonExtensionSV) sv.horizonExtensionSV.value = extension;
321
+ if (sv.presentedViewport) {
322
+ sv.presentedViewport.timestamp.value = state.timestamp + extension;
323
+ sv.presentedViewport.displayWindow.value = state.displayWindow + extension;
324
+ }
308
325
  if (sv.liveEdgeSV) sv.liveEdgeSV.value = state.liveEdge;
326
+ if (sv.followingSV) sv.followingSV.value = state.following!;
309
327
  if (sv.currentTimeSV) sv.currentTimeSV.value = state.currentTime!;
310
328
  if (sv.fullHistoryWindowSV) sv.fullHistoryWindowSV.value = state.fullHistoryWindow ?? null;
311
329
  sv.displaySeriesValues.value = state.displayValues;
@@ -343,13 +361,24 @@ export function useLiveChartSeriesEngine(
343
361
  config: MultiSeriesEngineConfig,
344
362
  ): MultiEngineState & ChartEngineScroll & {
345
363
  currentTime: SharedValue<number>;
364
+ navigationWindow: SharedValue<number>;
365
+ navigationEnd: SharedValue<number>;
346
366
  fullHistoryWindow: SharedValue<number | null>;
347
367
  } {
348
368
  // Pinch-zoom window-width override (null = follow the configured window).
349
369
  // Declared first so `timeWindow` folds it in — see useLiveChartEngine.
350
370
  const viewWindow = useSharedValue<number | null>(null);
351
371
  const fullHistoryWindow = useSharedValue<number | null>(null);
352
- const timeWindow = useDerivedValue(() => viewWindow.value ?? fullHistoryWindow.value ?? config.timeWindow);
372
+ const navigationWindow = useSharedValue(config.timeWindow);
373
+ const horizonExtension = useSharedValue(0);
374
+ const displayWindow = useSharedValue(config.timeWindow);
375
+ const baseTimeWindow = config.timeWindow;
376
+ const timeWindow = useDerivedValue(() => {
377
+ // During a reveal, select ticks across the whole painted span. Ordinary
378
+ // zoom and preset transitions select ticks from their destination (#126).
379
+ if (horizonExtension.value > 0) return displayWindow.value;
380
+ return viewWindow.value ?? fullHistoryWindow.value ?? baseTimeWindow;
381
+ });
353
382
  // These are React props, not UI-thread signals. The registered frame and
354
383
  // return-to-live worklets capture a fresh snapshot when props change. Keeping
355
384
  // them as plain values avoids one native mutable and mapper per parameter.
@@ -380,11 +409,11 @@ export function useLiveChartSeriesEngine(
380
409
  const displayMax = useSharedValue(1);
381
410
  const fittedMinSV = useSharedValue<number | undefined>(undefined);
382
411
  const fittedMaxSV = useSharedValue<number | undefined>(undefined);
383
- const displayWindow = useSharedValue(config.timeWindow);
384
412
  const canvasWidth = useSharedValue(0);
385
413
  const canvasHeight = useSharedValue(0);
386
414
  // Seed once; overwritten by the frame callback on the first tick.
387
415
  const [initialTimestamp] = useState(() => Date.now() / 1000);
416
+ const navigationEnd = useSharedValue(initialTimestamp);
388
417
  const timestamp = useSharedValue(initialTimestamp);
389
418
  const currentTime = useSharedValue(initialTimestamp);
390
419
  const tipTime = useDerivedValue(() => Math.min(timestamp.value, currentTime.value));
@@ -392,6 +421,7 @@ export function useLiveChartSeriesEngine(
392
421
  // Pan-scroll state (see useLiveChartEngine). Defaults to following live.
393
422
  const viewEnd = useSharedValue<number | null>(null);
394
423
  const liveEdge = useSharedValue(initialTimestamp);
424
+ const following = useSharedValue(!config.paused);
395
425
  // "Return to live" glide (see #164) — `returnT` rests at 1; the reaction below
396
426
  // animates it 0→1 from `returnFrom` when time-scroll is disabled while scrolled.
397
427
  const returnT = useSharedValue(1);
@@ -447,8 +477,9 @@ export function useLiveChartSeriesEngine(
447
477
  displayMax,
448
478
  fittedMinSV,
449
479
  fittedMaxSV,
450
- displayWindow,
451
- timestamp,
480
+ displayWindow: navigationWindow,
481
+ timestamp: navigationEnd,
482
+ presentedViewport: { timestamp, displayWindow },
452
483
  canvasWidth,
453
484
  canvasHeight,
454
485
  timeWindow: configuredTimeWindow,
@@ -466,6 +497,8 @@ export function useLiveChartSeriesEngine(
466
497
  yRangeScaleSV: config.yRangeScale,
467
498
  nowOverrideSV,
468
499
  presentationTimeSV: config.presentationTime,
500
+ timeHorizon: config.timeHorizon,
501
+ horizonExtensionSV: horizonExtension,
469
502
  currentTimeSV: currentTime,
470
503
  windowBufferSV,
471
504
  windowBufferSecondsSV,
@@ -476,6 +509,7 @@ export function useLiveChartSeriesEngine(
476
509
  returnFromSV: returnFrom,
477
510
  viewWindowSV: viewWindow,
478
511
  liveEdgeSV: liveEdge,
512
+ followingSV: following,
479
513
  snapSV,
480
514
  initialFitPendingSV,
481
515
  extremaMinValue,
@@ -529,12 +563,15 @@ export function useLiveChartSeriesEngine(
529
563
  displayMin,
530
564
  displayMax,
531
565
  displayWindow,
566
+ navigationWindow,
567
+ navigationEnd,
532
568
  timeWindow,
533
569
  canvasWidth,
534
570
  canvasHeight,
535
571
  timestamp,
536
572
  viewEnd,
537
573
  viewWindow,
574
+ following,
538
575
  liveEdge,
539
576
  currentTime,
540
577
  tipTime,
@@ -107,7 +107,7 @@ function clamp(value: number, min: number, max: number): number {
107
107
  */
108
108
  export function computePerSeriesTooltipLayout(
109
109
  scrubActive: boolean,
110
- scrubX: number,
110
+ projectedX: number,
111
111
  scrubTime: number,
112
112
  series: SeriesConfig[],
113
113
  displaySeriesValues: number[],
@@ -135,9 +135,8 @@ export function computePerSeriesTooltipLayout(
135
135
  const plotBottom = canvasHeight - padding.bottom;
136
136
  if (plotRight <= plotLeft || plotBottom <= plotTop) return HIDDEN_TOOLTIP;
137
137
 
138
- const anchorX = pinned
139
- ? plotRight
140
- : clamp(scrubX, plotLeft, plotRight);
138
+ if (pinned && projectedX < plotLeft) return HIDDEN_TOOLTIP;
139
+ const anchorX = clamp(projectedX, plotLeft, plotRight);
141
140
  const activeTime = Math.min(scrubTime, maxTime);
142
141
  if (!pinned && activeTime < 0) return HIDDEN_TOOLTIP;
143
142
 
@@ -155,6 +154,7 @@ export function computePerSeriesTooltipLayout(
155
154
  for (let i = 0; i < renderedSeriesCount; i++) {
156
155
  const item = series[i];
157
156
  if (item.visible === false || item.data.length === 0) continue;
157
+ if (pinned && item.data[0].time > maxTime) continue;
158
158
  const value = pinned
159
159
  ? (displaySeriesValues[i] ?? item.value)
160
160
  : valueAtTime(item, activeTime, maxTime, displaySeriesValues[i]);
@@ -220,6 +220,10 @@ export interface CrosshairState {
220
220
  timeBadge?: SharedValue<TimeBadgeLayout>;
221
221
  /** Tap gesture that places/moves the reticle, presses the badge, or dismisses. */
222
222
  tapGesture?: ReturnType<typeof Gesture.Tap>;
223
+
224
+ // ── Free X/Y crosshair (`scrub.freeCrosshair`) — single-series only. ───────
225
+ /** Finger Y in canvas px, clamped to the plot (-1 when not scrubbing). */
226
+ freeY?: SharedValue<number>;
223
227
  }
224
228
 
225
229
  /**
@@ -840,12 +844,13 @@ export function computeActionBadgeLayout(
840
844
  priceText: string,
841
845
  icon: string,
842
846
  canvasWidth: number,
843
- /** Plot's right edge (= canvasWidth - padding.right) — where the level line ends. */
844
- plotRight: number,
847
+ /** Plot edge adjacent to the price axis. */
848
+ plotEdge: number,
845
849
  font: SkFont,
846
850
  marginEdge: number,
847
851
  padX: number,
848
852
  padY: number,
853
+ side: "left" | "right" = "right",
849
854
  ): ActionBadgeLayout {
850
855
  "worklet";
851
856
  if (!locked || canvasWidth <= 0) return HIDDEN_ACTION_BADGE;
@@ -857,15 +862,16 @@ export function computeActionBadgeLayout(
857
862
  const pillH = font.getSize() + padY * 2;
858
863
  const r = pillH / 2;
859
864
  const top = lockY - pillH / 2;
860
- const rightEdge = canvasWidth - marginEdge;
865
+ const leftAxis = side === "left";
866
+ const edge = leftAxis ? marginEdge : canvasWidth - marginEdge;
861
867
 
862
868
  const fm = font.getMetrics();
863
869
  const textY = lockY - (fm.ascent + fm.descent) / 2;
864
870
 
865
871
  // Price pill (the readout) sits in the price-axis gutter, anchored to the edge.
866
872
  let priceW = 0;
867
- let priceX = rightEdge;
868
- let priceTextX = rightEdge;
873
+ let priceX = edge;
874
+ let priceTextX = edge;
869
875
  if (hasPrice) {
870
876
  // Size the pill to the text's ACTUAL visual bounds (+ pad each side), then
871
877
  // position the text origin so the *ink* — not the advance box — is centered:
@@ -881,19 +887,19 @@ export function computeActionBadgeLayout(
881
887
  // while a reticle is shown). See the price-pill centering tests.
882
888
  const bounds = font.measureText(priceText);
883
889
  priceW = bounds.width + padX * 2;
884
- priceX = rightEdge - priceW;
890
+ priceX = leftAxis ? edge : edge - priceW;
885
891
  priceTextX = priceX + padX - bounds.x;
886
892
  }
887
893
 
888
- // Circular icon button: left of the price pill, or — when alone (icon-only) —
889
- // anchored to the plot's right edge so it stays attached to the level line.
890
- let iconCx = plotRight;
894
+ // The action button sits on the plot-facing side of the pill.
895
+ let iconCx = plotEdge;
891
896
  if (hasIcon && hasPrice) {
892
- iconCx = priceX - ACTION_BADGE_GAP - r;
897
+ const gapToCenter = ACTION_BADGE_GAP + r;
898
+ iconCx = leftAxis ? priceX + priceW + gapToCenter : priceX - gapToCenter;
893
899
  }
894
900
 
895
- const unionLeft = hasIcon ? iconCx - r : priceX;
896
- const unionRight = hasPrice ? rightEdge : iconCx + r;
901
+ const unionLeft = hasPrice && (leftAxis || !hasIcon) ? priceX : iconCx - r;
902
+ const unionRight = hasPrice && (!leftAxis || !hasIcon) ? priceX + priceW : iconCx + r;
897
903
 
898
904
  return {
899
905
  x: unionLeft,
@@ -1,5 +1,5 @@
1
1
  import { type SkFont } from "@shopify/react-native-skia";
2
- import { useMemo, useRef } from "react";
2
+ import { useCallback, useMemo, useRef } from "react";
3
3
  import { Gesture } from "react-native-gesture-handler";
4
4
  import {
5
5
  useAnimatedReaction,
@@ -110,6 +110,8 @@ export {
110
110
  } from "./crosshairShared";
111
111
 
112
112
  export interface CrosshairChartOpts {
113
+ /** Track finger Y for the optional free-crosshair guides. */
114
+ freeCrosshair?: boolean;
113
115
  mode: "line" | "candle";
114
116
  candles?: SharedValue<CandlePoint[]>;
115
117
  liveCandle?: SharedValue<CandlePoint | null>;
@@ -221,7 +223,7 @@ export function useCrosshair(
221
223
  axisScaleActive?: SharedValue<boolean>,
222
224
  /** Buffered line charts must not expose synthetic prices in future space. */
223
225
  shouldClampToLatestPoint = false,
224
- ): CrosshairState {
226
+ ): CrosshairState & { hitTestActionBadge: (x: number, y: number) => boolean } {
225
227
  // Config objects may be recreated without changing the plot geometry. Keep
226
228
  // worklet closures and gestures stable until an actual inset changes.
227
229
  const { top, right, bottom, left } = paddingInput;
@@ -230,6 +232,8 @@ export function useCrosshair(
230
232
  [top, right, bottom, left],
231
233
  );
232
234
  const scrubPointerX = useSharedValue(-1);
235
+ const scrubPointerY = useSharedValue(-1);
236
+ const hasFreeCrosshair = chartOpts?.freeCrosshair ?? false;
233
237
  const scrubGestureActive = useSharedValue(false);
234
238
  // Tracks whether the active scrub phase actually began, so a tap that never
235
239
  // activates doesn't emit a spurious onGestureEnd.
@@ -486,6 +490,12 @@ export function useCrosshair(
486
490
  const lockCandle = useSharedValue<CandlePoint | null>(null);
487
491
  const actionBadge = useSharedValue(HIDDEN_ACTION_BADGE);
488
492
  const timeBadge = useSharedValue(HIDDEN_TIME_BADGE);
493
+ const hitTestActionBadge = useCallback((x: number, y: number): boolean => {
494
+ "worklet";
495
+ if (!enabled || !hasScrubAction || !lockActive.get()) return false;
496
+ const rect = actionBadge.get();
497
+ return rect.visible && pointInRect(x, y, rect, ACTION_HIT_SLOP);
498
+ }, [enabled, hasScrubAction, lockActive, actionBadge]);
489
499
 
490
500
  // The lock price, projected coordinates, candle and both badges are one
491
501
  // coherent reticle snapshot. Publishing them from one reaction replaces six
@@ -877,6 +887,11 @@ export function useCrosshair(
877
887
  deferTapHit(downX.get(), downY.get())
878
888
  )
879
889
  return;
890
+ if (hasFreeCrosshair) {
891
+ scrubPointerY.set(
892
+ clampPlotY(e.y, padding.top, canvasHeightSV.get(), padding.bottom),
893
+ );
894
+ }
880
895
  startPlainScrub(
881
896
  snapCandleX(e.x),
882
897
  padding,
@@ -918,6 +933,11 @@ export function useCrosshair(
918
933
  }
919
934
  return;
920
935
  }
936
+ if (hasFreeCrosshair && scrubGestureActive.get()) {
937
+ scrubPointerY.set(
938
+ clampPlotY(e.y, padding.top, canvasHeightSV.get(), padding.bottom),
939
+ );
940
+ }
921
941
  updatePlainScrub(
922
942
  snapCandleX(e.x),
923
943
  padding,
@@ -934,6 +954,7 @@ export function useCrosshair(
934
954
  resetDelayedPanGuard(fingerDown, panActivated, holdBroken);
935
955
  // A lock-adjust drag leaves the reticle in place. End the gesture even
936
956
  // when its visible selection is hidden outside the recorded window.
957
+ scrubPointerY.set(-1);
937
958
  if (scrubGestureActive.get()) {
938
959
  scrubGestureActive.set(false);
939
960
  if (hasOnScrub) scheduleOnRN(handleScrubEnd);
@@ -982,8 +1003,7 @@ export function useCrosshair(
982
1003
  if (!enabled || !hasScrubAction || !success) return;
983
1004
  if (lockActive.get()) {
984
1005
  // 1. Action-badge press → fire onScrubAction with the chosen price.
985
- const rect = actionBadge.get();
986
- if (rect.visible && pointInRect(e.x, e.y, rect, ACTION_HIT_SLOP)) {
1006
+ if (hitTestActionBadge(e.x, e.y)) {
987
1007
  const price = lockPrice.get();
988
1008
  if (price !== null) {
989
1009
  let candleJson: string | null = null;
@@ -1052,7 +1072,6 @@ export function useCrosshair(
1052
1072
  if (tapGesture && tapHitSlop) tapGesture = tapGesture.hitSlop(tapHitSlop);
1053
1073
  return { gesture, tapGesture };
1054
1074
  }, [
1055
- actionBadge,
1056
1075
  axisScaleActive,
1057
1076
  candleWidthSecs,
1058
1077
  candlesSV,
@@ -1076,11 +1095,13 @@ export function useCrosshair(
1076
1095
  handleGestureStart,
1077
1096
  handleScrubAction,
1078
1097
  handleScrubEnd,
1098
+ hasFreeCrosshair,
1079
1099
  hasOnGestureEnd,
1080
1100
  hasOnGestureStart,
1081
1101
  hasOnScrub,
1082
1102
  hasOnScrubAction,
1083
1103
  hasScrubAction,
1104
+ hitTestActionBadge,
1084
1105
  holdBroken,
1085
1106
  isCandleMode,
1086
1107
  liveCandleSV,
@@ -1098,6 +1119,7 @@ export function useCrosshair(
1098
1119
  scrubGestureActive,
1099
1120
  scrubBottomExclude,
1100
1121
  scrubPointerX,
1122
+ scrubPointerY,
1101
1123
  snapToCandles,
1102
1124
  timestampSV,
1103
1125
  ]);
@@ -1120,7 +1142,9 @@ export function useCrosshair(
1120
1142
  lockY,
1121
1143
  lockPrice,
1122
1144
  actionBadge,
1145
+ hitTestActionBadge,
1123
1146
  timeBadge,
1124
1147
  tapGesture,
1148
+ freeY: hasFreeCrosshair ? scrubPointerY : undefined,
1125
1149
  };
1126
1150
  }
@@ -158,9 +158,15 @@ export function useCrosshairSeries(
158
158
 
159
159
  const tooltipLayout = useDerivedValue(() => {
160
160
  if (!tooltip) return HIDDEN_TOOLTIP;
161
+ const active = scrubActive.get();
162
+ const canvasWidth = engine.canvasWidth.get();
163
+ const head = tooltip.maxTime.get();
164
+ const anchorX = !active && tooltip.config.alwaysShow
165
+ ? lineTipX(engine.timestamp.get(), engine.displayWindow.get(), head, canvasWidth, padding)
166
+ : scrubX.get();
161
167
  return computePerSeriesTooltipLayout(
162
- scrubActive.get(),
163
- scrubX.get(),
168
+ active,
169
+ anchorX,
164
170
  scrubTime.get(),
165
171
  engine.series.get(),
166
172
  engine.displaySeriesValues.get(),
@@ -168,9 +174,9 @@ export function useCrosshairSeries(
168
174
  engine.displayMin.get(),
169
175
  engine.displayMax.get(),
170
176
  padding,
171
- engine.canvasWidth.get(),
177
+ canvasWidth,
172
178
  engine.canvasHeight.get(),
173
- tooltip.maxTime.get(),
179
+ head,
174
180
  tooltip.formatValue,
175
181
  tooltip.formatTime,
176
182
  tooltip.font,