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.
- package/dist/components/CustomReferenceLineOverlay.d.ts +8 -1
- package/dist/components/CustomReferenceLineOverlay.d.ts.map +1 -1
- package/dist/components/CustomTooltipOverlay.d.ts +3 -2
- package/dist/components/CustomTooltipOverlay.d.ts.map +1 -1
- package/dist/components/LiveChart.d.ts +1 -1
- package/dist/components/LiveChart.d.ts.map +1 -1
- package/dist/components/LiveChartSeries.d.ts.map +1 -1
- package/dist/components/MultiSeriesDots.d.ts +1 -1
- package/dist/components/MultiSeriesDots.d.ts.map +1 -1
- package/dist/components/MultiSeriesValueLabels.d.ts +1 -1
- package/dist/components/MultiSeriesValueLabels.d.ts.map +1 -1
- package/dist/components/MultiSeriesValueLines.d.ts +1 -1
- package/dist/components/MultiSeriesValueLines.d.ts.map +1 -1
- package/dist/components/ReferenceLineOverlay.d.ts +4 -0
- package/dist/components/ReferenceLineOverlay.d.ts.map +1 -1
- package/dist/components/ReferenceValueBadge.d.ts +15 -0
- package/dist/components/ReferenceValueBadge.d.ts.map +1 -0
- package/dist/components/XAxisOverlay.d.ts +17 -0
- package/dist/components/XAxisOverlay.d.ts.map +1 -1
- package/dist/core/liveChartEngineTick.d.ts +4 -0
- package/dist/core/liveChartEngineTick.d.ts.map +1 -1
- package/dist/core/liveChartSeriesEngineTick.d.ts +15 -2
- package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
- package/dist/core/resolveConfig.d.ts +28 -1
- package/dist/core/resolveConfig.d.ts.map +1 -1
- package/dist/core/useLiveChartEngine.d.ts +9 -0
- package/dist/core/useLiveChartEngine.d.ts.map +1 -1
- package/dist/core/useLiveChartSeriesEngine.d.ts +18 -4
- package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
- package/dist/draw/grid.d.ts +6 -4
- package/dist/draw/grid.d.ts.map +1 -1
- package/dist/draw/line.d.ts +21 -3
- package/dist/draw/line.d.ts.map +1 -1
- package/dist/hooks/crosshairSeries.d.ts +2 -2
- package/dist/hooks/crosshairSeries.d.ts.map +1 -1
- package/dist/hooks/crosshairShared.d.ts +16 -1
- package/dist/hooks/crosshairShared.d.ts.map +1 -1
- package/dist/hooks/referenceBadgeFont.d.ts +5 -0
- package/dist/hooks/referenceBadgeFont.d.ts.map +1 -0
- package/dist/hooks/resolveChartLayout.d.ts +18 -2
- package/dist/hooks/resolveChartLayout.d.ts.map +1 -1
- package/dist/hooks/useBadge.d.ts +16 -1
- package/dist/hooks/useBadge.d.ts.map +1 -1
- package/dist/hooks/useChartSkiaFont.d.ts +1 -0
- package/dist/hooks/useChartSkiaFont.d.ts.map +1 -1
- package/dist/hooks/useCrosshair.d.ts +7 -2
- package/dist/hooks/useCrosshair.d.ts.map +1 -1
- package/dist/hooks/useCrosshairSeries.d.ts +6 -1
- package/dist/hooks/useCrosshairSeries.d.ts.map +1 -1
- package/dist/hooks/useLatestCallback.d.ts +6 -0
- package/dist/hooks/useLatestCallback.d.ts.map +1 -0
- package/dist/hooks/useMarkers.d.ts.map +1 -1
- package/dist/hooks/useMultiSeriesDegen.d.ts +1 -1
- package/dist/hooks/useMultiSeriesDegen.d.ts.map +1 -1
- package/dist/hooks/useMultiSeriesLinePaths.d.ts.map +1 -1
- package/dist/hooks/usePanScroll.d.ts +3 -1
- package/dist/hooks/usePanScroll.d.ts.map +1 -1
- package/dist/hooks/usePinchZoom.d.ts +7 -4
- package/dist/hooks/usePinchZoom.d.ts.map +1 -1
- package/dist/hooks/useReferenceDrag.d.ts +20 -5
- package/dist/hooks/useReferenceDrag.d.ts.map +1 -1
- package/dist/hooks/useReferenceLine.d.ts +24 -12
- package/dist/hooks/useReferenceLine.d.ts.map +1 -1
- package/dist/hooks/useReferenceLinePress.d.ts +4 -2
- package/dist/hooks/useReferenceLinePress.d.ts.map +1 -1
- package/dist/hooks/useReferenceTagStack.d.ts +31 -0
- package/dist/hooks/useReferenceTagStack.d.ts.map +1 -0
- package/dist/hooks/useScrubMarkers.d.ts +12 -0
- package/dist/hooks/useScrubMarkers.d.ts.map +1 -0
- package/dist/hooks/useXAxis.d.ts +1 -1
- package/dist/hooks/useXAxis.d.ts.map +1 -1
- package/dist/hooks/useYAxis.d.ts +1 -1
- package/dist/hooks/useYAxis.d.ts.map +1 -1
- package/dist/hooks/useYAxisLabelWidth.d.ts +6 -0
- package/dist/hooks/useYAxisLabelWidth.d.ts.map +1 -0
- package/dist/hooks/useYAxisScaleGesture.d.ts +34 -0
- package/dist/hooks/useYAxisScaleGesture.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/math/axisBadgeLayout.d.ts +16 -0
- package/dist/math/axisBadgeLayout.d.ts.map +1 -0
- package/dist/math/markers.d.ts +3 -0
- package/dist/math/markers.d.ts.map +1 -1
- package/dist/math/range.d.ts +1 -1
- package/dist/math/range.d.ts.map +1 -1
- package/dist/math/referenceLines.d.ts.map +1 -1
- package/dist/math/referenceTagStack.d.ts +36 -0
- package/dist/math/referenceTagStack.d.ts.map +1 -0
- package/dist/math/scrubMarkers.d.ts +12 -0
- package/dist/math/scrubMarkers.d.ts.map +1 -0
- package/dist/types.d.ts +262 -37
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/CustomReferenceLineOverlay.tsx +50 -8
- package/src/components/CustomTooltipOverlay.tsx +5 -1
- package/src/components/LiveChart.tsx +580 -138
- package/src/components/LiveChartSeries.tsx +139 -19
- package/src/components/MultiSeriesDots.tsx +4 -2
- package/src/components/MultiSeriesValueLabels.tsx +4 -2
- package/src/components/MultiSeriesValueLines.tsx +4 -2
- package/src/components/ReferenceLineOverlay.tsx +62 -26
- package/src/components/ReferenceValueBadge.tsx +102 -0
- package/src/components/XAxisOverlay.tsx +104 -1
- package/src/core/liveChartEngineTick.ts +49 -4
- package/src/core/liveChartSeriesEngineTick.ts +107 -14
- package/src/core/resolveConfig.ts +103 -7
- package/src/core/useLiveChartEngine.ts +45 -9
- package/src/core/useLiveChartSeriesEngine.ts +47 -6
- package/src/draw/grid.ts +17 -13
- package/src/draw/line.ts +46 -5
- package/src/hooks/crosshairSeries.ts +37 -5
- package/src/hooks/crosshairShared.ts +56 -1
- package/src/hooks/referenceBadgeFont.ts +35 -0
- package/src/hooks/resolveChartLayout.ts +51 -3
- package/src/hooks/useBadge.ts +44 -5
- package/src/hooks/useChartSkiaFont.ts +1 -1
- package/src/hooks/useCrosshair.ts +444 -310
- package/src/hooks/useCrosshairSeries.ts +57 -20
- package/src/hooks/useLatestCallback.ts +15 -0
- package/src/hooks/useMarkers.ts +51 -39
- package/src/hooks/useMultiSeriesDegen.ts +10 -5
- package/src/hooks/useMultiSeriesLinePaths.ts +2 -0
- package/src/hooks/usePanScroll.ts +155 -127
- package/src/hooks/usePinchZoom.ts +94 -66
- package/src/hooks/useReferenceDrag.ts +409 -156
- package/src/hooks/useReferenceLine.ts +453 -277
- package/src/hooks/useReferenceLineGrouping.ts +1 -1
- package/src/hooks/useReferenceLinePress.ts +121 -53
- package/src/hooks/useReferenceTagStack.ts +81 -0
- package/src/hooks/useScrubMarkers.ts +79 -0
- package/src/hooks/useXAxis.ts +11 -2
- package/src/hooks/useYAxis.ts +1 -1
- package/src/hooks/useYAxisLabelWidth.ts +26 -0
- package/src/hooks/useYAxisScaleGesture.ts +263 -0
- package/src/index.ts +11 -0
- package/src/math/axisBadgeLayout.ts +37 -0
- package/src/math/markers.ts +28 -3
- package/src/math/range.ts +35 -0
- package/src/math/referenceLines.ts +5 -0
- package/src/math/referenceTagStack.ts +112 -0
- package/src/math/scrubMarkers.ts +55 -0
- package/src/types.ts +263 -37
package/src/hooks/useBadge.ts
CHANGED
|
@@ -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 =
|
|
127
|
-
|
|
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
|
|
151
|
-
|
|
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
|
|
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"]>,
|