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.
- 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/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 +2 -0
- 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 +7 -0
- package/dist/core/useLiveChartEngine.d.ts.map +1 -1
- package/dist/core/useLiveChartSeriesEngine.d.ts +2 -0
- package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
- package/dist/draw/grid.d.ts +2 -2
- package/dist/draw/line.d.ts +15 -1
- package/dist/draw/line.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 +8 -0
- 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 +4 -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/usePanScroll.d.ts +3 -1
- package/dist/hooks/usePanScroll.d.ts.map +1 -1
- 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/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/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 +202 -32
- 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 +560 -138
- package/src/components/LiveChartSeries.tsx +113 -13
- 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 +37 -0
- package/src/core/resolveConfig.ts +95 -2
- package/src/core/useLiveChartEngine.ts +43 -9
- package/src/core/useLiveChartSeriesEngine.ts +5 -0
- package/src/draw/grid.ts +2 -2
- package/src/draw/line.ts +23 -1
- package/src/hooks/crosshairShared.ts +56 -1
- package/src/hooks/referenceBadgeFont.ts +35 -0
- package/src/hooks/resolveChartLayout.ts +17 -0
- 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 +29 -10
- package/src/hooks/useLatestCallback.ts +15 -0
- package/src/hooks/useMarkers.ts +51 -39
- package/src/hooks/usePanScroll.ts +155 -127
- package/src/hooks/usePinchZoom.ts +84 -63
- package/src/hooks/useReferenceDrag.ts +390 -155
- 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/useYAxisScaleGesture.ts +263 -0
- package/src/index.ts +10 -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/referenceTagStack.ts +112 -0
- package/src/math/scrubMarkers.ts +55 -0
- package/src/types.ts +207 -32
|
@@ -30,6 +30,7 @@ export interface MultiSeriesEngineConfig {
|
|
|
30
30
|
referenceValues?: number[];
|
|
31
31
|
nonNegative?: boolean;
|
|
32
32
|
maxValue?: number;
|
|
33
|
+
minRange?: number;
|
|
33
34
|
/** Positive, finite live Y-range multiplier (1 = auto-fit); read each frame. */
|
|
34
35
|
yRangeScale?: SharedValue<number>;
|
|
35
36
|
nowOverride?: number;
|
|
@@ -84,6 +85,7 @@ export interface MultiEngineFrameRefs {
|
|
|
84
85
|
referenceValues?: SharedValue<number[] | undefined>;
|
|
85
86
|
nonNegativeSV?: SharedValue<boolean>;
|
|
86
87
|
maxValueSV?: SharedValue<number | undefined>;
|
|
88
|
+
minRangeSV?: SharedValue<number | undefined>;
|
|
87
89
|
yRangeScaleSV?: SharedValue<number>;
|
|
88
90
|
nowOverrideSV?: SharedValue<number | undefined>;
|
|
89
91
|
windowBufferSV?: SharedValue<number>;
|
|
@@ -249,6 +251,7 @@ export function applyLiveChartSeriesEngineFrame(
|
|
|
249
251
|
input.referenceValues = sv.referenceValues?.value;
|
|
250
252
|
input.nonNegative = sv.nonNegativeSV?.value ?? false;
|
|
251
253
|
input.maxValue = sv.maxValueSV?.value;
|
|
254
|
+
input.minRange = sv.minRangeSV?.value;
|
|
252
255
|
input.yRangeScale = sv.yRangeScaleSV?.value ?? 1;
|
|
253
256
|
input.nowOverride = sv.nowOverrideSV?.value;
|
|
254
257
|
input.windowBuffer = sv.windowBufferSV?.value ?? 0;
|
|
@@ -311,6 +314,7 @@ export function useLiveChartSeriesEngine(
|
|
|
311
314
|
const referenceValues = useDerivedValue(() => config.referenceValues);
|
|
312
315
|
const nonNegativeSV = useDerivedValue(() => config.nonNegative ?? false);
|
|
313
316
|
const maxValueSV = useDerivedValue(() => config.maxValue);
|
|
317
|
+
const minRangeSV = useDerivedValue(() => config.minRange);
|
|
314
318
|
const nowOverrideSV = useDerivedValue(() => config.nowOverride);
|
|
315
319
|
const windowBufferSV = useDerivedValue(() => config.windowBuffer ?? 0);
|
|
316
320
|
const pausedSV = useDerivedValue(() => config.paused ?? false);
|
|
@@ -399,6 +403,7 @@ export function useLiveChartSeriesEngine(
|
|
|
399
403
|
referenceValues,
|
|
400
404
|
nonNegativeSV,
|
|
401
405
|
maxValueSV,
|
|
406
|
+
minRangeSV,
|
|
402
407
|
yRangeScaleSV: config.yRangeScale,
|
|
403
408
|
nowOverrideSV,
|
|
404
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
|
|
23
|
-
* their
|
|
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 `
|
|
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>;
|
|
@@ -306,6 +307,60 @@ export function snapPrice(price: number, increment?: number): number {
|
|
|
306
307
|
return Math.round(price / increment) * increment;
|
|
307
308
|
}
|
|
308
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
|
+
|
|
309
364
|
/**
|
|
310
365
|
* Maps a scrub X position to a window timestamp.
|
|
311
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
|
|
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"]>,
|