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
@@ -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"]>,