react-native-livechart 4.25.0 → 4.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/dist/components/CustomReferenceLineOverlay.d.ts +8 -1
  2. package/dist/components/CustomReferenceLineOverlay.d.ts.map +1 -1
  3. package/dist/components/CustomTooltipOverlay.d.ts +3 -2
  4. package/dist/components/CustomTooltipOverlay.d.ts.map +1 -1
  5. package/dist/components/LiveChart.d.ts +1 -1
  6. package/dist/components/LiveChart.d.ts.map +1 -1
  7. package/dist/components/LiveChartSeries.d.ts.map +1 -1
  8. package/dist/components/ReferenceLineOverlay.d.ts +4 -0
  9. package/dist/components/ReferenceLineOverlay.d.ts.map +1 -1
  10. package/dist/components/ReferenceValueBadge.d.ts +15 -0
  11. package/dist/components/ReferenceValueBadge.d.ts.map +1 -0
  12. package/dist/components/XAxisOverlay.d.ts +17 -0
  13. package/dist/components/XAxisOverlay.d.ts.map +1 -1
  14. package/dist/core/liveChartEngineTick.d.ts +6 -1
  15. package/dist/core/liveChartEngineTick.d.ts.map +1 -1
  16. package/dist/core/liveChartSeriesEngineTick.d.ts +4 -1
  17. package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
  18. package/dist/core/resolveConfig.d.ts +28 -1
  19. package/dist/core/resolveConfig.d.ts.map +1 -1
  20. package/dist/core/useLiveChartEngine.d.ts +10 -1
  21. package/dist/core/useLiveChartEngine.d.ts.map +1 -1
  22. package/dist/core/useLiveChartSeriesEngine.d.ts +5 -1
  23. package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
  24. package/dist/draw/grid.d.ts +2 -2
  25. package/dist/draw/line.d.ts +15 -1
  26. package/dist/draw/line.d.ts.map +1 -1
  27. package/dist/hooks/crosshairShared.d.ts +24 -1
  28. package/dist/hooks/crosshairShared.d.ts.map +1 -1
  29. package/dist/hooks/referenceBadgeFont.d.ts +5 -0
  30. package/dist/hooks/referenceBadgeFont.d.ts.map +1 -0
  31. package/dist/hooks/resolveChartLayout.d.ts +8 -0
  32. package/dist/hooks/resolveChartLayout.d.ts.map +1 -1
  33. package/dist/hooks/useBadge.d.ts +16 -1
  34. package/dist/hooks/useBadge.d.ts.map +1 -1
  35. package/dist/hooks/useChartSkiaFont.d.ts +1 -0
  36. package/dist/hooks/useChartSkiaFont.d.ts.map +1 -1
  37. package/dist/hooks/useCrosshair.d.ts +7 -2
  38. package/dist/hooks/useCrosshair.d.ts.map +1 -1
  39. package/dist/hooks/useCrosshairSeries.d.ts +4 -1
  40. package/dist/hooks/useCrosshairSeries.d.ts.map +1 -1
  41. package/dist/hooks/useLatestCallback.d.ts +6 -0
  42. package/dist/hooks/useLatestCallback.d.ts.map +1 -0
  43. package/dist/hooks/useMarkers.d.ts.map +1 -1
  44. package/dist/hooks/usePanScroll.d.ts +3 -1
  45. package/dist/hooks/usePanScroll.d.ts.map +1 -1
  46. package/dist/hooks/usePinchZoom.d.ts.map +1 -1
  47. package/dist/hooks/useReferenceDrag.d.ts +23 -7
  48. package/dist/hooks/useReferenceDrag.d.ts.map +1 -1
  49. package/dist/hooks/useReferenceLine.d.ts +24 -12
  50. package/dist/hooks/useReferenceLine.d.ts.map +1 -1
  51. package/dist/hooks/useReferenceLineGrouping.d.ts +19 -0
  52. package/dist/hooks/useReferenceLineGrouping.d.ts.map +1 -0
  53. package/dist/hooks/useReferenceLinePress.d.ts +4 -2
  54. package/dist/hooks/useReferenceLinePress.d.ts.map +1 -1
  55. package/dist/hooks/useReferenceTagStack.d.ts +31 -0
  56. package/dist/hooks/useReferenceTagStack.d.ts.map +1 -0
  57. package/dist/hooks/useScrubMarkers.d.ts +12 -0
  58. package/dist/hooks/useScrubMarkers.d.ts.map +1 -0
  59. package/dist/hooks/useXAxis.d.ts +1 -1
  60. package/dist/hooks/useXAxis.d.ts.map +1 -1
  61. package/dist/hooks/useYAxisScaleGesture.d.ts +34 -0
  62. package/dist/hooks/useYAxisScaleGesture.d.ts.map +1 -0
  63. package/dist/index.d.ts +1 -1
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/math/axisBadgeLayout.d.ts +16 -0
  66. package/dist/math/axisBadgeLayout.d.ts.map +1 -0
  67. package/dist/math/markers.d.ts +3 -0
  68. package/dist/math/markers.d.ts.map +1 -1
  69. package/dist/math/range.d.ts +1 -1
  70. package/dist/math/range.d.ts.map +1 -1
  71. package/dist/math/rangeAnimation.d.ts +4 -0
  72. package/dist/math/rangeAnimation.d.ts.map +1 -0
  73. package/dist/math/referenceDrag.d.ts +17 -5
  74. package/dist/math/referenceDrag.d.ts.map +1 -1
  75. package/dist/math/referenceGroup.d.ts +2 -2
  76. package/dist/math/referenceTagStack.d.ts +36 -0
  77. package/dist/math/referenceTagStack.d.ts.map +1 -0
  78. package/dist/math/scrubMarkers.d.ts +12 -0
  79. package/dist/math/scrubMarkers.d.ts.map +1 -0
  80. package/dist/types.d.ts +240 -30
  81. package/dist/types.d.ts.map +1 -1
  82. package/package.json +1 -1
  83. package/src/components/CustomReferenceLineOverlay.tsx +50 -8
  84. package/src/components/CustomTooltipOverlay.tsx +5 -1
  85. package/src/components/LiveChart.tsx +563 -200
  86. package/src/components/LiveChartSeries.tsx +117 -13
  87. package/src/components/ReferenceLineOverlay.tsx +62 -26
  88. package/src/components/ReferenceValueBadge.tsx +102 -0
  89. package/src/components/XAxisOverlay.tsx +104 -1
  90. package/src/core/liveChartEngineTick.ts +66 -10
  91. package/src/core/liveChartSeriesEngineTick.ts +55 -5
  92. package/src/core/resolveConfig.ts +95 -2
  93. package/src/core/useLiveChartEngine.ts +53 -11
  94. package/src/core/useLiveChartSeriesEngine.ts +11 -1
  95. package/src/draw/grid.ts +2 -2
  96. package/src/draw/line.ts +23 -1
  97. package/src/hooks/crosshairShared.ts +85 -1
  98. package/src/hooks/referenceBadgeFont.ts +35 -0
  99. package/src/hooks/resolveChartLayout.ts +17 -0
  100. package/src/hooks/useBadge.ts +44 -5
  101. package/src/hooks/useChartSkiaFont.ts +1 -1
  102. package/src/hooks/useCrosshair.ts +446 -300
  103. package/src/hooks/useCrosshairSeries.ts +29 -10
  104. package/src/hooks/useLatestCallback.ts +15 -0
  105. package/src/hooks/useMarkers.ts +51 -39
  106. package/src/hooks/usePanScroll.ts +155 -127
  107. package/src/hooks/usePinchZoom.ts +84 -63
  108. package/src/hooks/useReferenceDrag.ts +395 -146
  109. package/src/hooks/useReferenceLine.ts +453 -277
  110. package/src/hooks/useReferenceLineGrouping.ts +72 -0
  111. package/src/hooks/useReferenceLinePress.ts +121 -53
  112. package/src/hooks/useReferenceTagStack.ts +81 -0
  113. package/src/hooks/useScrubMarkers.ts +79 -0
  114. package/src/hooks/useXAxis.ts +11 -2
  115. package/src/hooks/useYAxisScaleGesture.ts +263 -0
  116. package/src/index.ts +11 -0
  117. package/src/math/axisBadgeLayout.ts +37 -0
  118. package/src/math/markers.ts +28 -3
  119. package/src/math/range.ts +35 -0
  120. package/src/math/rangeAnimation.ts +28 -0
  121. package/src/math/referenceDrag.ts +21 -4
  122. package/src/math/referenceGroup.ts +2 -2
  123. package/src/math/referenceTagStack.ts +112 -0
  124. package/src/math/scrubMarkers.ts +55 -0
  125. package/src/types.ts +246 -30
@@ -23,6 +23,7 @@ import type {
23
23
  CandlePoint,
24
24
  LiveChartFrameStats,
25
25
  LiveChartPoint,
26
+ RangeAnimationConfig,
26
27
  SeriesConfig,
27
28
  } from "../types";
28
29
  import {
@@ -38,8 +39,11 @@ import {
38
39
  } from "./historyRangeCache";
39
40
 
40
41
  import { useHistoryRevision } from "./useHistoryRevision";
42
+ import type { ResolvedViewportConfig } from "./resolveConfig";
41
43
 
42
44
  export interface EngineConfig {
45
+ /** External scroll/zoom values adopted in place of private gesture state. */
46
+ viewport?: ResolvedViewportConfig | null;
43
47
  /** Original inputs before a reveal/stash bridge that may suppress same-array notifications. */
44
48
  dataChangeSource?: SharedValue<LiveChartPoint[]>;
45
49
  candlesChangeSource?: SharedValue<CandlePoint[]>;
@@ -47,6 +51,7 @@ export interface EngineConfig {
47
51
  value: SharedValue<number>;
48
52
  timeWindow: number;
49
53
  smoothing: number;
54
+ rangeAnimation?: RangeAnimationConfig;
50
55
  /** Extra catch-up speed added to `smoothing` when the live value lags. */
51
56
  adaptiveSpeedBoost?: number;
52
57
  exaggerate?: boolean;
@@ -75,6 +80,7 @@ export interface EngineConfig {
75
80
  thresholdRangeExtendToNow?: boolean;
76
81
  nonNegative?: boolean;
77
82
  maxValue?: number;
83
+ minRange?: number;
78
84
  /** Positive, finite live Y-range multiplier (1 = auto-fit); read each frame. */
79
85
  yRangeScale?: SharedValue<number>;
80
86
  nowOverride?: number;
@@ -244,6 +250,7 @@ export interface EngineFrameRefs {
244
250
  timestamp: SharedValue<number>;
245
251
  timeWindow: SharedValue<number>;
246
252
  smoothing: SharedValue<number>;
253
+ rangeAnimationSV?: SharedValue<RangeAnimationConfig | undefined>;
247
254
  adaptiveSpeedBoostSV?: SharedValue<number | undefined>;
248
255
  exaggerateSV: SharedValue<boolean>;
249
256
  referenceValue: SharedValue<number | undefined>;
@@ -254,6 +261,7 @@ export interface EngineFrameRefs {
254
261
  thresholdRangeExtendToNow?: SharedValue<boolean>;
255
262
  nonNegativeSV?: SharedValue<boolean>;
256
263
  maxValueSV?: SharedValue<number | undefined>;
264
+ minRangeSV?: SharedValue<number | undefined>;
257
265
  yRangeScaleSV?: SharedValue<number>;
258
266
  nowOverrideSV?: SharedValue<number | undefined>;
259
267
  windowBufferSV?: SharedValue<number>;
@@ -268,6 +276,8 @@ export interface EngineFrameRefs {
268
276
  returnFromSV?: SharedValue<number>;
269
277
  /** Pinch-zoom window-width override (null = follow timeWindow). Optional for callers/tests. */
270
278
  viewWindowSV?: SharedValue<number | null>;
279
+ /** Whether a non-null window override eases (false copies a drawn width exactly). */
280
+ viewWindowSmoothingSV?: SharedValue<boolean>;
271
281
  /** Receives the computed live edge each frame. Optional for callers/tests. */
272
282
  liveEdgeSV?: SharedValue<number>;
273
283
  /** Receives the smoothed right-edge value each frame. Optional for callers/tests. */
@@ -388,6 +398,7 @@ export function applyLiveChartEngineFrame(
388
398
  input.canvasHeight = sv.canvasHeight.value;
389
399
  input.timeWindow = sv.timeWindow.value;
390
400
  input.smoothing = sv.smoothing.value;
401
+ input.rangeAnimation = sv.rangeAnimationSV?.value;
391
402
  input.adaptiveSpeedBoost = sv.adaptiveSpeedBoostSV?.value;
392
403
  input.exaggerate = sv.exaggerateSV.value;
393
404
  input.referenceValue = sv.referenceValue.value;
@@ -398,6 +409,7 @@ export function applyLiveChartEngineFrame(
398
409
  input.thresholdRangeExtendToNow = sv.thresholdRangeExtendToNow?.value ?? true;
399
410
  input.nonNegative = sv.nonNegativeSV?.value ?? false;
400
411
  input.maxValue = sv.maxValueSV?.value;
412
+ input.minRange = sv.minRangeSV?.value;
401
413
  input.yRangeScale = sv.yRangeScaleSV?.value ?? 1;
402
414
  input.nowOverride = sv.nowOverrideSV?.value;
403
415
  input.windowBuffer = sv.windowBufferSV?.value ?? 0;
@@ -413,6 +425,7 @@ export function applyLiveChartEngineFrame(
413
425
  input.returnT = sv.returnTSV?.value;
414
426
  input.returnFrom = sv.returnFromSV?.value;
415
427
  input.viewWindow = sv.viewWindowSV?.value;
428
+ input.viewWindowSmoothing = sv.viewWindowSmoothingSV?.value ?? true;
416
429
  input.mode = sv.modeSV.value;
417
430
  input.candles = candleHistory?.data ?? sv.candles?.value;
418
431
  input.historyRevision =
@@ -453,11 +466,13 @@ export function useLiveChartEngine(
453
466
  config: EngineConfig,
454
467
  ): SingleEngineState & ChartEngineScroll & ChartEngineEdge & { wake: () => void } {
455
468
  const {
469
+ viewport,
456
470
  data,
457
471
  dataChangeSource = data,
458
472
  value,
459
473
  timeWindow: configuredTimeWindow,
460
474
  smoothing: configuredSmoothing,
475
+ rangeAnimation,
461
476
  adaptiveSpeedBoost,
462
477
  exaggerate,
463
478
  referenceValue: configuredReferenceValue,
@@ -468,6 +483,7 @@ export function useLiveChartEngine(
468
483
  thresholdRangeExtendToStart: configuredThresholdRangeExtendToStart,
469
484
  nonNegative,
470
485
  maxValue,
486
+ minRange,
471
487
  yRangeScale,
472
488
  nowOverride,
473
489
  windowBuffer,
@@ -494,14 +510,20 @@ export function useLiveChartEngine(
494
510
  // Pinch-zoom window-width override (null = follow the configured window).
495
511
  // Declared first so `timeWindow` below can fold it in. Defaults to null so
496
512
  // charts without `zoom` behave exactly as before.
497
- const viewWindow = useSharedValue<number | null>(null);
513
+ const internalViewWindow = useSharedValue<number | null>(null);
514
+ const viewWindow = viewport?.window ?? internalViewWindow;
515
+ const hasViewport = viewport != null;
516
+ const windowSmoothing = viewport?.windowSmoothing ?? true;
517
+ const viewWindowSmoothingSV = useDerivedValue(() => windowSmoothing);
498
518
  // A change to the `timeWindow` prop (a range / timeframe selector) is an explicit
499
519
  // request to set the window, so it clears any active pinch-zoom override —
500
520
  // otherwise the override below (`viewWindow ?? config.timeWindow`) would shadow
501
521
  // the new prop forever, and prop-driven window changes would silently no-op.
522
+ // An app-owned viewport keeps its override until the app/handle clears it.
502
523
  useEffect(() => {
524
+ if (hasViewport) return;
503
525
  viewWindow.set(null);
504
- }, [configuredTimeWindow, viewWindow]);
526
+ }, [configuredTimeWindow, viewWindow, hasViewport]);
505
527
 
506
528
  // Low-frequency config → UI thread via useDerivedValue. `timeWindow` is the
507
529
  // *effective* target window: the zoom override when set, else the prop. Both
@@ -513,6 +535,7 @@ export function useLiveChartEngine(
513
535
  // Static charts snap to their target in one tick (smoothing=1), so the single
514
536
  // settle reaction below produces the final state with no per-frame easing.
515
537
  const smoothing = useDerivedValue(() => (isStatic ? 1 : configuredSmoothing));
538
+ const rangeAnimationSV = useDerivedValue(() => rangeAnimation);
516
539
  const adaptiveSpeedBoostSV = useDerivedValue(() => adaptiveSpeedBoost);
517
540
  const exaggerateSV = useDerivedValue(() => exaggerate ?? false);
518
541
  const referenceValue = useDerivedValue(() => configuredReferenceValue);
@@ -547,6 +570,7 @@ export function useLiveChartEngine(
547
570
  );
548
571
  const nonNegativeSV = useDerivedValue(() => nonNegative ?? false);
549
572
  const maxValueSV = useDerivedValue(() => maxValue);
573
+ const minRangeSV = useDerivedValue(() => minRange);
550
574
  const nowOverrideSV = useDerivedValue(() => nowOverride);
551
575
  const windowBufferSV = useDerivedValue(() => windowBuffer ?? 0);
552
576
  const pausedSV = useDerivedValue(() => paused ?? false);
@@ -554,9 +578,9 @@ export function useLiveChartEngine(
554
578
  // (the tick no longer reads it — clearing `viewEnd` is what makes it follow).
555
579
  // Defaults to enabled so a caller that omits it behaves as before.
556
580
  const scrollEnabledSV = useDerivedValue(() => scrollEnabled ?? true);
557
- // Honor a viewEnd parked past the live edge (timeScroll.overscroll).
581
+ // External viewports can follow a pane whose forming bar ends past our live edge.
558
582
  const allowFutureViewEndSV = useDerivedValue(
559
- () => allowFutureViewEnd ?? false,
583
+ () => hasViewport || (allowFutureViewEnd ?? false),
560
584
  );
561
585
  // Return-to-live glide duration (ms); 0 = instant snap. Read by the reaction.
562
586
  const returnToLiveMsSV = useDerivedValue(
@@ -589,7 +613,8 @@ export function useLiveChartEngine(
589
613
  // edge at that absolute time. `liveEdge` mirrors the would-be-live timestamp
590
614
  // each frame so the gesture can clamp / detect catch-up. Both default to
591
615
  // "following" so charts without `timeScroll` behave exactly as before.
592
- const viewEnd = useSharedValue<number | null>(null);
616
+ const internalViewEnd = useSharedValue<number | null>(null);
617
+ const viewEnd = viewport?.end ?? internalViewEnd;
593
618
  const liveEdge = useSharedValue(initialTimestamp);
594
619
  const edgeValue = useSharedValue(0);
595
620
  // "Return to live" glide (see #164). When time-scroll is disabled while scrolled
@@ -654,6 +679,7 @@ export function useLiveChartEngine(
654
679
  canvasHeight,
655
680
  timeWindow,
656
681
  smoothing,
682
+ rangeAnimationSV,
657
683
  adaptiveSpeedBoostSV,
658
684
  exaggerateSV,
659
685
  referenceValue,
@@ -663,6 +689,7 @@ export function useLiveChartEngine(
663
689
  thresholdRangeExtendToNow,
664
690
  nonNegativeSV,
665
691
  maxValueSV,
692
+ minRangeSV,
666
693
  yRangeScaleSV: yRangeScale,
667
694
  nowOverrideSV,
668
695
  windowBufferSV,
@@ -672,6 +699,7 @@ export function useLiveChartEngine(
672
699
  returnTSV: returnT,
673
700
  returnFromSV: returnFrom,
674
701
  viewWindowSV: viewWindow,
702
+ viewWindowSmoothingSV,
675
703
  liveEdgeSV: liveEdge,
676
704
  edgeValueSV: edgeValue,
677
705
  snapSV,
@@ -713,6 +741,7 @@ export function useLiveChartEngine(
713
741
  liveCandle,
714
742
  liveEdge,
715
743
  maxValueSV,
744
+ minRangeSV,
716
745
  modeSV,
717
746
  nonNegativeSV,
718
747
  nowOverrideSV,
@@ -722,6 +751,7 @@ export function useLiveChartEngine(
722
751
  returnFrom,
723
752
  returnT,
724
753
  smoothing,
754
+ rangeAnimationSV,
725
755
  snapSV,
726
756
  thresholdRangeExtendToNow,
727
757
  thresholdRangeExtendToStart,
@@ -731,6 +761,7 @@ export function useLiveChartEngine(
731
761
  value,
732
762
  viewEnd,
733
763
  viewWindow,
764
+ viewWindowSmoothingSV,
734
765
  windowBufferSV,
735
766
  yRangeScale,
736
767
  ],
@@ -780,18 +811,18 @@ export function useLiveChartEngine(
780
811
  // History revisions also notify when a reveal bridge suppresses a same-array
781
812
  // source update. A sleeping engine must wake to consume that invalidation.
782
813
  return [pointHistory.get(), candleHistory.get(), data.get(), value.get(), candles?.get(), liveCandle?.get(), canvasWidth.get(),
783
- canvasHeight.get(), timeWindow.get(), smoothing.get(), adaptiveSpeedBoostSV.get(),
814
+ canvasHeight.get(), timeWindow.get(), smoothing.get(), rangeAnimationSV.get(), adaptiveSpeedBoostSV.get(),
784
815
  exaggerateSV.get(), referenceValue.get(), referenceValues.get(), thresholdRangePoints.get(),
785
816
  thresholdRangeExtendToStart.get(), thresholdRangeExtendToNow.get(), nonNegativeSV.get(),
786
- maxValueSV.get(), yRangeScale?.get(), nowOverrideSV.get(), windowBufferSV.get(), pausedSV.get(),
787
- viewEnd.get(), viewWindow.get(), allowFutureViewEndSV.get(), returnT.get(), returnFrom.get(),
817
+ maxValueSV.get(), minRangeSV.get(), yRangeScale?.get(), nowOverrideSV.get(), windowBufferSV.get(), pausedSV.get(),
818
+ viewEnd.get(), viewWindow.get(), viewWindowSmoothingSV.get(), allowFutureViewEndSV.get(), returnT.get(), returnFrom.get(),
788
819
  snapSV.get(), modeSV.get(), candleGapsSV.get(), candleGapBridgeNoTradesSV.get(),
789
820
  candleGapBridgeUnavailableSV.get(), candleGapBridgeUnknownSV.get(), isFrameLoopActive?.get(),
790
821
  keepAwake?.get(), wakeSignal?.get()];
791
- }, [pointHistory, candleHistory, data, value, candles, liveCandle, canvasWidth, canvasHeight, timeWindow, smoothing,
822
+ }, [pointHistory, candleHistory, data, value, candles, liveCandle, canvasWidth, canvasHeight, timeWindow, smoothing, rangeAnimationSV,
792
823
  adaptiveSpeedBoostSV, exaggerateSV, referenceValue, referenceValues, thresholdRangePoints,
793
- thresholdRangeExtendToStart, thresholdRangeExtendToNow, nonNegativeSV, maxValueSV, yRangeScale,
794
- nowOverrideSV, windowBufferSV, pausedSV, viewEnd, viewWindow, allowFutureViewEndSV, returnT,
824
+ thresholdRangeExtendToStart, thresholdRangeExtendToNow, nonNegativeSV, maxValueSV, minRangeSV, yRangeScale,
825
+ nowOverrideSV, windowBufferSV, pausedSV, viewEnd, viewWindow, viewWindowSmoothingSV, allowFutureViewEndSV, returnT,
795
826
  returnFrom, snapSV, modeSV, candleGapsSV, candleGapBridgeNoTradesSV, candleGapBridgeUnavailableSV,
796
827
  candleGapBridgeUnknownSV, isFrameLoopActive, keepAwake, wakeSignal]);
797
828
 
@@ -827,6 +858,7 @@ export function useLiveChartEngine(
827
858
  () => scrollEnabledSV.value,
828
859
  /* 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 */
829
860
  (enabled, prev) => {
861
+ if (hasViewport) return;
830
862
  if (prev === true && !enabled && viewEnd.value != null) {
831
863
  const ms = returnToLiveMsSV.value;
832
864
  if (ms > 0) {
@@ -861,10 +893,20 @@ export function useLiveChartEngine(
861
893
  canvasWidth.get(),
862
894
  canvasHeight.get(),
863
895
  timeWindow.get(),
896
+ viewEnd.get(),
897
+ viewWindowSmoothingSV.get(),
898
+ // `nowOverride` sets the right edge and `smoothing` changes when
899
+ // `static` flips. Reading them here makes them inputs of this mapper,
900
+ // so a same-render prop change can't settle on their previous values.
901
+ nowOverrideSV.get(),
902
+ smoothing.get(),
864
903
  // Range props can arrive after the data shared value. Re-settle when
865
904
  // those bounds change too, rather than retaining the previous scale
866
905
  // until another data/layout update (static charts have no frame loop).
867
906
  maxValueSV.get(),
907
+ minRangeSV.get(),
908
+ nonNegativeSV.get(),
909
+ yRangeScale?.get(),
868
910
  referenceValue.get(),
869
911
  ...(referenceValues.get() ?? []),
870
912
  ].join(","),
@@ -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, SeriesConfig } from "../types";
13
+ import type { LiveChartPoint, RangeAnimationConfig, SeriesConfig } from "../types";
14
14
  import {
15
15
  tickLiveChartSeriesEngineFrame,
16
16
  type MultiEngineTickInput,
@@ -22,6 +22,7 @@ export interface MultiSeriesEngineConfig {
22
22
  series: SharedValue<SeriesConfig[]>;
23
23
  timeWindow: number;
24
24
  smoothing: number;
25
+ rangeAnimation?: RangeAnimationConfig;
25
26
  /** Extra catch-up speed added to `smoothing` when a series tip lags. */
26
27
  adaptiveSpeedBoost?: number;
27
28
  exaggerate?: boolean;
@@ -29,6 +30,7 @@ export interface MultiSeriesEngineConfig {
29
30
  referenceValues?: number[];
30
31
  nonNegative?: boolean;
31
32
  maxValue?: number;
33
+ minRange?: number;
32
34
  /** Positive, finite live Y-range multiplier (1 = auto-fit); read each frame. */
33
35
  yRangeScale?: SharedValue<number>;
34
36
  nowOverride?: number;
@@ -76,12 +78,14 @@ export interface MultiEngineFrameRefs {
76
78
  canvasHeight: SharedValue<number>;
77
79
  timeWindow: SharedValue<number>;
78
80
  smoothing: SharedValue<number>;
81
+ rangeAnimationSV?: SharedValue<RangeAnimationConfig | undefined>;
79
82
  adaptiveSpeedBoostSV?: SharedValue<number | undefined>;
80
83
  exaggerateSV: SharedValue<boolean>;
81
84
  referenceValue: SharedValue<number | undefined>;
82
85
  referenceValues?: SharedValue<number[] | undefined>;
83
86
  nonNegativeSV?: SharedValue<boolean>;
84
87
  maxValueSV?: SharedValue<number | undefined>;
88
+ minRangeSV?: SharedValue<number | undefined>;
85
89
  yRangeScaleSV?: SharedValue<number>;
86
90
  nowOverrideSV?: SharedValue<number | undefined>;
87
91
  windowBufferSV?: SharedValue<number>;
@@ -240,12 +244,14 @@ export function applyLiveChartSeriesEngineFrame(
240
244
  input.canvasHeight = sv.canvasHeight.value;
241
245
  input.timeWindow = sv.timeWindow.value;
242
246
  input.smoothing = sv.smoothing.value;
247
+ input.rangeAnimation = sv.rangeAnimationSV?.value;
243
248
  input.adaptiveSpeedBoost = sv.adaptiveSpeedBoostSV?.value;
244
249
  input.exaggerate = sv.exaggerateSV.value;
245
250
  input.referenceValue = sv.referenceValue.value;
246
251
  input.referenceValues = sv.referenceValues?.value;
247
252
  input.nonNegative = sv.nonNegativeSV?.value ?? false;
248
253
  input.maxValue = sv.maxValueSV?.value;
254
+ input.minRange = sv.minRangeSV?.value;
249
255
  input.yRangeScale = sv.yRangeScaleSV?.value ?? 1;
250
256
  input.nowOverride = sv.nowOverrideSV?.value;
251
257
  input.windowBuffer = sv.windowBufferSV?.value ?? 0;
@@ -301,12 +307,14 @@ export function useLiveChartSeriesEngine(
301
307
  const viewWindow = useSharedValue<number | null>(null);
302
308
  const timeWindow = useDerivedValue(() => viewWindow.value ?? config.timeWindow);
303
309
  const smoothing = useDerivedValue(() => config.smoothing);
310
+ const rangeAnimationSV = useDerivedValue(() => config.rangeAnimation);
304
311
  const adaptiveSpeedBoostSV = useDerivedValue(() => config.adaptiveSpeedBoost);
305
312
  const exaggerateSV = useDerivedValue(() => config.exaggerate ?? false);
306
313
  const referenceValue = useDerivedValue(() => config.referenceValue);
307
314
  const referenceValues = useDerivedValue(() => config.referenceValues);
308
315
  const nonNegativeSV = useDerivedValue(() => config.nonNegative ?? false);
309
316
  const maxValueSV = useDerivedValue(() => config.maxValue);
317
+ const minRangeSV = useDerivedValue(() => config.minRange);
310
318
  const nowOverrideSV = useDerivedValue(() => config.nowOverride);
311
319
  const windowBufferSV = useDerivedValue(() => config.windowBuffer ?? 0);
312
320
  const pausedSV = useDerivedValue(() => config.paused ?? false);
@@ -388,12 +396,14 @@ export function useLiveChartSeriesEngine(
388
396
  canvasHeight,
389
397
  timeWindow,
390
398
  smoothing,
399
+ rangeAnimationSV,
391
400
  adaptiveSpeedBoostSV,
392
401
  exaggerateSV,
393
402
  referenceValue,
394
403
  referenceValues,
395
404
  nonNegativeSV,
396
405
  maxValueSV,
406
+ minRangeSV,
397
407
  yRangeScaleSV: config.yRangeScale,
398
408
  nowOverrideSV,
399
409
  windowBufferSV,
package/src/draw/grid.ts CHANGED
@@ -19,8 +19,8 @@ export interface RightAnchoredYAxisColumnLayout {
19
19
 
20
20
  /**
21
21
  * Measure the widest Y-axis label and anchor the shared left-aligned column to
22
- * a fixed canvas-edge margin. Shared by the axis and reference-line worklets so
23
- * their right edges cannot drift apart.
22
+ * a fixed canvas-edge margin. Shared by the axis, reference-line and live-badge
23
+ * worklets so their edges cannot drift apart.
24
24
  */
25
25
  export function rightAnchoredYAxisColumnLayout(
26
26
  canvasWidth: number,
package/src/draw/line.ts CHANGED
@@ -44,8 +44,10 @@ export function badgeTailAndCap(
44
44
  /**
45
45
  * Text left-edge X so the label is horizontally centered in the badge pill.
46
46
  * Uses the ASYMMETRIC layout: tail gap (`tl`) on the left, `BADGE_MARGIN_RIGHT` on
47
- * the right. Both `useBadge` and `GridOverlay` (when badge is shown) call this so
47
+ * the right. Both `useBadge` and `YAxisOverlay` (when badge is shown) call this so
48
48
  * the badge text and y-axis labels share the exact same horizontal position.
49
+ * With `yAxis.labelRightMargin` the labels use `rightAnchoredYAxisColumnLayout`
50
+ * instead, and so does the badge text with `badge.textAlign: "yAxisColumn"`.
49
51
  *
50
52
  * Layout: |dot| tl |PAD_X| text |PAD_X| BADGE_MARGIN_RIGHT |canvas edge
51
53
  * ↑ same x for grid labels and badge text
@@ -215,6 +217,26 @@ export function resolvePadding(
215
217
  };
216
218
  }
217
219
 
220
+ /**
221
+ * Clip rect for the series layers (line, fill, candles, gap bridges): the plot's
222
+ * vertical extent, so a zoomed-in `yRangeScale` can't draw over the time axis.
223
+ * Horizontally it reaches a canvas width past each edge so the left-edge entry
224
+ * and the degen shake stay unclipped.
225
+ */
226
+ export function seriesPlotClip(
227
+ padding: ChartPadding,
228
+ canvasWidth: number,
229
+ canvasHeight: number,
230
+ ): { x: number; y: number; width: number; height: number } {
231
+ "worklet";
232
+ return {
233
+ x: -canvasWidth,
234
+ y: padding.top,
235
+ width: canvasWidth * 3,
236
+ height: Math.max(0, canvasHeight - padding.top - padding.bottom),
237
+ };
238
+ }
239
+
218
240
  /**
219
241
  * Build screen-space points as a flat number array [x0, y0, x1, y1, ...].
220
242
  * Includes one point before the window for smooth left-edge entry,
@@ -10,7 +10,7 @@ import {
10
10
  pickCandleGapAtTime,
11
11
  } from "../math/candleGaps";
12
12
  import { pickCandleAtTime } from "../math/pickCandle";
13
- import type { CandleGap, CandlePoint } from "../types";
13
+ import type { CandleGap, CandlePoint, Marker } from "../types";
14
14
 
15
15
  const TOOLTIP_PAD_X = 8;
16
16
  const TOOLTIP_PAD_Y = 6;
@@ -177,6 +177,7 @@ export const HIDDEN_TOOLTIP: TooltipLayout = {
177
177
  };
178
178
 
179
179
  export interface CrosshairState {
180
+ scrubMarkers: SharedValue<Marker[]>;
180
181
  scrubX: SharedValue<number>;
181
182
  scrubActive: SharedValue<boolean>;
182
183
  scrubTime: SharedValue<number>;
@@ -244,6 +245,35 @@ export function computeScrubDotY(
244
245
  return padTop + ((displayMax - value) / valRange) * chartH;
245
246
  }
246
247
 
248
+ /**
249
+ * A reference value's canvas Y pinned to the plot: a value off the visible range
250
+ * sits on the nearest plot edge. `-1` when there is no plot height (not laid out,
251
+ * or shorter than its padding) — decided from the layout, not from the projected
252
+ * Y: {@link computeScrubDotY} returns a negative Y for a value far above the range
253
+ * too, and that one must pin to the top edge as a value below pins to the bottom.
254
+ */
255
+ export function pinnedPlotY(
256
+ value: number,
257
+ displayMin: number,
258
+ displayMax: number,
259
+ canvasHeight: number,
260
+ padTop: number,
261
+ padBottom: number,
262
+ ): number {
263
+ "worklet";
264
+ const bottom = canvasHeight - padBottom;
265
+ if (bottom - padTop <= 0) return -1;
266
+ const y = computeScrubDotY(
267
+ value,
268
+ displayMin,
269
+ displayMax,
270
+ canvasHeight,
271
+ padTop,
272
+ padBottom,
273
+ );
274
+ return Math.min(bottom, Math.max(padTop, y));
275
+ }
276
+
247
277
  /**
248
278
  * Inverse of {@link computeScrubDotY}: maps a canvas Y pixel back to a value (a
249
279
  * free price *level*, used by scrub-action mode where the reticle Y is the chosen
@@ -277,6 +307,60 @@ export function snapPrice(price: number, increment?: number): number {
277
307
  return Math.round(price / increment) * increment;
278
308
  }
279
309
 
310
+ /** What `Math.round(price / increment) * increment` can be off by at this price
311
+ * in double precision. */
312
+ function roundingNoise(increment: number, price: number): number {
313
+ "worklet";
314
+ return Math.max(increment * 1e-9, Math.abs(price) * 4 * Number.EPSILON);
315
+ }
316
+
317
+ /**
318
+ * {@link snapPrice} for a price inside `[min, max]` that should stay there: when
319
+ * rounding alone would leave the range, it rounds one `increment` inward instead
320
+ * (if that is still inside). A drag held at the plot's edge maps to exactly
321
+ * `max` / `min`, which plain rounding pushes just off the plot half the time.
322
+ */
323
+ export function snapPriceWithin(
324
+ price: number,
325
+ increment: number | undefined,
326
+ min: number,
327
+ max: number,
328
+ ): number {
329
+ "worklet";
330
+ const snapped = snapPrice(price, increment);
331
+ if (!increment || increment <= 0) return snapped;
332
+ // Past an edge by float noise alone (90.05 rounds to 90.05000000000001): the
333
+ // edge is that grid value, and it stays on the plot.
334
+ if (snapped > max) {
335
+ if (snapped - max <= roundingNoise(increment, max)) return max;
336
+ if (snapped - increment >= min) return snapped - increment;
337
+ } else if (snapped < min) {
338
+ if (min - snapped <= roundingNoise(increment, min)) return min;
339
+ if (snapped + increment <= max) return snapped + increment;
340
+ }
341
+ return snapped;
342
+ }
343
+
344
+ /**
345
+ * {@link snapPrice} that rounds away from the range instead of to the nearest
346
+ * increment: up for `side` `1`, down for `-1`, nearest for `0`. A drag past the
347
+ * plot's edge asks for a price beyond it, and a coarse `snap` rounded back
348
+ * inside would leave the range nothing to widen to.
349
+ */
350
+ export function snapPriceOutward(
351
+ price: number,
352
+ increment: number | undefined,
353
+ side: -1 | 0 | 1,
354
+ ): number {
355
+ "worklet";
356
+ const snapped = snapPrice(price, increment);
357
+ if (!increment || increment <= 0 || side === 0) return snapped;
358
+ const noise = roundingNoise(increment, price);
359
+ if (side > 0 && price - snapped > noise) return snapped + increment;
360
+ if (side < 0 && snapped - price > noise) return snapped - increment;
361
+ return snapped;
362
+ }
363
+
280
364
  /**
281
365
  * Maps a scrub X position to a window timestamp.
282
366
  * Returns -1 when inactive or when the canvas is not yet laid out.
@@ -0,0 +1,35 @@
1
+ import { matchFont, Skia, type SkFont } from "@shopify/react-native-skia";
2
+ import { resolveFontConfig } from "../core/resolveConfig";
3
+ import { MONO_FONT_FAMILY } from "../lib/monoFontFamily";
4
+ import type { BadgeStyleConfig, FontConfig } from "../types";
5
+ import { matchSystemFont } from "./useChartSkiaFont";
6
+
7
+ /** Resolve the same font for a rendered pill and its hit target, on the JS thread. */
8
+ export function referenceBadgeFont(
9
+ base: SkFont,
10
+ prop: FontConfig | undefined,
11
+ style: BadgeStyleConfig | undefined,
12
+ ): SkFont {
13
+ if (
14
+ style?.fontSize == null &&
15
+ style?.fontFamily == null &&
16
+ style?.fontWeight == null
17
+ )
18
+ return base;
19
+ const config = {
20
+ ...prop,
21
+ fontSize: style.fontSize ?? prop?.fontSize,
22
+ fontFamily: style.fontFamily ?? prop?.fontFamily,
23
+ fontWeight: style.fontWeight ?? prop?.fontWeight,
24
+ };
25
+ const { fontSize, fontFamily, fontWeight } = resolveFontConfig(
26
+ config,
27
+ MONO_FONT_FAMILY,
28
+ base.getSize(),
29
+ );
30
+ if (prop?.typeface)
31
+ return Skia.Font(base.getTypeface() ?? undefined, fontSize);
32
+ return prop?.fontManager
33
+ ? matchFont({ fontSize, fontFamily, fontWeight }, prop.fontManager)
34
+ : matchSystemFont(fontFamily, fontSize, fontWeight);
35
+ }
@@ -70,6 +70,23 @@ export interface ChartLayoutResult {
70
70
  padding: ChartPadding;
71
71
  }
72
72
 
73
+ /**
74
+ * Whether a live value should replace `sampled` (`0` = nothing sampled yet) as
75
+ * the `currentValue` the right gutter is measured from. Skips `0` and
76
+ * non-finite placeholders, then waits for a full order-of-magnitude move: the
77
+ * measured samples already span `v / 100` to `v * 10`, and ticks near a power
78
+ * of ten don't re-measure back and forth.
79
+ */
80
+ export function shouldResampleLayoutValue(
81
+ next: number,
82
+ sampled: number,
83
+ ): boolean {
84
+ "worklet";
85
+ if (next === 0 || !Number.isFinite(next)) return false;
86
+ if (sampled === 0) return true;
87
+ return Math.abs(Math.log10(Math.abs(next / sampled))) >= 1;
88
+ }
89
+
73
90
  /** Right inset (px) for a floating y-axis — just keeps the plot off the edge. */
74
91
  const FLOAT_AXIS_RIGHT_INSET = 6;
75
92
 
@@ -15,11 +15,13 @@ import {
15
15
  type TextWidthCache,
16
16
  } from "../lib/measureFontTextWidth";
17
17
  import type { ChartEngineWithLiveValue } from "../core/useLiveChartEngine";
18
+ import { rightAnchoredYAxisColumnLayout, type YAxisEntry } from "../draw/grid";
18
19
  import {
19
20
  badgeTailAndCap,
20
21
  pillTextLeftX,
21
22
  type ChartPadding,
22
23
  } from "../draw/line";
24
+ import { axisBadgeBounds } from "../math/axisBadgeLayout";
23
25
  import { hexToRgb, lerpColor } from "../math/color";
24
26
  import { lerp } from "../math/lerp";
25
27
  import type {
@@ -64,6 +66,20 @@ export function useBadge(
64
66
  radius?: number,
65
67
  /** Label text color override; falls back to the variant/theme rule. */
66
68
  textColorOverride?: string,
69
+ /**
70
+ * Y-axis label entries. With {@link labelRightMargin}, the right-gutter
71
+ * badge's value lines up with the Y-axis's right-anchored label column
72
+ * instead of centering in the pill body (`BadgeConfig.textAlign`).
73
+ */
74
+ yAxisEntries?: SharedValue<YAxisEntry[]>,
75
+ /**
76
+ * Matches {@link YAxisConfig.labelRightMargin}. Pass it (and the entries)
77
+ * only when `textAlign` is `"yAxisColumn"` and the labels use the
78
+ * right-anchored column, so other charts get no extra mapper input.
79
+ */
80
+ labelRightMargin?: number,
81
+ /** Font the Y-axis labels are measured with; a badge font override must not move the column. */
82
+ yAxisFont: SkFont = font,
67
83
  ) {
68
84
  const colorR = useSharedValue(0);
69
85
  const colorG = useSharedValue(0);
@@ -123,8 +139,9 @@ export function useBadge(
123
139
  // floating over the full-width plot (no reserved gutter). Its pill bg keeps
124
140
  // the live value readable over the candles.
125
141
  const pillW = 2 * badgeMetrics.padX + textW;
126
- const bodyRight = w - badgeMetrics.marginEdge;
127
- const bodyLeft = bodyRight - pillW;
142
+ const { left: bodyLeft, right: bodyRight } = axisBadgeBounds(
143
+ w, padding.right, textW, font.getSize(), { float: true, metrics: badgeMetrics },
144
+ );
128
145
  textX = (bodyLeft + bodyRight - textW) / 2;
129
146
  b.addRRect({
130
147
  rect: { x: bodyLeft, y: badgeY, width: pillW, height: pillH },
@@ -147,10 +164,11 @@ export function useBadge(
147
164
  } else {
148
165
  // Right-gutter badge (default): asymmetric layout with optional tail.
149
166
  const tl = badgeTailAndCap(font.getSize(), showTail, badgeMetrics);
150
- const bodyLeft = w - padding.right + badgeMetrics.dotGap + tl;
151
- const bodyRight = w - badgeMetrics.marginEdge;
167
+ const { left: bodyLeft, right: bodyRight } = axisBadgeBounds(
168
+ w, padding.right, textW, font.getSize(), { showTail, metrics: badgeMetrics },
169
+ );
152
170
  const pillW = bodyRight - bodyLeft;
153
- // Text centered in pill body — same formula used by GridOverlay.
171
+ // Text centered in pill body — same formula used by YAxisOverlay.
154
172
  textX = pillTextLeftX(
155
173
  w,
156
174
  padding.right,
@@ -158,6 +176,27 @@ export function useBadge(
158
176
  textW,
159
177
  badgeMetrics,
160
178
  );
179
+ // textAlign "yAxisColumn": the range the value may take inside the
180
+ // pill's horizontal padding. When it doesn't fit there, it stays centered.
181
+ const minTextX = bodyLeft + badgeMetrics.padX;
182
+ const maxTextX = bodyRight - badgeMetrics.padX - textW;
183
+ if (
184
+ yAxisEntries !== undefined &&
185
+ labelRightMargin !== undefined &&
186
+ minTextX <= maxTextX
187
+ ) {
188
+ // Start at the labels' shared left X; a value wider than every label
189
+ // ends at the column's right edge instead. Kept inside the padding, so
190
+ // the alignment gives way where the two disagree.
191
+ const { labelX } = rightAnchoredYAxisColumnLayout(
192
+ w,
193
+ yAxisEntries.get(),
194
+ yAxisFont,
195
+ labelRightMargin,
196
+ );
197
+ const columnX = Math.min(labelX, w - labelRightMargin - textW);
198
+ textX = Math.min(Math.max(columnX, minTextX), maxTextX);
199
+ }
161
200
 
162
201
  if (showTail) {
163
202
  const badgeX = w - padding.right + badgeMetrics.dotGap;
@@ -21,7 +21,7 @@ import type { FontConfig } from "../types";
21
21
  const systemFontCache = new Map<string, SkFont>();
22
22
  let systemFontMgr: SkFontMgr | null = null;
23
23
 
24
- function matchSystemFont(
24
+ export function matchSystemFont(
25
25
  fontFamily: string,
26
26
  fontSize: number,
27
27
  fontWeight: NonNullable<FontConfig["fontWeight"]>,