react-native-livechart 4.26.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 (115) 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 +4 -0
  15. package/dist/core/liveChartEngineTick.d.ts.map +1 -1
  16. package/dist/core/liveChartSeriesEngineTick.d.ts +2 -0
  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 +7 -0
  21. package/dist/core/useLiveChartEngine.d.ts.map +1 -1
  22. package/dist/core/useLiveChartSeriesEngine.d.ts +2 -0
  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 +16 -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 +20 -5
  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/useReferenceLinePress.d.ts +4 -2
  52. package/dist/hooks/useReferenceLinePress.d.ts.map +1 -1
  53. package/dist/hooks/useReferenceTagStack.d.ts +31 -0
  54. package/dist/hooks/useReferenceTagStack.d.ts.map +1 -0
  55. package/dist/hooks/useScrubMarkers.d.ts +12 -0
  56. package/dist/hooks/useScrubMarkers.d.ts.map +1 -0
  57. package/dist/hooks/useXAxis.d.ts +1 -1
  58. package/dist/hooks/useXAxis.d.ts.map +1 -1
  59. package/dist/hooks/useYAxisScaleGesture.d.ts +34 -0
  60. package/dist/hooks/useYAxisScaleGesture.d.ts.map +1 -0
  61. package/dist/index.d.ts +1 -1
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/math/axisBadgeLayout.d.ts +16 -0
  64. package/dist/math/axisBadgeLayout.d.ts.map +1 -0
  65. package/dist/math/markers.d.ts +3 -0
  66. package/dist/math/markers.d.ts.map +1 -1
  67. package/dist/math/range.d.ts +1 -1
  68. package/dist/math/range.d.ts.map +1 -1
  69. package/dist/math/referenceTagStack.d.ts +36 -0
  70. package/dist/math/referenceTagStack.d.ts.map +1 -0
  71. package/dist/math/scrubMarkers.d.ts +12 -0
  72. package/dist/math/scrubMarkers.d.ts.map +1 -0
  73. package/dist/types.d.ts +202 -32
  74. package/dist/types.d.ts.map +1 -1
  75. package/package.json +1 -1
  76. package/src/components/CustomReferenceLineOverlay.tsx +50 -8
  77. package/src/components/CustomTooltipOverlay.tsx +5 -1
  78. package/src/components/LiveChart.tsx +560 -138
  79. package/src/components/LiveChartSeries.tsx +113 -13
  80. package/src/components/ReferenceLineOverlay.tsx +62 -26
  81. package/src/components/ReferenceValueBadge.tsx +102 -0
  82. package/src/components/XAxisOverlay.tsx +104 -1
  83. package/src/core/liveChartEngineTick.ts +49 -4
  84. package/src/core/liveChartSeriesEngineTick.ts +37 -0
  85. package/src/core/resolveConfig.ts +95 -2
  86. package/src/core/useLiveChartEngine.ts +43 -9
  87. package/src/core/useLiveChartSeriesEngine.ts +5 -0
  88. package/src/draw/grid.ts +2 -2
  89. package/src/draw/line.ts +23 -1
  90. package/src/hooks/crosshairShared.ts +56 -1
  91. package/src/hooks/referenceBadgeFont.ts +35 -0
  92. package/src/hooks/resolveChartLayout.ts +17 -0
  93. package/src/hooks/useBadge.ts +44 -5
  94. package/src/hooks/useChartSkiaFont.ts +1 -1
  95. package/src/hooks/useCrosshair.ts +444 -310
  96. package/src/hooks/useCrosshairSeries.ts +29 -10
  97. package/src/hooks/useLatestCallback.ts +15 -0
  98. package/src/hooks/useMarkers.ts +51 -39
  99. package/src/hooks/usePanScroll.ts +155 -127
  100. package/src/hooks/usePinchZoom.ts +84 -63
  101. package/src/hooks/useReferenceDrag.ts +390 -155
  102. package/src/hooks/useReferenceLine.ts +453 -277
  103. package/src/hooks/useReferenceLineGrouping.ts +1 -1
  104. package/src/hooks/useReferenceLinePress.ts +121 -53
  105. package/src/hooks/useReferenceTagStack.ts +81 -0
  106. package/src/hooks/useScrubMarkers.ts +79 -0
  107. package/src/hooks/useXAxis.ts +11 -2
  108. package/src/hooks/useYAxisScaleGesture.ts +263 -0
  109. package/src/index.ts +10 -0
  110. package/src/math/axisBadgeLayout.ts +37 -0
  111. package/src/math/markers.ts +28 -3
  112. package/src/math/range.ts +35 -0
  113. package/src/math/referenceTagStack.ts +112 -0
  114. package/src/math/scrubMarkers.ts +55 -0
  115. package/src/types.ts +207 -32
@@ -5,7 +5,7 @@
5
5
  * @see https://github.com/benjitaylor/liveline
6
6
  */
7
7
  import { Canvas, Group, Rect, type SkFont } from "@shopify/react-native-skia";
8
- import { forwardRef, useImperativeHandle, useState } from "react";
8
+ import { forwardRef, useCallback, useImperativeHandle, useState } from "react";
9
9
  import { StyleSheet, View } from "react-native";
10
10
  import { Gesture, GestureDetector } from "react-native-gesture-handler";
11
11
  import Animated, {
@@ -47,17 +47,26 @@ import {
47
47
  resolveSelectionDot,
48
48
  resolveTransitions,
49
49
  resolveXAxis,
50
+ resolveXAxisGridStyle,
50
51
  resolveYAxis,
51
52
  resolveZoom,
52
53
  } from "../core/resolveConfig";
53
54
  import { useLiveChartSeriesEngine } from "../core/useLiveChartSeriesEngine";
54
- import { dotGlowRadialOutset, pulseRadialOutset } from "../draw/line";
55
- import { resolveChartLayout } from "../hooks/resolveChartLayout";
55
+ import {
56
+ dotGlowRadialOutset,
57
+ pulseRadialOutset,
58
+ seriesPlotClip,
59
+ } from "../draw/line";
60
+ import {
61
+ resolveChartLayout,
62
+ shouldResampleLayoutValue,
63
+ } from "../hooks/resolveChartLayout";
56
64
  import { useCanvasLayout } from "../hooks/useCanvasLayout";
57
65
  import { useChartReveal } from "../hooks/useChartReveal";
58
66
  import { useChartOverlayContext } from "../hooks/useChartOverlayContext";
59
67
  import { useChartSkiaFont } from "../hooks/useChartSkiaFont";
60
68
  import { useCrosshairSeries } from "../hooks/useCrosshairSeries";
69
+ import { resolveScrubMarkerOptions } from "../hooks/useScrubMarkers";
61
70
  import { useCrosshairVisibleOpacity } from "../hooks/useCrosshairVisibleOpacity";
62
71
  import { useLoadingLook } from "../hooks/useLoadingLook";
63
72
  import { useMarkers } from "../hooks/useMarkers";
@@ -73,6 +82,10 @@ import {
73
82
  import { useVisibleRange } from "../hooks/useVisibleRange";
74
83
  import { useXAxis } from "../hooks/useXAxis";
75
84
  import { useYAxis } from "../hooks/useYAxis";
85
+ import {
86
+ useYAxisScaleGesture,
87
+ useYAxisScaleValue,
88
+ } from "../hooks/useYAxisScaleGesture";
76
89
  import {
77
90
  formatTime as defaultFormatTime,
78
91
  formatValue as defaultFormatValue,
@@ -117,7 +130,7 @@ import { MultiSeriesValueLines } from "./MultiSeriesValueLines";
117
130
  import { PerSeriesTooltipOverlay } from "./PerSeriesTooltipOverlay";
118
131
  import { ReferenceLineOverlay } from "./ReferenceLineOverlay";
119
132
  import { SeriesToggleChips } from "./SeriesToggleChips";
120
- import { XAxisOverlay } from "./XAxisOverlay";
133
+ import { XAxisGridLines, XAxisOverlay } from "./XAxisOverlay";
121
134
  import { YAxisOverlay } from "./YAxisOverlay";
122
135
 
123
136
  /**
@@ -138,6 +151,35 @@ function seriesConfigSig(s: SharedValue<SeriesConfig[]>) {
138
151
  return out;
139
152
  }
140
153
 
154
+ /** Largest finite magnitude — zeros and invalid placeholders cannot mask it. */
155
+ function seriesLayoutValue(s: SharedValue<SeriesConfig[]>) {
156
+ "worklet";
157
+ const arr = s.value;
158
+ let sample = 0;
159
+ for (let i = 0; i < arr.length; i++) {
160
+ const value = arr[i].value;
161
+ if (Number.isFinite(value) && Math.abs(value) > Math.abs(sample)) {
162
+ sample = value;
163
+ }
164
+ }
165
+ return sample;
166
+ }
167
+
168
+ function useSeriesLayoutValueSample(series: SharedValue<SeriesConfig[]>) {
169
+ const [sample, setSample] = useState<number | undefined>(undefined);
170
+ const sampled = useSharedValue(0);
171
+ useAnimatedReaction(
172
+ () => seriesLayoutValue(series),
173
+ (current) => {
174
+ if (!shouldResampleLayoutValue(current, sampled.get())) return;
175
+ sampled.set(current);
176
+ scheduleOnRN(setSample, current);
177
+ },
178
+ [sampled, series],
179
+ );
180
+ return sample;
181
+ }
182
+
141
183
  /**
142
184
  * Resolves props → configs → theme/layout → engine → per-frame derived values,
143
185
  * overlay hooks and the color/style reaction state, returning a single render
@@ -163,6 +205,7 @@ function resolveLiveChartSeriesInputs({
163
205
  exaggerate = false,
164
206
  nonNegative = false,
165
207
  maxValue,
208
+ minRange,
166
209
  yRangeScale,
167
210
  windowBuffer = 0,
168
211
  nowOverride,
@@ -234,6 +277,10 @@ function resolveLiveChartSeriesInputs({
234
277
  : (scrubCfg?.panGestureDelay ?? 0);
235
278
  const selectionDotCfg = resolveSelectionDot(selectionDot ?? false);
236
279
  const gridStyleCfg = resolveGridStyle(gridStyle);
280
+ const xGridStyleCfg = resolveXAxisGridStyle(
281
+ xAxisCfg?.gridLines ?? null,
282
+ gridStyleCfg,
283
+ );
237
284
  const dotCfg = resolveMultiSeriesDot(dotProp);
238
285
  const dotOuterRadius = Math.max(
239
286
  dotCfg.radius + (dotCfg.ring?.width ?? 0),
@@ -281,6 +328,7 @@ function resolveLiveChartSeriesInputs({
281
328
  exaggerate,
282
329
  nonNegative,
283
330
  maxValue,
331
+ minRange,
284
332
  yRangeScale,
285
333
  windowBuffer,
286
334
  nowOverride,
@@ -306,6 +354,7 @@ function resolveLiveChartSeriesInputs({
306
354
  scrubHoldMs,
307
355
  selectionDotCfg,
308
356
  gridStyleCfg,
357
+ xGridStyleCfg,
309
358
  dotCfg,
310
359
  dotOuterRadius,
311
360
  legendCfg,
@@ -354,8 +403,6 @@ function resolveSeriesSnapshotLayout(
354
403
  return {
355
404
  maxLabelWidth,
356
405
  labelInset: dot.valueLabel ? dotOuterRadius + 8 + maxLabelWidth + 8 : 0,
357
- representativeValue:
358
- snapshot.length > 0 ? Math.max(...snapshot.map((item) => item.value)) : 0,
359
406
  colors: resolveMultiSeriesLineColorsSnapshot(snapshot),
360
407
  styles: resolveMultiSeriesLineStylesSnapshot(snapshot),
361
408
  };
@@ -404,6 +451,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
404
451
  exaggerate,
405
452
  nonNegative,
406
453
  maxValue,
454
+ minRange,
407
455
  yRangeScale,
408
456
  windowBuffer,
409
457
  nowOverride,
@@ -429,6 +477,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
429
477
  scrubHoldMs,
430
478
  selectionDotCfg,
431
479
  gridStyleCfg,
480
+ xGridStyleCfg,
432
481
  dotCfg,
433
482
  dotOuterRadius,
434
483
  legendCfg,
@@ -476,6 +525,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
476
525
  // rendering. The animated reaction below emits the initial snapshot and every
477
526
  // subsequent configuration change without reading the SharedValue in render.
478
527
  const [seriesSnapshot, setSeriesSnapshot] = useState<SeriesConfig[]>([]);
528
+ const valueLayoutSample = useSeriesLayoutValueSample(series);
479
529
 
480
530
  // Mount per-series drawing worklets only for real series. The previous fixed
481
531
  // 12-slot render kept 144 derived-value mappers alive for the default stroke,
@@ -485,7 +535,6 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
485
535
  const {
486
536
  maxLabelWidth: maxSeriesLabelWidth,
487
537
  labelInset: seriesLabelInset,
488
- representativeValue,
489
538
  colors: lineColors,
490
539
  styles: lineStyles,
491
540
  } = resolveSeriesSnapshotLayout(
@@ -500,12 +549,12 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
500
549
  lineWidthOverride: lineProp?.width,
501
550
  insetsOverride: insets,
502
551
  yAxis: yAxisCfg !== null,
503
- badge: false,
552
+ badge: allRefLines.some(line => typeof line.valueBadge === "object" && line.valueBadge.position === "axis"),
504
553
  badgeMetrics: metricsCfg.badge,
505
554
  xAxis: xAxisCfg !== null,
506
555
  font: skiaFont,
507
556
  formatValue,
508
- currentValue: representativeValue,
557
+ currentValue: valueLayoutSample,
509
558
  pulse: dotCfg.pulse,
510
559
  dotGlow: dotCfg.glow,
511
560
  multiSeriesDotRadius: dotOuterRadius,
@@ -544,6 +593,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
544
593
  morphT: reveal.morphT,
545
594
  });
546
595
 
596
+ const effectiveYRangeScale = useYAxisScaleValue(yRangeScale);
547
597
  const engine = useLiveChartSeriesEngine({
548
598
  series: effectiveSeries,
549
599
  timeWindow,
@@ -559,7 +609,8 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
559
609
  referenceValues: refValues,
560
610
  nonNegative,
561
611
  maxValue,
562
- yRangeScale,
612
+ minRange,
613
+ yRangeScale: effectiveYRangeScale,
563
614
  windowBuffer,
564
615
  nowOverride,
565
616
  });
@@ -570,6 +621,13 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
570
621
  activeSeriesCount,
571
622
  lineProp?.simplify,
572
623
  );
624
+ const seriesClip = useDerivedValue(() =>
625
+ seriesPlotClip(
626
+ effectivePadding,
627
+ engine.canvasWidth.get(),
628
+ engine.canvasHeight.get(),
629
+ ),
630
+ );
573
631
 
574
632
  // Read the `series` prop from closure, not a SharedValue passed through
575
633
  // `scheduleOnRN`: the handle serialized across the worklet→JS boundary keeps
@@ -611,6 +669,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
611
669
  effectivePadding,
612
670
  formatTime,
613
671
  skiaFont,
672
+ xAxisCfg?.minGap,
614
673
  );
615
674
 
616
675
  // Cross-gesture arbitration for the one-finger touch. `Gesture.Race` below is
@@ -620,6 +679,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
620
679
  // long-press guard) makes "the scroll already won" a hard fact; `scrubActive`
621
680
  // (written by the crosshair, read by the scroll pan) is the mirror image.
622
681
  const scrollActive = useSharedValue(false);
682
+ const axisScaleActive = useSharedValue(false);
623
683
  // `liveEdge` includes the optional right breathing-room buffer. The time pill
624
684
  // must clamp against the real "now" anchor so its live bucket never ends in
625
685
  // that future buffer.
@@ -647,6 +707,8 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
647
707
  }
648
708
  : undefined,
649
709
  scrubCfg?.clampToPlot ?? false,
710
+ resolveScrubMarkerOptions(scrubCfg, markersSV),
711
+ axisScaleActive,
650
712
  );
651
713
 
652
714
  // Capture only the shared value in the worklets below. Referencing
@@ -657,7 +719,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
657
719
 
658
720
  // `projected` is used internally by the hit-test gesture; the overlay
659
721
  // self-projects, so we only need the gesture here.
660
- const { tapGesture: markerTapGesture } = useMarkers(
722
+ const { tapGesture: markerTapGesture, hitTest: markerHitTest } = useMarkers(
661
723
  engine,
662
724
  effectivePadding,
663
725
  markersSV,
@@ -724,7 +786,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
724
786
  onReachStart,
725
787
  });
726
788
 
727
- const rootGesture = composeSeriesRootGesture(
789
+ const plotGesture = composeSeriesRootGesture(
728
790
  crosshair.gesture,
729
791
  markerTapGesture,
730
792
  panScrollGesture,
@@ -735,6 +797,23 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
735
797
  scrollGestureMode,
736
798
  );
737
799
 
800
+ const clearCrosshair = useCallback(() => {
801
+ "worklet";
802
+ crosshairScrubActive.set(false);
803
+ }, [crosshairScrubActive]);
804
+ const rootGesture = useYAxisScaleGesture({
805
+ engine,
806
+ padding: effectivePadding,
807
+ axis: yAxisCfg,
808
+ entries: yAxisEntries,
809
+ font: skiaFont,
810
+ scale: effectiveYRangeScale,
811
+ gesture: plotGesture,
812
+ deferHit: markerHitTest,
813
+ onStart: clearCrosshair,
814
+ active: axisScaleActive,
815
+ });
816
+
738
817
  const backgroundColor = `rgb(${palette.bgRgb[0]}, ${palette.bgRgb[1]}, ${palette.bgRgb[2]})`;
739
818
 
740
819
  // Fade markers + reference lines out while scrubbing when
@@ -772,6 +851,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
772
851
  scrubCfg,
773
852
  seriesTooltipCfg,
774
853
  gridStyleCfg,
854
+ xGridStyleCfg,
775
855
  dotCfg,
776
856
  dotOuterRadius,
777
857
  legendCfg,
@@ -786,6 +866,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
786
866
  // theme / layout / fonts
787
867
  palette,
788
868
  skiaFont,
869
+ fontProp,
789
870
  seriesLabelInset,
790
871
  strokeWidth,
791
872
  effectivePadding,
@@ -804,6 +885,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
804
885
  layoutHeight,
805
886
  onLayout,
806
887
  linePaths,
888
+ seriesClip,
807
889
  activeSeriesCount,
808
890
  lineColors,
809
891
  lineStyles,
@@ -901,6 +983,7 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
901
983
  lineStyles,
902
984
  xAxisCfg,
903
985
  xAxisEntries,
986
+ xGridStyleCfg,
904
987
  degenCfg,
905
988
  degenPack,
906
989
  degenPackRevision,
@@ -924,6 +1007,7 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
924
1007
  canvasMode,
925
1008
  activeSeriesCount,
926
1009
  refLineKeys,
1010
+ seriesClip,
927
1011
  } = model;
928
1012
 
929
1013
  return (
@@ -933,6 +1017,18 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
933
1017
  variant={yAxisCfg?.side === "left" ? "grid" : "all"}
934
1018
  />
935
1019
 
1020
+ {/* Vertical grid at the time ticks (`xAxis.gridLines`), behind the
1021
+ series like the horizontal grid. */}
1022
+ {xAxisCfg && xGridStyleCfg && (
1023
+ <XAxisGridLines
1024
+ entries={xAxisEntries}
1025
+ engine={engine}
1026
+ padding={effectivePadding}
1027
+ palette={palette}
1028
+ gridStyle={xGridStyleCfg}
1029
+ />
1030
+ )}
1031
+
936
1032
  {/* Fade group lets `scrub.hideOverlaysOnScrub` ease the lines out. Explicit
937
1033
  ids keep each reference line mounted when the caller reorders it. */}
938
1034
  <Group opacity={overlayScrubFade}>
@@ -942,6 +1038,8 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
942
1038
  engine={engine}
943
1039
  padding={effectivePadding}
944
1040
  line={rl}
1041
+ valueAxis={{ metrics: model.metricsCfg.badge, fontSize: skiaFont.getSize() }}
1042
+ fontProp={model.fontProp}
945
1043
  palette={palette}
946
1044
  formatValue={formatValue}
947
1045
  font={skiaFont}
@@ -965,7 +1063,7 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
965
1063
  </Group>
966
1064
  )}
967
1065
 
968
- <Group opacity={reveal.lineOpacity}>
1066
+ <Group opacity={reveal.lineOpacity} clip={seriesClip}>
969
1067
  {Array.from({ length: activeSeriesCount }, (_, i) => (
970
1068
  <MultiSeriesStroke
971
1069
  key={i}
@@ -1130,6 +1228,8 @@ function SeriesRefBadgeLayer({ model }: { model: LiveChartSeriesModel }) {
1130
1228
  engine={engine}
1131
1229
  padding={effectivePadding}
1132
1230
  line={rl}
1231
+ valueAxis={{ metrics: model.metricsCfg.badge, fontSize: skiaFont.getSize() }}
1232
+ fontProp={model.fontProp}
1133
1233
  palette={palette}
1134
1234
  formatValue={formatValue}
1135
1235
  font={skiaFont}
@@ -1,3 +1,4 @@
1
+ import { useMemo } from "react";
1
2
  import {
2
3
  DashPathEffect,
3
4
  Group,
@@ -17,6 +18,10 @@ import {
17
18
  useReferenceLine,
18
19
  type ReferenceLineLayout,
19
20
  } from "../hooks/useReferenceLine";
21
+ import { referenceBadgeFont } from "../hooks/referenceBadgeFont";
22
+ import type { ReferenceTagStack } from "../math/referenceTagStack";
23
+ import type { AxisBadgeConfig } from "../math/axisBadgeLayout";
24
+ import { ReferenceValueBadge } from "./ReferenceValueBadge";
20
25
  import { MONO_FONT_FAMILY } from "../lib/monoFontFamily";
21
26
  import {
22
27
  referenceLineForm,
@@ -56,6 +61,7 @@ type ReferenceLineOverlayProps = {
56
61
  * When no badge font knob is set, the resolved `font` is used as-is.
57
62
  */
58
63
  fontProp?: FontConfig;
64
+ valueAxis?: AxisBadgeConfig;
59
65
  /**
60
66
  * Render only the badge + label (`true`) or only the lines / bands (`false`,
61
67
  * default). The caller draws the base pass behind the chart content and the
@@ -87,6 +93,7 @@ type ReferenceLineOverlayProps = {
87
93
  * stroke still draws).
88
94
  */
89
95
  groupHidden?: SharedValue<boolean[]>;
96
+ tagStack?: SharedValue<ReferenceTagStack>;
90
97
  /** Per-line live value overrides (dragged values), index-aligned with `referenceLines`. */
91
98
  dragValues?: SharedValue<number[]>;
92
99
  /** This line's index into {@link dragValues}. */
@@ -179,11 +186,13 @@ function ReferenceLineStaticOverlay({
179
186
  suppressTagWhenOffAxis = false,
180
187
  customTagWidths,
181
188
  groupHidden,
189
+ tagStack,
182
190
  dragValues,
183
191
  index = 0,
184
192
  yAxisEntries,
185
193
  labelRightMargin,
186
194
  gridEndGap,
195
+ valueAxis,
187
196
  }: ReferenceLineOverlayProps) {
188
197
  const {
189
198
  form,
@@ -214,6 +223,8 @@ function ReferenceLineStaticOverlay({
214
223
  );
215
224
  const badgeFont = badgeHasFontOverride ? badgeFontOverride : font;
216
225
 
226
+ const valueStyle = typeof line.valueBadge === "object" ? line.valueBadge : undefined;
227
+ const valueFont = useMemo(() => referenceBadgeFont(font, fontProp, valueStyle), [font, fontProp, valueStyle]);
217
228
  const layout = useReferenceLine(
218
229
  engine,
219
230
  padding,
@@ -226,7 +237,12 @@ function ReferenceLineStaticOverlay({
226
237
  labelRightMargin,
227
238
  gridEndGap,
228
239
  font,
240
+ valueFont,
241
+ valueAxis,
229
242
  );
243
+ const valueHidden = useDerivedValue(() => suppressTag ||
244
+ (suppressTagWhenOffAxis && layout.get().offAxis) ||
245
+ (groupHidden?.get()[index] ?? false));
230
246
 
231
247
  if (!badgeLayer) {
232
248
  return (
@@ -246,26 +262,30 @@ function ReferenceLineStaticOverlay({
246
262
  }
247
263
 
248
264
  return (
249
- <ReferenceLineBadgePass
250
- layout={layout}
251
- color={color}
252
- strokeWidth={strokeWidth}
253
- intervals={intervals}
254
- badgeFont={badgeFont}
255
- badgePosition={badge?.position}
256
- labelColor={labelColor}
257
- badgeBackground={badgeBackground}
258
- badgeBorderColor={badgeBorderColor}
259
- badgeBorderWidth={badgeBorderWidth}
260
- badgeRadius={badgeRadius}
261
- badgeOffsetX={badgeOffsetX}
262
- badgeOffsetY={badgeOffsetY}
263
- suppressTag={suppressTag}
264
- suppressTagWhenOffAxis={suppressTagWhenOffAxis}
265
- customTagWidths={customTagWidths}
266
- groupHidden={groupHidden}
267
- index={index}
268
- />
265
+ <>
266
+ <ReferenceLineBadgePass
267
+ layout={layout}
268
+ color={color}
269
+ strokeWidth={strokeWidth}
270
+ intervals={intervals}
271
+ badgeFont={badgeFont}
272
+ badgePosition={badge?.position}
273
+ labelColor={labelColor}
274
+ badgeBackground={badgeBackground}
275
+ badgeBorderColor={badgeBorderColor}
276
+ badgeBorderWidth={badgeBorderWidth}
277
+ badgeRadius={badgeRadius}
278
+ badgeOffsetX={badgeOffsetX}
279
+ badgeOffsetY={badgeOffsetY}
280
+ suppressTag={suppressTag}
281
+ suppressTagWhenOffAxis={suppressTagWhenOffAxis}
282
+ customTagWidths={customTagWidths}
283
+ groupHidden={groupHidden}
284
+ tagStack={tagStack}
285
+ index={index}
286
+ />
287
+ {line.valueBadge && <ReferenceValueBadge layout={layout} line={line} font={valueFont} palette={palette} hidden={valueHidden} tagStack={tagStack} index={index} />}
288
+ </>
269
289
  );
270
290
  }
271
291
 
@@ -401,6 +421,7 @@ function ReferenceLineBadgePass({
401
421
  suppressTagWhenOffAxis,
402
422
  customTagWidths,
403
423
  groupHidden,
424
+ tagStack,
404
425
  index,
405
426
  }: {
406
427
  layout: SharedValue<ReferenceLineLayout>;
@@ -420,6 +441,7 @@ function ReferenceLineBadgePass({
420
441
  suppressTagWhenOffAxis: boolean;
421
442
  customTagWidths?: SharedValue<number[]>;
422
443
  groupHidden?: SharedValue<boolean[]>;
444
+ tagStack?: SharedValue<ReferenceTagStack>;
423
445
  index: number;
424
446
  }) {
425
447
  const connBuilder = usePathBuilder();
@@ -428,12 +450,19 @@ function ReferenceLineBadgePass({
428
450
  badgeOffsetX !== 0 || badgeOffsetY !== 0
429
451
  ? [{ translateX: badgeOffsetX }, { translateY: badgeOffsetY }]
430
452
  : undefined;
453
+ const tagTransform = useDerivedValue(() => [
454
+ { translateX: badgeOffsetX },
455
+ { translateY: badgeOffsetY + (tagStack?.get().offsets[index] ?? 0) },
456
+ ]);
431
457
  const connPath = useDerivedValue(() => {
432
458
  const b = connBuilder.value;
433
459
  const l = layout.get();
434
- if (l.visible && l.badge && l.connStart >= 0) {
460
+ if (l.visible && (l.badge || l.valueBadge) && l.connStart >= 0) {
435
461
  let start = l.connStart;
436
462
  let end = l.connEnd;
463
+ if ((suppressTag || (suppressTagWhenOffAxis && l.offAxis)) && l.valueBadge) {
464
+ end = l.x2;
465
+ }
437
466
  const customTagActive =
438
467
  suppressTag || (suppressTagWhenOffAxis && l.offAxis);
439
468
  const customWidth = customTagActive
@@ -449,8 +478,15 @@ function ReferenceLineBadgePass({
449
478
  }
450
479
  }
451
480
  if (end > start) {
452
- b.moveTo(start, l.y);
453
- b.lineTo(end, l.y);
481
+ const nameOffset = tagStack?.get().offsets[index] ?? 0;
482
+ const valueOffset = tagStack?.get().valueOffsets[index] ?? 0;
483
+ const leftOffset = badgePosition === "left" ? nameOffset : 0;
484
+ const rightOffset = l.valueBadge && !customTagActive ? valueOffset : badgePosition === "right" ? nameOffset : 0;
485
+ const elbow = Math.min(8, (end - start) / 3);
486
+ b.moveTo(start, l.y + leftOffset);
487
+ if (leftOffset !== 0) b.lineTo(start + elbow, l.y);
488
+ if (rightOffset !== 0) b.lineTo(end - elbow, l.y);
489
+ b.lineTo(end, l.y + rightOffset);
454
490
  }
455
491
  }
456
492
  return b.detach();
@@ -484,7 +520,7 @@ function ReferenceLineBadgePass({
484
520
  const connectorOpacity = useDerivedValue(() => {
485
521
  const l = layout.get();
486
522
  const grouped = groupHidden ? groupHidden.get()[index] === true : false;
487
- return !grouped && l.visible && l.badge && l.connStart >= 0 ? 1 : 0;
523
+ return !grouped && l.visible && (l.badge || l.valueBadge) && l.connStart >= 0 ? 1 : 0;
488
524
  });
489
525
  const labelOpacity = useDerivedValue(() => {
490
526
  const l = layout.get();
@@ -529,7 +565,7 @@ function ReferenceLineBadgePass({
529
565
  <DashPathEffect intervals={intervals} />
530
566
  </Path>
531
567
  </Group>
532
- <Group opacity={badgeOpacity} transform={badgeTransform}>
568
+ <Group opacity={badgeOpacity} transform={tagStack ? tagTransform : badgeTransform}>
533
569
  <RoundedRect
534
570
  x={pillX}
535
571
  y={pillY}
@@ -566,7 +602,7 @@ function ReferenceLineBadgePass({
566
602
  />
567
603
  </Group>
568
604
  </Group>
569
- <Group opacity={labelOpacity} transform={badgeTransform}>
605
+ <Group opacity={labelOpacity} transform={tagStack ? tagTransform : badgeTransform}>
570
606
  <SkiaText
571
607
  x={labelX}
572
608
  y={labelY}
@@ -0,0 +1,102 @@
1
+ import type { ReferenceTagStack } from "../math/referenceTagStack";
2
+ import {
3
+ Group,
4
+ Path,
5
+ RoundedRect,
6
+ Text,
7
+ type SkFont,
8
+ } from "@shopify/react-native-skia";
9
+ import { useDerivedValue, type SharedValue } from "react-native-reanimated";
10
+ import type { ReferenceLineLayout } from "../hooks/useReferenceLine";
11
+ import { usePathBuilder } from "../hooks/usePathBuilder";
12
+ import type { LiveChartPalette, ReferenceLine } from "../types";
13
+
14
+ function useValueTagTransform(stack: SharedValue<ReferenceTagStack> | undefined, index: number) {
15
+ return useDerivedValue(() => [{ translateY: stack?.get().valueOffsets[index] ?? 0 }]);
16
+ }
17
+
18
+ export function ReferenceValueBadge({
19
+ layout,
20
+ line,
21
+ font,
22
+ palette,
23
+ hidden,
24
+ tagStack,
25
+ index = 0,
26
+ }: {
27
+ layout: SharedValue<ReferenceLineLayout>;
28
+ line: ReferenceLine;
29
+ font: SkFont;
30
+ palette: LiveChartPalette;
31
+ hidden: SharedValue<boolean>;
32
+ tagStack?: SharedValue<ReferenceTagStack>;
33
+ index?: number;
34
+ }) {
35
+ const cfg = typeof line.valueBadge === "object" ? line.valueBadge : {};
36
+ const color = line.color ?? palette.refLine;
37
+ const builder = usePathBuilder();
38
+ const chevron = useDerivedValue(() => {
39
+ const b = builder.get();
40
+ const l = layout.get();
41
+ const pill = l.valueBadge;
42
+ if (pill && pill.chevronCx >= 0) {
43
+ const cx = pill.chevronCx;
44
+ const cy = pill.y + pill.h / 2;
45
+ const sign = l.chevronUp ? 1 : -1;
46
+ b.moveTo(cx - 4, cy + sign * 4);
47
+ b.lineTo(cx, cy - sign * 4);
48
+ b.lineTo(cx + 4, cy + sign * 4);
49
+ }
50
+ return b.detach();
51
+ });
52
+ const opacity = useDerivedValue(() =>
53
+ !hidden.get() && layout.get().valueBadge ? 1 : 0,
54
+ );
55
+ const x = useDerivedValue(() => layout.get().valueBadge?.x ?? 0);
56
+ const y = useDerivedValue(() => layout.get().valueBadge?.y ?? 0);
57
+ const width = useDerivedValue(() => layout.get().valueBadge?.w ?? 0);
58
+ const height = useDerivedValue(() => layout.get().valueBadge?.h ?? 0);
59
+ const text = useDerivedValue(() => layout.get().valueBadge?.text ?? "");
60
+ const textX = useDerivedValue(() => layout.get().valueBadge?.textX ?? 0);
61
+ const textY = useDerivedValue(() => layout.get().valueBadge?.textY ?? 0);
62
+ const transform = useValueTagTransform(tagStack, index);
63
+ return (
64
+ <Group opacity={opacity} transform={transform}>
65
+ <RoundedRect
66
+ x={x}
67
+ y={y}
68
+ width={width}
69
+ height={height}
70
+ r={cfg.radius ?? line.badgeRadius ?? 5}
71
+ color={cfg.background ?? line.badgeBackground ?? palette.tooltipBg}
72
+ />
73
+ <RoundedRect
74
+ x={x}
75
+ y={y}
76
+ width={width}
77
+ height={height}
78
+ r={cfg.radius ?? line.badgeRadius ?? 5}
79
+ color={cfg.borderColor ?? line.badgeBorderColor ?? color}
80
+ style="stroke"
81
+ strokeWidth={cfg.borderWidth ?? 1}
82
+ />
83
+ <Path
84
+ path={chevron}
85
+ color={color}
86
+ style="stroke"
87
+ strokeWidth={1.5}
88
+ strokeCap="round"
89
+ strokeJoin="round"
90
+ />
91
+ <Text
92
+ x={textX}
93
+ y={textY}
94
+ text={text}
95
+ font={font}
96
+ color={
97
+ cfg.textColor ?? line.labelColor ?? line.color ?? palette.refLabel
98
+ }
99
+ />
100
+ </Group>
101
+ );
102
+ }