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
|
@@ -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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
-
|
|
453
|
-
|
|
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
|
+
}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DashPathEffect,
|
|
3
|
+
Group,
|
|
4
|
+
Path,
|
|
5
|
+
type SkFont,
|
|
6
|
+
type SkPath,
|
|
7
|
+
} from "@shopify/react-native-skia";
|
|
2
8
|
import { useDerivedValue, type SharedValue } from "react-native-reanimated";
|
|
3
9
|
import { X_AXIS_LABEL_OFFSET_Y } from "../constants";
|
|
10
|
+
import type { ResolvedGridStyleConfig } from "../core/resolveConfig";
|
|
4
11
|
import type { ChartEngineLayout } from "../core/useLiveChartEngine";
|
|
5
12
|
import type { ChartPadding } from "../draw/line";
|
|
6
13
|
import type { XAxisEntry } from "../hooks/useXAxis";
|
|
@@ -95,3 +102,99 @@ export function XAxisOverlay({
|
|
|
95
102
|
</Group>
|
|
96
103
|
);
|
|
97
104
|
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Vertical grid lines at the time-axis ticks (`xAxis.gridLines`). The chart
|
|
108
|
+
* draws this behind the series, in the horizontal grid's layer; the axis line,
|
|
109
|
+
* ticks, and labels stay in {@link XAxisOverlay} above it. One pooled line per
|
|
110
|
+
* label slot, so each line fades with its label instead of popping in at the
|
|
111
|
+
* plot edges.
|
|
112
|
+
*/
|
|
113
|
+
export function XAxisGridLines({
|
|
114
|
+
entries,
|
|
115
|
+
engine,
|
|
116
|
+
padding,
|
|
117
|
+
palette,
|
|
118
|
+
gridStyle,
|
|
119
|
+
volumeBandHeight = 0,
|
|
120
|
+
}: {
|
|
121
|
+
entries: SharedValue<XAxisEntry[]>;
|
|
122
|
+
engine: ChartEngineLayout;
|
|
123
|
+
padding: ChartPadding;
|
|
124
|
+
palette: LiveChartPalette;
|
|
125
|
+
gridStyle: ResolvedGridStyleConfig;
|
|
126
|
+
/** Reserved volume-band height (px); the lines run through it to the axis line. */
|
|
127
|
+
volumeBandHeight?: number;
|
|
128
|
+
}) {
|
|
129
|
+
const segmentBuilder = usePathBuilder();
|
|
130
|
+
// Capturing the whole engine subscribes this immutable segment to its live
|
|
131
|
+
// clock/range too. Only layout changes should allocate a new segment path.
|
|
132
|
+
const { canvasWidth, canvasHeight } = engine;
|
|
133
|
+
const { left, right, top, bottom } = padding;
|
|
134
|
+
|
|
135
|
+
// One vertical segment, from the plot top down to the axis line, shared by
|
|
136
|
+
// the whole pool: each line only translates it to its tick.
|
|
137
|
+
const segment = useDerivedValue(() => {
|
|
138
|
+
"worklet";
|
|
139
|
+
const b = segmentBuilder.value;
|
|
140
|
+
b.moveTo(0, top);
|
|
141
|
+
b.lineTo(
|
|
142
|
+
0,
|
|
143
|
+
canvasHeight.get() - bottom + volumeBandHeight,
|
|
144
|
+
);
|
|
145
|
+
return b.detach();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Fading ticks can remain just outside the plot. Keep their strokes out of
|
|
149
|
+
// the axis gutters while retaining the full candle volume-band height.
|
|
150
|
+
const clip = useDerivedValue(() => ({
|
|
151
|
+
x: left,
|
|
152
|
+
y: top,
|
|
153
|
+
width: Math.max(0, canvasWidth.get() - left - right),
|
|
154
|
+
height: Math.max(0, canvasHeight.get() - bottom + volumeBandHeight - top),
|
|
155
|
+
}));
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<Group opacity={gridStyle.opacity} clip={clip}>
|
|
159
|
+
{Array.from({ length: MAX_X_LABELS }, (_, i) => (
|
|
160
|
+
<XAxisGridLine
|
|
161
|
+
key={i}
|
|
162
|
+
entries={entries}
|
|
163
|
+
index={i}
|
|
164
|
+
segment={segment}
|
|
165
|
+
color={gridStyle.color ?? palette.gridLine}
|
|
166
|
+
strokeWidth={gridStyle.strokeWidth}
|
|
167
|
+
intervals={gridStyle.intervals}
|
|
168
|
+
/>
|
|
169
|
+
))}
|
|
170
|
+
</Group>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function XAxisGridLine({
|
|
175
|
+
entries,
|
|
176
|
+
index,
|
|
177
|
+
segment,
|
|
178
|
+
color,
|
|
179
|
+
strokeWidth,
|
|
180
|
+
intervals,
|
|
181
|
+
}: {
|
|
182
|
+
entries: SharedValue<XAxisEntry[]>;
|
|
183
|
+
index: number;
|
|
184
|
+
segment: SharedValue<SkPath>;
|
|
185
|
+
color: string;
|
|
186
|
+
strokeWidth: number;
|
|
187
|
+
intervals: number[];
|
|
188
|
+
}) {
|
|
189
|
+
const transform = useDerivedValue(() => [
|
|
190
|
+
{ translateX: entries.get()[index]?.x ?? -200 },
|
|
191
|
+
]);
|
|
192
|
+
const opacity = useDerivedValue(() => entries.get()[index]?.alpha ?? 0);
|
|
193
|
+
return (
|
|
194
|
+
<Group transform={transform} opacity={opacity}>
|
|
195
|
+
<Path path={segment} style="stroke" strokeWidth={strokeWidth} color={color}>
|
|
196
|
+
{intervals.length > 0 && <DashPathEffect intervals={intervals} />}
|
|
197
|
+
</Path>
|
|
198
|
+
</Group>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
@@ -88,6 +88,8 @@ export interface EngineTickInput {
|
|
|
88
88
|
nonNegative?: boolean;
|
|
89
89
|
/** Hard cap for the computed upper bound. */
|
|
90
90
|
maxValue?: number;
|
|
91
|
+
/** Smallest fitted span, in data units; widened around the data. */
|
|
92
|
+
minRange?: number;
|
|
91
93
|
/** Positive, finite Y-range multiplier around the fitted midpoint (1 = auto-fit). */
|
|
92
94
|
yRangeScale?: number;
|
|
93
95
|
targetValue: number;
|
|
@@ -148,6 +150,8 @@ export interface EngineTickInput {
|
|
|
148
150
|
* overrides its width. `displayWindow` eases toward this when set.
|
|
149
151
|
*/
|
|
150
152
|
viewWindow?: number | null;
|
|
153
|
+
/** Ease a non-null viewWindow override. False adopts a leader's drawn width exactly. Default true. */
|
|
154
|
+
viewWindowSmoothing?: boolean;
|
|
151
155
|
/** Chart mode — `"candle"` uses OHLC bars for Y range instead of line points. */
|
|
152
156
|
mode?: "line" | "candle";
|
|
153
157
|
/** Committed OHLC bars (sorted by time). Used when mode is `"candle"`. */
|
|
@@ -207,6 +211,12 @@ export function tickLiveChartEngineFrame(
|
|
|
207
211
|
"worklet";
|
|
208
212
|
const baseNow = input.nowOverride ?? input.nowSeconds ?? Date.now() / 1000;
|
|
209
213
|
const liveEdge = baseNow + (input.windowBuffer ?? 0) * input.timeWindow;
|
|
214
|
+
const targetWindow = input.viewWindow ?? input.timeWindow;
|
|
215
|
+
// Keep clock rounding below half a pixel of the displayed window as it
|
|
216
|
+
// changes. Using only the target window during expansion can leave "now"
|
|
217
|
+
// several visible pixels past the edge and hide a live marker.
|
|
218
|
+
const timestampSecondsPerPixel =
|
|
219
|
+
Math.min(state.displayWindow, targetWindow) / input.canvasWidth;
|
|
210
220
|
const viewEnd = input.viewEnd;
|
|
211
221
|
// First time of the visible series' data — the floor a frozen edge must stay
|
|
212
222
|
// at or above. `-Infinity` when there's no data to bound against, so the freeze
|
|
@@ -238,7 +248,7 @@ export function tickLiveChartEngineFrame(
|
|
|
238
248
|
? advanceTimestampByPixel(
|
|
239
249
|
state.liveEdge,
|
|
240
250
|
liveEdge,
|
|
241
|
-
|
|
251
|
+
timestampSecondsPerPixel,
|
|
242
252
|
)
|
|
243
253
|
: liveEdge;
|
|
244
254
|
if (scrolledBack) {
|
|
@@ -260,7 +270,7 @@ export function tickLiveChartEngineFrame(
|
|
|
260
270
|
state.timestamp = advanceTimestampByPixel(
|
|
261
271
|
state.timestamp,
|
|
262
272
|
liveEdge,
|
|
263
|
-
|
|
273
|
+
timestampSecondsPerPixel,
|
|
264
274
|
);
|
|
265
275
|
} else {
|
|
266
276
|
state.timestamp = liveEdge;
|
|
@@ -304,8 +314,8 @@ export function tickLiveChartEngineFrame(
|
|
|
304
314
|
|
|
305
315
|
// Pinch-zoom: ease toward the zoom override when set, else the configured
|
|
306
316
|
// window. Mirrors the viewEnd freeze above (width vs. right edge).
|
|
307
|
-
|
|
308
|
-
|
|
317
|
+
state.displayWindow = snap ||
|
|
318
|
+
(input.viewWindow != null && input.viewWindowSmoothing === false)
|
|
309
319
|
? targetWindow
|
|
310
320
|
: lerpAndSettle(
|
|
311
321
|
state.displayWindow,
|
|
@@ -445,6 +455,41 @@ export function tickLiveChartEngineFrame(
|
|
|
445
455
|
tMax += margin;
|
|
446
456
|
}
|
|
447
457
|
|
|
458
|
+
const floorRange = input.minRange;
|
|
459
|
+
// Compare the bounded fit: a clamp can shrink an otherwise wider range.
|
|
460
|
+
// Slide a widened fit off either bound; both hard bounds win if the floor
|
|
461
|
+
// cannot fit between them. Resolve this before the optional manual zoom.
|
|
462
|
+
if (floorRange !== undefined && floorRange > 0 && Number.isFinite(floorRange)) {
|
|
463
|
+
const boundedMin = input.nonNegative && tMin < 0 ? 0 : tMin;
|
|
464
|
+
const boundedMax =
|
|
465
|
+
input.maxValue !== undefined && tMax > input.maxValue ? input.maxValue : tMax;
|
|
466
|
+
if (floorRange > boundedMax - boundedMin) {
|
|
467
|
+
// Halve before adding so large finite prices cannot overflow the midpoint.
|
|
468
|
+
const mid = tMin / 2 + tMax / 2;
|
|
469
|
+
let nextMin = mid - floorRange / 2;
|
|
470
|
+
let nextMax = mid + floorRange / 2;
|
|
471
|
+
if (input.nonNegative && nextMin < 0) {
|
|
472
|
+
nextMax -= nextMin;
|
|
473
|
+
nextMin = 0;
|
|
474
|
+
}
|
|
475
|
+
if (input.maxValue !== undefined && nextMax > input.maxValue) {
|
|
476
|
+
nextMin -= nextMax - input.maxValue;
|
|
477
|
+
nextMax = input.maxValue;
|
|
478
|
+
}
|
|
479
|
+
if (input.nonNegative && nextMin < 0) nextMin = 0;
|
|
480
|
+
// Ignore a floor that would overflow or round the bounds onto each other.
|
|
481
|
+
if (
|
|
482
|
+
Number.isFinite(nextMin) &&
|
|
483
|
+
Number.isFinite(nextMax) &&
|
|
484
|
+
nextMin < nextMax &&
|
|
485
|
+
Number.isFinite(nextMax - nextMin)
|
|
486
|
+
) {
|
|
487
|
+
tMin = nextMin;
|
|
488
|
+
tMax = nextMax;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
448
493
|
// Treat malformed gesture output as auto-fit. A zero/negative multiplier
|
|
449
494
|
// collapses or inverts the range; a non-finite/overflowing one poisons every
|
|
450
495
|
// downstream price-to-Y projection. Keep the guard here on the UI thread so
|