react-native-livechart 4.26.0 → 4.28.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 (142) 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/MultiSeriesDots.d.ts +1 -1
  9. package/dist/components/MultiSeriesDots.d.ts.map +1 -1
  10. package/dist/components/MultiSeriesValueLabels.d.ts +1 -1
  11. package/dist/components/MultiSeriesValueLabels.d.ts.map +1 -1
  12. package/dist/components/MultiSeriesValueLines.d.ts +1 -1
  13. package/dist/components/MultiSeriesValueLines.d.ts.map +1 -1
  14. package/dist/components/ReferenceLineOverlay.d.ts +4 -0
  15. package/dist/components/ReferenceLineOverlay.d.ts.map +1 -1
  16. package/dist/components/ReferenceValueBadge.d.ts +15 -0
  17. package/dist/components/ReferenceValueBadge.d.ts.map +1 -0
  18. package/dist/components/XAxisOverlay.d.ts +17 -0
  19. package/dist/components/XAxisOverlay.d.ts.map +1 -1
  20. package/dist/core/liveChartEngineTick.d.ts +4 -0
  21. package/dist/core/liveChartEngineTick.d.ts.map +1 -1
  22. package/dist/core/liveChartSeriesEngineTick.d.ts +15 -2
  23. package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
  24. package/dist/core/resolveConfig.d.ts +28 -1
  25. package/dist/core/resolveConfig.d.ts.map +1 -1
  26. package/dist/core/useLiveChartEngine.d.ts +9 -0
  27. package/dist/core/useLiveChartEngine.d.ts.map +1 -1
  28. package/dist/core/useLiveChartSeriesEngine.d.ts +18 -4
  29. package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
  30. package/dist/draw/grid.d.ts +6 -4
  31. package/dist/draw/grid.d.ts.map +1 -1
  32. package/dist/draw/line.d.ts +21 -3
  33. package/dist/draw/line.d.ts.map +1 -1
  34. package/dist/hooks/crosshairSeries.d.ts +2 -2
  35. package/dist/hooks/crosshairSeries.d.ts.map +1 -1
  36. package/dist/hooks/crosshairShared.d.ts +16 -1
  37. package/dist/hooks/crosshairShared.d.ts.map +1 -1
  38. package/dist/hooks/referenceBadgeFont.d.ts +5 -0
  39. package/dist/hooks/referenceBadgeFont.d.ts.map +1 -0
  40. package/dist/hooks/resolveChartLayout.d.ts +18 -2
  41. package/dist/hooks/resolveChartLayout.d.ts.map +1 -1
  42. package/dist/hooks/useBadge.d.ts +16 -1
  43. package/dist/hooks/useBadge.d.ts.map +1 -1
  44. package/dist/hooks/useChartSkiaFont.d.ts +1 -0
  45. package/dist/hooks/useChartSkiaFont.d.ts.map +1 -1
  46. package/dist/hooks/useCrosshair.d.ts +7 -2
  47. package/dist/hooks/useCrosshair.d.ts.map +1 -1
  48. package/dist/hooks/useCrosshairSeries.d.ts +6 -1
  49. package/dist/hooks/useCrosshairSeries.d.ts.map +1 -1
  50. package/dist/hooks/useLatestCallback.d.ts +6 -0
  51. package/dist/hooks/useLatestCallback.d.ts.map +1 -0
  52. package/dist/hooks/useMarkers.d.ts.map +1 -1
  53. package/dist/hooks/useMultiSeriesDegen.d.ts +1 -1
  54. package/dist/hooks/useMultiSeriesDegen.d.ts.map +1 -1
  55. package/dist/hooks/useMultiSeriesLinePaths.d.ts.map +1 -1
  56. package/dist/hooks/usePanScroll.d.ts +3 -1
  57. package/dist/hooks/usePanScroll.d.ts.map +1 -1
  58. package/dist/hooks/usePinchZoom.d.ts +7 -4
  59. package/dist/hooks/usePinchZoom.d.ts.map +1 -1
  60. package/dist/hooks/useReferenceDrag.d.ts +20 -5
  61. package/dist/hooks/useReferenceDrag.d.ts.map +1 -1
  62. package/dist/hooks/useReferenceLine.d.ts +24 -12
  63. package/dist/hooks/useReferenceLine.d.ts.map +1 -1
  64. package/dist/hooks/useReferenceLinePress.d.ts +4 -2
  65. package/dist/hooks/useReferenceLinePress.d.ts.map +1 -1
  66. package/dist/hooks/useReferenceTagStack.d.ts +31 -0
  67. package/dist/hooks/useReferenceTagStack.d.ts.map +1 -0
  68. package/dist/hooks/useScrubMarkers.d.ts +12 -0
  69. package/dist/hooks/useScrubMarkers.d.ts.map +1 -0
  70. package/dist/hooks/useXAxis.d.ts +1 -1
  71. package/dist/hooks/useXAxis.d.ts.map +1 -1
  72. package/dist/hooks/useYAxis.d.ts +1 -1
  73. package/dist/hooks/useYAxis.d.ts.map +1 -1
  74. package/dist/hooks/useYAxisLabelWidth.d.ts +6 -0
  75. package/dist/hooks/useYAxisLabelWidth.d.ts.map +1 -0
  76. package/dist/hooks/useYAxisScaleGesture.d.ts +34 -0
  77. package/dist/hooks/useYAxisScaleGesture.d.ts.map +1 -0
  78. package/dist/index.d.ts +1 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/math/axisBadgeLayout.d.ts +16 -0
  81. package/dist/math/axisBadgeLayout.d.ts.map +1 -0
  82. package/dist/math/markers.d.ts +3 -0
  83. package/dist/math/markers.d.ts.map +1 -1
  84. package/dist/math/range.d.ts +1 -1
  85. package/dist/math/range.d.ts.map +1 -1
  86. package/dist/math/referenceLines.d.ts.map +1 -1
  87. package/dist/math/referenceTagStack.d.ts +36 -0
  88. package/dist/math/referenceTagStack.d.ts.map +1 -0
  89. package/dist/math/scrubMarkers.d.ts +12 -0
  90. package/dist/math/scrubMarkers.d.ts.map +1 -0
  91. package/dist/types.d.ts +262 -37
  92. package/dist/types.d.ts.map +1 -1
  93. package/package.json +1 -1
  94. package/src/components/CustomReferenceLineOverlay.tsx +50 -8
  95. package/src/components/CustomTooltipOverlay.tsx +5 -1
  96. package/src/components/LiveChart.tsx +580 -138
  97. package/src/components/LiveChartSeries.tsx +139 -19
  98. package/src/components/MultiSeriesDots.tsx +4 -2
  99. package/src/components/MultiSeriesValueLabels.tsx +4 -2
  100. package/src/components/MultiSeriesValueLines.tsx +4 -2
  101. package/src/components/ReferenceLineOverlay.tsx +62 -26
  102. package/src/components/ReferenceValueBadge.tsx +102 -0
  103. package/src/components/XAxisOverlay.tsx +104 -1
  104. package/src/core/liveChartEngineTick.ts +49 -4
  105. package/src/core/liveChartSeriesEngineTick.ts +107 -14
  106. package/src/core/resolveConfig.ts +103 -7
  107. package/src/core/useLiveChartEngine.ts +45 -9
  108. package/src/core/useLiveChartSeriesEngine.ts +47 -6
  109. package/src/draw/grid.ts +17 -13
  110. package/src/draw/line.ts +46 -5
  111. package/src/hooks/crosshairSeries.ts +37 -5
  112. package/src/hooks/crosshairShared.ts +56 -1
  113. package/src/hooks/referenceBadgeFont.ts +35 -0
  114. package/src/hooks/resolveChartLayout.ts +51 -3
  115. package/src/hooks/useBadge.ts +44 -5
  116. package/src/hooks/useChartSkiaFont.ts +1 -1
  117. package/src/hooks/useCrosshair.ts +444 -310
  118. package/src/hooks/useCrosshairSeries.ts +57 -20
  119. package/src/hooks/useLatestCallback.ts +15 -0
  120. package/src/hooks/useMarkers.ts +51 -39
  121. package/src/hooks/useMultiSeriesDegen.ts +10 -5
  122. package/src/hooks/useMultiSeriesLinePaths.ts +2 -0
  123. package/src/hooks/usePanScroll.ts +155 -127
  124. package/src/hooks/usePinchZoom.ts +94 -66
  125. package/src/hooks/useReferenceDrag.ts +409 -156
  126. package/src/hooks/useReferenceLine.ts +453 -277
  127. package/src/hooks/useReferenceLineGrouping.ts +1 -1
  128. package/src/hooks/useReferenceLinePress.ts +121 -53
  129. package/src/hooks/useReferenceTagStack.ts +81 -0
  130. package/src/hooks/useScrubMarkers.ts +79 -0
  131. package/src/hooks/useXAxis.ts +11 -2
  132. package/src/hooks/useYAxis.ts +1 -1
  133. package/src/hooks/useYAxisLabelWidth.ts +26 -0
  134. package/src/hooks/useYAxisScaleGesture.ts +263 -0
  135. package/src/index.ts +11 -0
  136. package/src/math/axisBadgeLayout.ts +37 -0
  137. package/src/math/markers.ts +28 -3
  138. package/src/math/range.ts +35 -0
  139. package/src/math/referenceLines.ts +5 -0
  140. package/src/math/referenceTagStack.ts +112 -0
  141. package/src/math/scrubMarkers.ts +55 -0
  142. package/src/types.ts +263 -37
@@ -1,11 +1,18 @@
1
1
  import { MOTION_METRICS_DEFAULTS } from "../constants";
2
2
  import { lerp } from "../math/lerp";
3
3
  import { rangeAnimationSpeed } from "../math/rangeAnimation";
4
- import type { RangeAnimationConfig, SeriesConfig } from "../types";
4
+ import type { SeriesRangeAnimationConfig, SeriesConfig } from "../types";
5
5
 
6
6
  export interface MultiEngineTickMutable {
7
7
  displayMin: number;
8
8
  displayMax: number;
9
+ /** Current clock before breathing-room buffer. */
10
+ currentTime?: number;
11
+ /** Unzoomed authoritative-history span, including buffer. */
12
+ fullHistoryWindow?: number | null;
13
+ /** Untransformed eased bounds, kept separate from presentation output. */
14
+ fittedMin?: number;
15
+ fittedMax?: number;
9
16
  displayWindow: number;
10
17
  timestamp: number;
11
18
  /**
@@ -35,8 +42,10 @@ export interface MultiEngineTickInput {
35
42
  canvasWidth: number;
36
43
  canvasHeight: number;
37
44
  timeWindow: number;
45
+ /** Authoritative Unix-second start for an expanding live history. */
46
+ historyStartTime?: number;
38
47
  smoothing: number;
39
- rangeAnimation?: RangeAnimationConfig;
48
+ rangeAnimation?: SeriesRangeAnimationConfig;
40
49
  exaggerate: boolean;
41
50
  /** Extra catch-up speed added to `smoothing` when a series tip lags. Default `0.12`. */
42
51
  adaptiveSpeedBoost?: number;
@@ -47,12 +56,16 @@ export interface MultiEngineTickInput {
47
56
  nonNegative?: boolean;
48
57
  /** Hard cap for the computed upper bound. */
49
58
  maxValue?: number;
59
+ /** Smallest fitted span, in data units; widened around the data. */
60
+ minRange?: number;
50
61
  /** Positive, finite Y-range multiplier around the fitted midpoint (1 = auto-fit). */
51
62
  yRangeScale?: number;
52
63
  series: SeriesConfig[];
53
64
  nowSeconds?: number;
54
65
  /** Override the engine's "now" (unix seconds). */
55
66
  nowOverride?: number;
67
+ /** UI-thread presentation head, with precedence over nowOverride/wall time. */
68
+ presentationTime?: number;
56
69
  /** Right-edge buffer as a fraction of the time window. */
57
70
  windowBuffer?: number;
58
71
  paused?: boolean;
@@ -108,8 +121,15 @@ export function tickLiveChartSeriesEngineFrame(
108
121
  input: MultiEngineTickInput,
109
122
  ): void {
110
123
  "worklet";
111
- const baseNow = input.nowOverride ?? input.nowSeconds ?? Date.now() / 1000;
112
- const liveEdge = baseNow + (input.windowBuffer ?? 0) * input.timeWindow;
124
+ const baseNow = input.presentationTime ?? input.nowOverride ?? input.nowSeconds ?? Date.now() / 1000;
125
+ const buffer = input.windowBuffer ?? 0;
126
+ const start = input.historyStartTime;
127
+ const fullWindow = start != null && Number.isFinite(start) && start < baseNow &&
128
+ buffer >= 0 && buffer < 1 ? (baseNow - start) / (1 - buffer) : null;
129
+ state.currentTime = baseNow;
130
+ state.fullHistoryWindow = fullWindow;
131
+ const liveWindow = input.viewWindow ?? fullWindow ?? input.timeWindow;
132
+ const liveEdge = baseNow + buffer * liveWindow;
113
133
  state.liveEdge = liveEdge;
114
134
  const viewEnd = input.viewEnd;
115
135
  // Earliest first-point time across visible series — the floor a frozen edge
@@ -121,6 +141,7 @@ export function tickLiveChartSeriesEngineFrame(
121
141
  const d = input.series[i].data;
122
142
  if (d.length > 0 && d[0].time < firstDataTime) firstDataTime = d[0].time;
123
143
  }
144
+ if (fullWindow != null) firstDataTime = Math.min(firstDataTime, start!);
124
145
  if (firstDataTime === Infinity) firstDataTime = -Infinity;
125
146
  // Freeze the right edge while the gesture has parked `viewEnd` behind the live
126
147
  // edge AND that edge still sits within the data; a stranded edge falls through
@@ -149,6 +170,11 @@ export function tickLiveChartSeriesEngineFrame(
149
170
 
150
171
  if (input.canvasWidth === 0 || input.canvasHeight === 0) return;
151
172
 
173
+ // Never ease/fit against the previous frame's transformed output. Retain these
174
+ // even after removing the callback, so its expansion disappears in one frame.
175
+ state.displayMin = state.fittedMin ?? state.displayMin;
176
+ state.displayMax = state.fittedMax ?? state.displayMax;
177
+
152
178
  const speed = input.smoothing;
153
179
  // One-shot settle (snapKey change): collapse this frame's easing so the
154
180
  // window / range / tips land on target instantly. See `MultiEngineTickInput.snap`.
@@ -168,23 +194,26 @@ export function tickLiveChartSeriesEngineFrame(
168
194
 
169
195
  // Pinch-zoom: ease toward the zoom override when set, else the configured
170
196
  // window (mirrors the single-series tick).
171
- const targetWindow = input.viewWindow ?? input.timeWindow;
172
- state.displayWindow = snap
197
+ const anchoredFollowing = fullWindow != null && input.viewWindow == null &&
198
+ !scrolledBack && !input.paused && (input.returnT == null || input.returnT >= 1);
199
+ // Park the unzoomed width with a frozen edge. Resuming live restores the exact
200
+ // anchored span; easing a growing target would continuously lose the start.
201
+ const targetWindow = input.viewWindow ??
202
+ (fullWindow != null && (scrolledBack || input.paused) ? state.displayWindow : liveWindow);
203
+ state.displayWindow = snap || anchoredFollowing
173
204
  ? targetWindow
174
205
  : lerp(state.displayWindow, targetWindow, speed, input.dt);
175
206
 
176
207
  const winStart = state.timestamp - state.displayWindow;
177
208
  const range = state.displayMax - state.displayMin;
178
209
 
179
- // Scrolled back in time (pan/zoom): the per-series tips/dots sit at the
180
- // window's right edge, so they must track each series' value AT that edge
181
- // (`timestamp`), not the live value — otherwise the dot floats at the current
182
- // price while the line ends in the past. Mirrors single-series `edgeValue`.
183
- // Reuses the gated `scrolledBack` computed above.
210
+ // Historical edges use recorded values. An edge parked in or beyond the
211
+ // future buffer still ends at the presentation head, using its presented
212
+ // value; samples after that head must never enter the tip or fitted range.
184
213
 
185
214
  for (let i = 0; i < n; i++) {
186
215
  let target = series[i].value;
187
- if (scrolledBack) {
216
+ if (scrolledBack && state.timestamp < baseNow) {
188
217
  const pts = series[i].data;
189
218
  let elo = 0;
190
219
  let ehi = pts.length;
@@ -203,7 +232,14 @@ export function tickLiveChartSeriesEngineFrame(
203
232
  (1 - gapRatio) *
204
233
  (input.adaptiveSpeedBoost ??
205
234
  MOTION_METRICS_DEFAULTS.adaptiveSpeedBoost);
206
- state.displayValues[i] = snap
235
+ // History already owns the authoritative target at this timestamp. Easing
236
+ // it again would put the synthetic tip/dot behind the newest recorded point.
237
+ // Unrecorded prices and historical viewport edges retain normal smoothing.
238
+ const pts = series[i].data;
239
+ const latest = pts[pts.length - 1];
240
+ const targetIsRecorded = !scrolledBack && latest != null &&
241
+ latest.time <= Math.min(state.timestamp, baseNow) && latest.value === target;
242
+ state.displayValues[i] = snap || targetIsRecorded
207
243
  ? target
208
244
  : lerp(cur, target, adaptiveSpeed, input.dt);
209
245
 
@@ -237,7 +273,8 @@ export function tickLiveChartSeriesEngineFrame(
237
273
  // already track the edge value, so they stay in-range). Following live,
238
274
  // keep the tail inclusive — feed timestamps can run slightly ahead of
239
275
  // the local clock and must not flicker out of the range.
240
- if (scrolledBack && points[j].time > state.timestamp) break;
276
+ if ((scrolledBack && points[j].time > state.timestamp) ||
277
+ (input.presentationTime != null && points[j].time > baseNow)) break;
241
278
  const v = points[j].value;
242
279
  /* istanbul ignore next -- trivial min/max */
243
280
  if (v < tMin) tMin = v;
@@ -298,6 +335,41 @@ export function tickLiveChartSeriesEngineFrame(
298
335
  tMax += margin;
299
336
  }
300
337
 
338
+ const floorRange = input.minRange;
339
+ // Compare the bounded fit: a clamp can shrink an otherwise wider range.
340
+ // Slide a widened fit off either bound; both hard bounds win if the floor
341
+ // cannot fit between them. Resolve this before the optional manual zoom.
342
+ if (floorRange !== undefined && floorRange > 0 && Number.isFinite(floorRange)) {
343
+ const boundedMin = input.nonNegative && tMin < 0 ? 0 : tMin;
344
+ const boundedMax =
345
+ input.maxValue !== undefined && tMax > input.maxValue ? input.maxValue : tMax;
346
+ if (floorRange > boundedMax - boundedMin) {
347
+ // Halve before adding so large finite prices cannot overflow the midpoint.
348
+ const mid = tMin / 2 + tMax / 2;
349
+ let nextMin = mid - floorRange / 2;
350
+ let nextMax = mid + floorRange / 2;
351
+ if (input.nonNegative && nextMin < 0) {
352
+ nextMax -= nextMin;
353
+ nextMin = 0;
354
+ }
355
+ if (input.maxValue !== undefined && nextMax > input.maxValue) {
356
+ nextMin -= nextMax - input.maxValue;
357
+ nextMax = input.maxValue;
358
+ }
359
+ if (input.nonNegative && nextMin < 0) nextMin = 0;
360
+ // Ignore a floor that would overflow or round the bounds onto each other.
361
+ if (
362
+ Number.isFinite(nextMin) &&
363
+ Number.isFinite(nextMax) &&
364
+ nextMin < nextMax &&
365
+ Number.isFinite(nextMax - nextMin)
366
+ ) {
367
+ tMin = nextMin;
368
+ tMax = nextMax;
369
+ }
370
+ }
371
+ }
372
+
301
373
  // Keep this behavior in parity with the single-series engine: malformed
302
374
  // gesture output must never collapse, invert, or poison the shared axis.
303
375
  const requestedYScale = input.yRangeScale ?? 1;
@@ -357,4 +429,25 @@ export function tickLiveChartSeriesEngineFrame(
357
429
  );
358
430
  }
359
431
  }
432
+
433
+ state.fittedMin = state.displayMin;
434
+ state.fittedMax = state.displayMax;
435
+ const transform = input.rangeAnimation?.transform;
436
+ if (transform) {
437
+ const result = transform({
438
+ min: state.fittedMin,
439
+ max: state.fittedMax,
440
+ from: winStart,
441
+ to: state.timestamp,
442
+ });
443
+ if (
444
+ result &&
445
+ Number.isFinite(result.min) &&
446
+ Number.isFinite(result.max) &&
447
+ result.min < result.max
448
+ ) {
449
+ state.displayMin = result.min;
450
+ state.displayMax = result.max;
451
+ }
452
+ }
360
453
  }
@@ -9,6 +9,7 @@ import type {
9
9
  CandleGapKind,
10
10
  CandleGapLabelStyle,
11
11
  CandleGapsConfig,
12
+ ChartViewportControl,
12
13
  DegenOptions,
13
14
  FontConfig,
14
15
  FontWeight,
@@ -42,9 +43,11 @@ import type {
42
43
  TradeEvent,
43
44
  TransitionConfig,
44
45
  ValueLineConfig,
46
+ ViewportConfig,
45
47
  VolumeConfig,
46
48
  XAxisConfig,
47
49
  YAxisConfig,
50
+ YAxisScaleGestureConfig,
48
51
  ZoomConfig,
49
52
  } from "../types";
50
53
  import type { ComponentType, ReactElement } from "react";
@@ -76,6 +79,8 @@ export interface ResolvedBadgeConfig {
76
79
  variant: BadgeVariant;
77
80
  tail: boolean;
78
81
  position: "right" | "left";
82
+ /** "yAxisColumn" → value in the right-anchored Y-axis label column. */
83
+ textAlign: "center" | "yAxisColumn";
79
84
  background: string | undefined;
80
85
  /** undefined → capsule (pillHeight / 2) at render time */
81
86
  radius: number | undefined;
@@ -93,7 +98,10 @@ export interface ResolvedBadgeConfig {
93
98
  followViewEdge: boolean;
94
99
  }
95
100
 
101
+ export type ResolvedYAxisScaleGestureConfig = Required<YAxisScaleGestureConfig>;
102
+
96
103
  export interface ResolvedYAxisConfig {
104
+ scaleGesture: ResolvedYAxisScaleGestureConfig | null;
97
105
  side: "left" | "right";
98
106
  minGap: number;
99
107
  /** Multiplier used to choose and align representable dynamic nice intervals. */
@@ -188,9 +196,12 @@ export interface ResolvedAxisLabelConfig {
188
196
 
189
197
  export interface ResolvedXAxisConfig {
190
198
  minGap: number;
199
+ /** Vertical grid-line overrides over `gridStyle`; null → no vertical grid. */
200
+ gridLines: GridStyleConfig | null;
191
201
  }
192
202
 
193
203
  export interface ResolvedScrubConfig {
204
+ markers: { radius: number } | null;
194
205
  tooltip: boolean;
195
206
  /** Opt-in per-series pill tooltip for LiveChartSeries; null keeps guide-only behavior. */
196
207
  seriesTooltip: ResolvedPerSeriesTooltipConfig | null;
@@ -508,6 +519,7 @@ const BADGE_DEFAULTS: ResolvedBadgeConfig = {
508
519
  variant: "default",
509
520
  tail: true,
510
521
  position: "right",
522
+ textAlign: "center",
511
523
  background: undefined,
512
524
  radius: undefined,
513
525
  borderColor: undefined,
@@ -531,7 +543,7 @@ export function resolveBadge(
531
543
  return resolveToggle(prop, BADGE_DEFAULTS, false);
532
544
  }
533
545
 
534
- const Y_AXIS_DEFAULTS: ResolvedYAxisConfig = {
546
+ const Y_AXIS_DEFAULTS: Omit<ResolvedYAxisConfig, "scaleGesture"> = {
535
547
  side: "right",
536
548
  minGap: 36,
537
549
  intervalScale: 1,
@@ -541,6 +553,23 @@ const Y_AXIS_DEFAULTS: ResolvedYAxisConfig = {
541
553
  float: false,
542
554
  };
543
555
 
556
+ /** Normalize the opt-in axis gesture; bounds only constrain gesture writes. */
557
+ export function resolveYAxisScaleGesture(
558
+ prop: boolean | YAxisScaleGestureConfig | undefined,
559
+ ): ResolvedYAxisScaleGestureConfig | null {
560
+ if (!prop) return null;
561
+ const config = prop === true ? {} : prop;
562
+ const positive = (value: number | undefined, fallback: number) =>
563
+ value !== undefined && Number.isFinite(value) && value > 0 ? value : fallback;
564
+ const minScale = positive(config.minScale, 0.25);
565
+ return {
566
+ minScale,
567
+ maxScale: Math.max(minScale, positive(config.maxScale, 10)),
568
+ dragDistance: positive(config.dragDistance, 160),
569
+ doubleTapReset: config.doubleTapReset ?? true,
570
+ };
571
+ }
572
+
544
573
  /**
545
574
  * Resolves `yAxis` prop to a fully-typed config or null (disabled).
546
575
  * `true` → defaults, object → merged with defaults, falsy → null.
@@ -554,6 +583,9 @@ export function resolveYAxis(
554
583
  if (resolved === null) return null;
555
584
  return {
556
585
  ...resolved,
586
+ scaleGesture: resolveYAxisScaleGesture(
587
+ typeof prop === "object" ? prop.scaleGesture : undefined,
588
+ ),
557
589
  count: Math.max(0, Math.floor(resolved.count)),
558
590
  intervalScale:
559
591
  Number.isFinite(resolved.intervalScale) && resolved.intervalScale > 0
@@ -726,6 +758,31 @@ export function resolveCandleGaps(
726
758
  };
727
759
  }
728
760
 
761
+ export interface ResolvedViewportConfig extends ChartViewportControl {
762
+ /** Fully resolved render-time option; shared values are kept by reference. */
763
+ windowSmoothing: boolean;
764
+ }
765
+
766
+ const VIEWPORT_DEFAULTS: Pick<ResolvedViewportConfig, "windowSmoothing"> = {
767
+ windowSmoothing: true,
768
+ };
769
+
770
+ /**
771
+ * Resolves the external viewport prop at render time: false/omitted → private
772
+ * state; an object → required shared values plus defaulted behavior options.
773
+ * Never reads or clones the shared values; they remain UI-thread inputs.
774
+ */
775
+ export function resolveViewport(
776
+ prop: false | ViewportConfig | undefined,
777
+ ): ResolvedViewportConfig | null {
778
+ if (prop === undefined || prop === false) return null;
779
+ return {
780
+ end: prop.end,
781
+ window: prop.window,
782
+ windowSmoothing: prop.windowSmoothing ?? VIEWPORT_DEFAULTS.windowSmoothing,
783
+ };
784
+ }
785
+
729
786
  export interface ResolvedZoomConfig {
730
787
  /** Tightest window (max zoom-in), seconds. `undefined` → `timeWindow / 8`. */
731
788
  minTimeWindow: number | undefined;
@@ -904,8 +961,12 @@ export function resolveAxisLabel(
904
961
 
905
962
  const X_AXIS_DEFAULTS: ResolvedXAxisConfig = {
906
963
  minGap: 60,
964
+ gridLines: null,
907
965
  };
908
966
 
967
+ /** `gridLines: true` overrides nothing, so the lines take the `gridStyle` look. */
968
+ const NO_GRID_STYLE_OVERRIDES: GridStyleConfig = {};
969
+
909
970
  /**
910
971
  * Resolves `xAxis` prop to a fully-typed config or null (disabled).
911
972
  * Defaults to enabled (`true`) so a bare `undefined` also returns the defaults.
@@ -913,10 +974,37 @@ const X_AXIS_DEFAULTS: ResolvedXAxisConfig = {
913
974
  export function resolveXAxis(
914
975
  prop: boolean | XAxisConfig | undefined,
915
976
  ): ResolvedXAxisConfig | null {
916
- return resolveToggle(prop, X_AXIS_DEFAULTS, true);
977
+ if (prop === false) return null;
978
+ if (prop == null || prop === true) return X_AXIS_DEFAULTS;
979
+ const { gridLines } = prop;
980
+ return {
981
+ minGap: prop.minGap ?? X_AXIS_DEFAULTS.minGap,
982
+ gridLines:
983
+ gridLines === true ? NO_GRID_STYLE_OVERRIDES : gridLines || null,
984
+ };
985
+ }
986
+
987
+ /**
988
+ * Resolves the vertical grid's style: `xAxis.gridLines` fields over the
989
+ * resolved `gridStyle`. Returns `base` itself when nothing is overridden, and
990
+ * null when the vertical grid is off.
991
+ */
992
+ export function resolveXAxisGridStyle(
993
+ gridLines: GridStyleConfig | null,
994
+ base: ResolvedGridStyleConfig,
995
+ ): ResolvedGridStyleConfig | null {
996
+ if (!gridLines) return null;
997
+ if (gridLines === NO_GRID_STYLE_OVERRIDES) return base;
998
+ return {
999
+ color: gridLines.color ?? base.color,
1000
+ strokeWidth: gridLines.strokeWidth ?? base.strokeWidth,
1001
+ intervals: gridLines.intervals ?? base.intervals,
1002
+ opacity: gridLines.opacity ?? base.opacity,
1003
+ };
917
1004
  }
918
1005
 
919
1006
  const SCRUB_DEFAULTS: ResolvedScrubConfig = {
1007
+ markers: null,
920
1008
  tooltip: true,
921
1009
  seriesTooltip: null,
922
1010
  dimTarget: "future",
@@ -981,12 +1069,15 @@ function resolvePerSeriesTooltip(
981
1069
  if (dash !== undefined) {
982
1070
  resolved.guideDashPattern = dash === true ? [3, 3] : dash || undefined;
983
1071
  }
984
- resolved.maxLabelChars = Math.max(1, Math.floor(resolved.maxLabelChars));
985
- resolved.bucketSeconds =
986
- resolved.bucketSeconds !== undefined && resolved.bucketSeconds > 0
1072
+ // Boolean defaults may already be serialized/frozen by an earlier chart's
1073
+ // worklet. Normalize a fresh object rather than mutating that shared config.
1074
+ return {
1075
+ ...resolved,
1076
+ maxLabelChars: Math.max(1, Math.floor(resolved.maxLabelChars)),
1077
+ bucketSeconds: resolved.bucketSeconds !== undefined && resolved.bucketSeconds > 0
987
1078
  ? resolved.bucketSeconds
988
- : undefined;
989
- return resolved;
1079
+ : undefined,
1080
+ };
990
1081
  }
991
1082
 
992
1083
  /**
@@ -1005,6 +1096,11 @@ export function resolveScrub(
1005
1096
  const seriesTooltip =
1006
1097
  typeof prop === "object" ? prop.seriesTooltip : undefined;
1007
1098
  resolved.seriesTooltip = resolvePerSeriesTooltip(seriesTooltip);
1099
+ const markers = typeof prop === "object" ? prop.markers : undefined;
1100
+ const radius = typeof markers === "object" ? markers.radius : undefined;
1101
+ resolved.markers = markers
1102
+ ? { radius: radius !== undefined && Number.isFinite(radius) ? Math.max(0, radius) : 16 }
1103
+ : null;
1008
1104
  // `resolveToggle` shallow-merges object props, so an explicitly undefined
1009
1105
  // optional field replaces its default. Restore the public defaults before
1010
1106
  // normalizing; otherwise the numeric clamps produce NaN and an undefined
@@ -39,8 +39,11 @@ import {
39
39
  } from "./historyRangeCache";
40
40
 
41
41
  import { useHistoryRevision } from "./useHistoryRevision";
42
+ import type { ResolvedViewportConfig } from "./resolveConfig";
42
43
 
43
44
  export interface EngineConfig {
45
+ /** External scroll/zoom values adopted in place of private gesture state. */
46
+ viewport?: ResolvedViewportConfig | null;
44
47
  /** Original inputs before a reveal/stash bridge that may suppress same-array notifications. */
45
48
  dataChangeSource?: SharedValue<LiveChartPoint[]>;
46
49
  candlesChangeSource?: SharedValue<CandlePoint[]>;
@@ -77,6 +80,7 @@ export interface EngineConfig {
77
80
  thresholdRangeExtendToNow?: boolean;
78
81
  nonNegative?: boolean;
79
82
  maxValue?: number;
83
+ minRange?: number;
80
84
  /** Positive, finite live Y-range multiplier (1 = auto-fit); read each frame. */
81
85
  yRangeScale?: SharedValue<number>;
82
86
  nowOverride?: number;
@@ -223,6 +227,8 @@ export interface MultiEngineState
223
227
  series: SharedValue<SeriesConfig[]>;
224
228
  displaySeriesValues: SharedValue<number[]>;
225
229
  seriesOpacities: SharedValue<number[]>;
230
+ /** Presented tip time, clamped to the viewport edge; absent uses timestamp. */
231
+ tipTime?: SharedValue<number>;
226
232
  }
227
233
 
228
234
  export type EngineState = SingleEngineState | MultiEngineState;
@@ -257,6 +263,7 @@ export interface EngineFrameRefs {
257
263
  thresholdRangeExtendToNow?: SharedValue<boolean>;
258
264
  nonNegativeSV?: SharedValue<boolean>;
259
265
  maxValueSV?: SharedValue<number | undefined>;
266
+ minRangeSV?: SharedValue<number | undefined>;
260
267
  yRangeScaleSV?: SharedValue<number>;
261
268
  nowOverrideSV?: SharedValue<number | undefined>;
262
269
  windowBufferSV?: SharedValue<number>;
@@ -271,6 +278,8 @@ export interface EngineFrameRefs {
271
278
  returnFromSV?: SharedValue<number>;
272
279
  /** Pinch-zoom window-width override (null = follow timeWindow). Optional for callers/tests. */
273
280
  viewWindowSV?: SharedValue<number | null>;
281
+ /** Whether a non-null window override eases (false copies a drawn width exactly). */
282
+ viewWindowSmoothingSV?: SharedValue<boolean>;
274
283
  /** Receives the computed live edge each frame. Optional for callers/tests. */
275
284
  liveEdgeSV?: SharedValue<number>;
276
285
  /** Receives the smoothed right-edge value each frame. Optional for callers/tests. */
@@ -402,6 +411,7 @@ export function applyLiveChartEngineFrame(
402
411
  input.thresholdRangeExtendToNow = sv.thresholdRangeExtendToNow?.value ?? true;
403
412
  input.nonNegative = sv.nonNegativeSV?.value ?? false;
404
413
  input.maxValue = sv.maxValueSV?.value;
414
+ input.minRange = sv.minRangeSV?.value;
405
415
  input.yRangeScale = sv.yRangeScaleSV?.value ?? 1;
406
416
  input.nowOverride = sv.nowOverrideSV?.value;
407
417
  input.windowBuffer = sv.windowBufferSV?.value ?? 0;
@@ -417,6 +427,7 @@ export function applyLiveChartEngineFrame(
417
427
  input.returnT = sv.returnTSV?.value;
418
428
  input.returnFrom = sv.returnFromSV?.value;
419
429
  input.viewWindow = sv.viewWindowSV?.value;
430
+ input.viewWindowSmoothing = sv.viewWindowSmoothingSV?.value ?? true;
420
431
  input.mode = sv.modeSV.value;
421
432
  input.candles = candleHistory?.data ?? sv.candles?.value;
422
433
  input.historyRevision =
@@ -457,6 +468,7 @@ export function useLiveChartEngine(
457
468
  config: EngineConfig,
458
469
  ): SingleEngineState & ChartEngineScroll & ChartEngineEdge & { wake: () => void } {
459
470
  const {
471
+ viewport,
460
472
  data,
461
473
  dataChangeSource = data,
462
474
  value,
@@ -473,6 +485,7 @@ export function useLiveChartEngine(
473
485
  thresholdRangeExtendToStart: configuredThresholdRangeExtendToStart,
474
486
  nonNegative,
475
487
  maxValue,
488
+ minRange,
476
489
  yRangeScale,
477
490
  nowOverride,
478
491
  windowBuffer,
@@ -499,14 +512,20 @@ export function useLiveChartEngine(
499
512
  // Pinch-zoom window-width override (null = follow the configured window).
500
513
  // Declared first so `timeWindow` below can fold it in. Defaults to null so
501
514
  // charts without `zoom` behave exactly as before.
502
- const viewWindow = useSharedValue<number | null>(null);
515
+ const internalViewWindow = useSharedValue<number | null>(null);
516
+ const viewWindow = viewport?.window ?? internalViewWindow;
517
+ const hasViewport = viewport != null;
518
+ const windowSmoothing = viewport?.windowSmoothing ?? true;
519
+ const viewWindowSmoothingSV = useDerivedValue(() => windowSmoothing);
503
520
  // A change to the `timeWindow` prop (a range / timeframe selector) is an explicit
504
521
  // request to set the window, so it clears any active pinch-zoom override —
505
522
  // otherwise the override below (`viewWindow ?? config.timeWindow`) would shadow
506
523
  // the new prop forever, and prop-driven window changes would silently no-op.
524
+ // An app-owned viewport keeps its override until the app/handle clears it.
507
525
  useEffect(() => {
526
+ if (hasViewport) return;
508
527
  viewWindow.set(null);
509
- }, [configuredTimeWindow, viewWindow]);
528
+ }, [configuredTimeWindow, viewWindow, hasViewport]);
510
529
 
511
530
  // Low-frequency config → UI thread via useDerivedValue. `timeWindow` is the
512
531
  // *effective* target window: the zoom override when set, else the prop. Both
@@ -553,6 +572,7 @@ export function useLiveChartEngine(
553
572
  );
554
573
  const nonNegativeSV = useDerivedValue(() => nonNegative ?? false);
555
574
  const maxValueSV = useDerivedValue(() => maxValue);
575
+ const minRangeSV = useDerivedValue(() => minRange);
556
576
  const nowOverrideSV = useDerivedValue(() => nowOverride);
557
577
  const windowBufferSV = useDerivedValue(() => windowBuffer ?? 0);
558
578
  const pausedSV = useDerivedValue(() => paused ?? false);
@@ -560,9 +580,9 @@ export function useLiveChartEngine(
560
580
  // (the tick no longer reads it — clearing `viewEnd` is what makes it follow).
561
581
  // Defaults to enabled so a caller that omits it behaves as before.
562
582
  const scrollEnabledSV = useDerivedValue(() => scrollEnabled ?? true);
563
- // Honor a viewEnd parked past the live edge (timeScroll.overscroll).
583
+ // External viewports can follow a pane whose forming bar ends past our live edge.
564
584
  const allowFutureViewEndSV = useDerivedValue(
565
- () => allowFutureViewEnd ?? false,
585
+ () => hasViewport || (allowFutureViewEnd ?? false),
566
586
  );
567
587
  // Return-to-live glide duration (ms); 0 = instant snap. Read by the reaction.
568
588
  const returnToLiveMsSV = useDerivedValue(
@@ -595,7 +615,8 @@ export function useLiveChartEngine(
595
615
  // edge at that absolute time. `liveEdge` mirrors the would-be-live timestamp
596
616
  // each frame so the gesture can clamp / detect catch-up. Both default to
597
617
  // "following" so charts without `timeScroll` behave exactly as before.
598
- const viewEnd = useSharedValue<number | null>(null);
618
+ const internalViewEnd = useSharedValue<number | null>(null);
619
+ const viewEnd = viewport?.end ?? internalViewEnd;
599
620
  const liveEdge = useSharedValue(initialTimestamp);
600
621
  const edgeValue = useSharedValue(0);
601
622
  // "Return to live" glide (see #164). When time-scroll is disabled while scrolled
@@ -670,6 +691,7 @@ export function useLiveChartEngine(
670
691
  thresholdRangeExtendToNow,
671
692
  nonNegativeSV,
672
693
  maxValueSV,
694
+ minRangeSV,
673
695
  yRangeScaleSV: yRangeScale,
674
696
  nowOverrideSV,
675
697
  windowBufferSV,
@@ -679,6 +701,7 @@ export function useLiveChartEngine(
679
701
  returnTSV: returnT,
680
702
  returnFromSV: returnFrom,
681
703
  viewWindowSV: viewWindow,
704
+ viewWindowSmoothingSV,
682
705
  liveEdgeSV: liveEdge,
683
706
  edgeValueSV: edgeValue,
684
707
  snapSV,
@@ -720,6 +743,7 @@ export function useLiveChartEngine(
720
743
  liveCandle,
721
744
  liveEdge,
722
745
  maxValueSV,
746
+ minRangeSV,
723
747
  modeSV,
724
748
  nonNegativeSV,
725
749
  nowOverrideSV,
@@ -739,6 +763,7 @@ export function useLiveChartEngine(
739
763
  value,
740
764
  viewEnd,
741
765
  viewWindow,
766
+ viewWindowSmoothingSV,
742
767
  windowBufferSV,
743
768
  yRangeScale,
744
769
  ],
@@ -791,15 +816,15 @@ export function useLiveChartEngine(
791
816
  canvasHeight.get(), timeWindow.get(), smoothing.get(), rangeAnimationSV.get(), adaptiveSpeedBoostSV.get(),
792
817
  exaggerateSV.get(), referenceValue.get(), referenceValues.get(), thresholdRangePoints.get(),
793
818
  thresholdRangeExtendToStart.get(), thresholdRangeExtendToNow.get(), nonNegativeSV.get(),
794
- maxValueSV.get(), yRangeScale?.get(), nowOverrideSV.get(), windowBufferSV.get(), pausedSV.get(),
795
- viewEnd.get(), viewWindow.get(), allowFutureViewEndSV.get(), returnT.get(), returnFrom.get(),
819
+ maxValueSV.get(), minRangeSV.get(), yRangeScale?.get(), nowOverrideSV.get(), windowBufferSV.get(), pausedSV.get(),
820
+ viewEnd.get(), viewWindow.get(), viewWindowSmoothingSV.get(), allowFutureViewEndSV.get(), returnT.get(), returnFrom.get(),
796
821
  snapSV.get(), modeSV.get(), candleGapsSV.get(), candleGapBridgeNoTradesSV.get(),
797
822
  candleGapBridgeUnavailableSV.get(), candleGapBridgeUnknownSV.get(), isFrameLoopActive?.get(),
798
823
  keepAwake?.get(), wakeSignal?.get()];
799
824
  }, [pointHistory, candleHistory, data, value, candles, liveCandle, canvasWidth, canvasHeight, timeWindow, smoothing, rangeAnimationSV,
800
825
  adaptiveSpeedBoostSV, exaggerateSV, referenceValue, referenceValues, thresholdRangePoints,
801
- thresholdRangeExtendToStart, thresholdRangeExtendToNow, nonNegativeSV, maxValueSV, yRangeScale,
802
- nowOverrideSV, windowBufferSV, pausedSV, viewEnd, viewWindow, allowFutureViewEndSV, returnT,
826
+ thresholdRangeExtendToStart, thresholdRangeExtendToNow, nonNegativeSV, maxValueSV, minRangeSV, yRangeScale,
827
+ nowOverrideSV, windowBufferSV, pausedSV, viewEnd, viewWindow, viewWindowSmoothingSV, allowFutureViewEndSV, returnT,
803
828
  returnFrom, snapSV, modeSV, candleGapsSV, candleGapBridgeNoTradesSV, candleGapBridgeUnavailableSV,
804
829
  candleGapBridgeUnknownSV, isFrameLoopActive, keepAwake, wakeSignal]);
805
830
 
@@ -835,6 +860,7 @@ export function useLiveChartEngine(
835
860
  () => scrollEnabledSV.value,
836
861
  /* istanbul ignore next -- Reanimated reaction driven by a prop→derived change; not exercised under the SharedValue mock (see the viewWindow-reset test note), verified in-app */
837
862
  (enabled, prev) => {
863
+ if (hasViewport) return;
838
864
  if (prev === true && !enabled && viewEnd.value != null) {
839
865
  const ms = returnToLiveMsSV.value;
840
866
  if (ms > 0) {
@@ -869,10 +895,20 @@ export function useLiveChartEngine(
869
895
  canvasWidth.get(),
870
896
  canvasHeight.get(),
871
897
  timeWindow.get(),
898
+ viewEnd.get(),
899
+ viewWindowSmoothingSV.get(),
900
+ // `nowOverride` sets the right edge and `smoothing` changes when
901
+ // `static` flips. Reading them here makes them inputs of this mapper,
902
+ // so a same-render prop change can't settle on their previous values.
903
+ nowOverrideSV.get(),
904
+ smoothing.get(),
872
905
  // Range props can arrive after the data shared value. Re-settle when
873
906
  // those bounds change too, rather than retaining the previous scale
874
907
  // until another data/layout update (static charts have no frame loop).
875
908
  maxValueSV.get(),
909
+ minRangeSV.get(),
910
+ nonNegativeSV.get(),
911
+ yRangeScale?.get(),
876
912
  referenceValue.get(),
877
913
  ...(referenceValues.get() ?? []),
878
914
  ].join(","),