react-native-livechart 4.25.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 +6 -1
- package/dist/core/liveChartEngineTick.d.ts.map +1 -1
- package/dist/core/liveChartSeriesEngineTick.d.ts +4 -1
- 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 +10 -1
- package/dist/core/useLiveChartEngine.d.ts.map +1 -1
- package/dist/core/useLiveChartSeriesEngine.d.ts +5 -1
- 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 +24 -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 +23 -7
- 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/useReferenceLineGrouping.d.ts +19 -0
- package/dist/hooks/useReferenceLineGrouping.d.ts.map +1 -0
- 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/rangeAnimation.d.ts +4 -0
- package/dist/math/rangeAnimation.d.ts.map +1 -0
- package/dist/math/referenceDrag.d.ts +17 -5
- package/dist/math/referenceDrag.d.ts.map +1 -1
- package/dist/math/referenceGroup.d.ts +2 -2
- 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 +240 -30
- 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 +563 -200
- package/src/components/LiveChartSeries.tsx +117 -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 +66 -10
- package/src/core/liveChartSeriesEngineTick.ts +55 -5
- package/src/core/resolveConfig.ts +95 -2
- package/src/core/useLiveChartEngine.ts +53 -11
- package/src/core/useLiveChartSeriesEngine.ts +11 -1
- package/src/draw/grid.ts +2 -2
- package/src/draw/line.ts +23 -1
- package/src/hooks/crosshairShared.ts +85 -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 +446 -300
- 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 +395 -146
- package/src/hooks/useReferenceLine.ts +453 -277
- package/src/hooks/useReferenceLineGrouping.ts +72 -0
- 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 +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/rangeAnimation.ts +28 -0
- package/src/math/referenceDrag.ts +21 -4
- package/src/math/referenceGroup.ts +2 -2
- package/src/math/referenceTagStack.ts +112 -0
- package/src/math/scrubMarkers.ts +55 -0
- package/src/types.ts +246 -30
|
@@ -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 {
|
|
55
|
-
|
|
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
|
|
@@ -159,9 +201,11 @@ function resolveLiveChartSeriesInputs({
|
|
|
159
201
|
transitions,
|
|
160
202
|
snapKey,
|
|
161
203
|
smoothing = 0.08,
|
|
204
|
+
rangeAnimation,
|
|
162
205
|
exaggerate = false,
|
|
163
206
|
nonNegative = false,
|
|
164
207
|
maxValue,
|
|
208
|
+
minRange,
|
|
165
209
|
yRangeScale,
|
|
166
210
|
windowBuffer = 0,
|
|
167
211
|
nowOverride,
|
|
@@ -233,6 +277,10 @@ function resolveLiveChartSeriesInputs({
|
|
|
233
277
|
: (scrubCfg?.panGestureDelay ?? 0);
|
|
234
278
|
const selectionDotCfg = resolveSelectionDot(selectionDot ?? false);
|
|
235
279
|
const gridStyleCfg = resolveGridStyle(gridStyle);
|
|
280
|
+
const xGridStyleCfg = resolveXAxisGridStyle(
|
|
281
|
+
xAxisCfg?.gridLines ?? null,
|
|
282
|
+
gridStyleCfg,
|
|
283
|
+
);
|
|
236
284
|
const dotCfg = resolveMultiSeriesDot(dotProp);
|
|
237
285
|
const dotOuterRadius = Math.max(
|
|
238
286
|
dotCfg.radius + (dotCfg.ring?.width ?? 0),
|
|
@@ -276,9 +324,11 @@ function resolveLiveChartSeriesInputs({
|
|
|
276
324
|
transitions,
|
|
277
325
|
snapKey,
|
|
278
326
|
smoothing,
|
|
327
|
+
rangeAnimation,
|
|
279
328
|
exaggerate,
|
|
280
329
|
nonNegative,
|
|
281
330
|
maxValue,
|
|
331
|
+
minRange,
|
|
282
332
|
yRangeScale,
|
|
283
333
|
windowBuffer,
|
|
284
334
|
nowOverride,
|
|
@@ -304,6 +354,7 @@ function resolveLiveChartSeriesInputs({
|
|
|
304
354
|
scrubHoldMs,
|
|
305
355
|
selectionDotCfg,
|
|
306
356
|
gridStyleCfg,
|
|
357
|
+
xGridStyleCfg,
|
|
307
358
|
dotCfg,
|
|
308
359
|
dotOuterRadius,
|
|
309
360
|
legendCfg,
|
|
@@ -352,8 +403,6 @@ function resolveSeriesSnapshotLayout(
|
|
|
352
403
|
return {
|
|
353
404
|
maxLabelWidth,
|
|
354
405
|
labelInset: dot.valueLabel ? dotOuterRadius + 8 + maxLabelWidth + 8 : 0,
|
|
355
|
-
representativeValue:
|
|
356
|
-
snapshot.length > 0 ? Math.max(...snapshot.map((item) => item.value)) : 0,
|
|
357
406
|
colors: resolveMultiSeriesLineColorsSnapshot(snapshot),
|
|
358
407
|
styles: resolveMultiSeriesLineStylesSnapshot(snapshot),
|
|
359
408
|
};
|
|
@@ -398,9 +447,11 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
398
447
|
transitions,
|
|
399
448
|
snapKey,
|
|
400
449
|
smoothing,
|
|
450
|
+
rangeAnimation,
|
|
401
451
|
exaggerate,
|
|
402
452
|
nonNegative,
|
|
403
453
|
maxValue,
|
|
454
|
+
minRange,
|
|
404
455
|
yRangeScale,
|
|
405
456
|
windowBuffer,
|
|
406
457
|
nowOverride,
|
|
@@ -426,6 +477,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
426
477
|
scrubHoldMs,
|
|
427
478
|
selectionDotCfg,
|
|
428
479
|
gridStyleCfg,
|
|
480
|
+
xGridStyleCfg,
|
|
429
481
|
dotCfg,
|
|
430
482
|
dotOuterRadius,
|
|
431
483
|
legendCfg,
|
|
@@ -473,6 +525,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
473
525
|
// rendering. The animated reaction below emits the initial snapshot and every
|
|
474
526
|
// subsequent configuration change without reading the SharedValue in render.
|
|
475
527
|
const [seriesSnapshot, setSeriesSnapshot] = useState<SeriesConfig[]>([]);
|
|
528
|
+
const valueLayoutSample = useSeriesLayoutValueSample(series);
|
|
476
529
|
|
|
477
530
|
// Mount per-series drawing worklets only for real series. The previous fixed
|
|
478
531
|
// 12-slot render kept 144 derived-value mappers alive for the default stroke,
|
|
@@ -482,7 +535,6 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
482
535
|
const {
|
|
483
536
|
maxLabelWidth: maxSeriesLabelWidth,
|
|
484
537
|
labelInset: seriesLabelInset,
|
|
485
|
-
representativeValue,
|
|
486
538
|
colors: lineColors,
|
|
487
539
|
styles: lineStyles,
|
|
488
540
|
} = resolveSeriesSnapshotLayout(
|
|
@@ -497,12 +549,12 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
497
549
|
lineWidthOverride: lineProp?.width,
|
|
498
550
|
insetsOverride: insets,
|
|
499
551
|
yAxis: yAxisCfg !== null,
|
|
500
|
-
badge:
|
|
552
|
+
badge: allRefLines.some(line => typeof line.valueBadge === "object" && line.valueBadge.position === "axis"),
|
|
501
553
|
badgeMetrics: metricsCfg.badge,
|
|
502
554
|
xAxis: xAxisCfg !== null,
|
|
503
555
|
font: skiaFont,
|
|
504
556
|
formatValue,
|
|
505
|
-
currentValue:
|
|
557
|
+
currentValue: valueLayoutSample,
|
|
506
558
|
pulse: dotCfg.pulse,
|
|
507
559
|
dotGlow: dotCfg.glow,
|
|
508
560
|
multiSeriesDotRadius: dotOuterRadius,
|
|
@@ -541,6 +593,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
541
593
|
morphT: reveal.morphT,
|
|
542
594
|
});
|
|
543
595
|
|
|
596
|
+
const effectiveYRangeScale = useYAxisScaleValue(yRangeScale);
|
|
544
597
|
const engine = useLiveChartSeriesEngine({
|
|
545
598
|
series: effectiveSeries,
|
|
546
599
|
timeWindow,
|
|
@@ -550,12 +603,14 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
550
603
|
allowFutureViewEnd: timeScrollOverscroll > 0,
|
|
551
604
|
returnToLiveMs,
|
|
552
605
|
smoothing,
|
|
606
|
+
rangeAnimation,
|
|
553
607
|
adaptiveSpeedBoost: metricsCfg.motion.adaptiveSpeedBoost,
|
|
554
608
|
exaggerate,
|
|
555
609
|
referenceValues: refValues,
|
|
556
610
|
nonNegative,
|
|
557
611
|
maxValue,
|
|
558
|
-
|
|
612
|
+
minRange,
|
|
613
|
+
yRangeScale: effectiveYRangeScale,
|
|
559
614
|
windowBuffer,
|
|
560
615
|
nowOverride,
|
|
561
616
|
});
|
|
@@ -566,6 +621,13 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
566
621
|
activeSeriesCount,
|
|
567
622
|
lineProp?.simplify,
|
|
568
623
|
);
|
|
624
|
+
const seriesClip = useDerivedValue(() =>
|
|
625
|
+
seriesPlotClip(
|
|
626
|
+
effectivePadding,
|
|
627
|
+
engine.canvasWidth.get(),
|
|
628
|
+
engine.canvasHeight.get(),
|
|
629
|
+
),
|
|
630
|
+
);
|
|
569
631
|
|
|
570
632
|
// Read the `series` prop from closure, not a SharedValue passed through
|
|
571
633
|
// `scheduleOnRN`: the handle serialized across the worklet→JS boundary keeps
|
|
@@ -607,6 +669,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
607
669
|
effectivePadding,
|
|
608
670
|
formatTime,
|
|
609
671
|
skiaFont,
|
|
672
|
+
xAxisCfg?.minGap,
|
|
610
673
|
);
|
|
611
674
|
|
|
612
675
|
// Cross-gesture arbitration for the one-finger touch. `Gesture.Race` below is
|
|
@@ -616,6 +679,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
616
679
|
// long-press guard) makes "the scroll already won" a hard fact; `scrubActive`
|
|
617
680
|
// (written by the crosshair, read by the scroll pan) is the mirror image.
|
|
618
681
|
const scrollActive = useSharedValue(false);
|
|
682
|
+
const axisScaleActive = useSharedValue(false);
|
|
619
683
|
// `liveEdge` includes the optional right breathing-room buffer. The time pill
|
|
620
684
|
// must clamp against the real "now" anchor so its live bucket never ends in
|
|
621
685
|
// that future buffer.
|
|
@@ -643,6 +707,8 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
643
707
|
}
|
|
644
708
|
: undefined,
|
|
645
709
|
scrubCfg?.clampToPlot ?? false,
|
|
710
|
+
resolveScrubMarkerOptions(scrubCfg, markersSV),
|
|
711
|
+
axisScaleActive,
|
|
646
712
|
);
|
|
647
713
|
|
|
648
714
|
// Capture only the shared value in the worklets below. Referencing
|
|
@@ -653,7 +719,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
653
719
|
|
|
654
720
|
// `projected` is used internally by the hit-test gesture; the overlay
|
|
655
721
|
// self-projects, so we only need the gesture here.
|
|
656
|
-
const { tapGesture: markerTapGesture } = useMarkers(
|
|
722
|
+
const { tapGesture: markerTapGesture, hitTest: markerHitTest } = useMarkers(
|
|
657
723
|
engine,
|
|
658
724
|
effectivePadding,
|
|
659
725
|
markersSV,
|
|
@@ -720,7 +786,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
720
786
|
onReachStart,
|
|
721
787
|
});
|
|
722
788
|
|
|
723
|
-
const
|
|
789
|
+
const plotGesture = composeSeriesRootGesture(
|
|
724
790
|
crosshair.gesture,
|
|
725
791
|
markerTapGesture,
|
|
726
792
|
panScrollGesture,
|
|
@@ -731,6 +797,23 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
731
797
|
scrollGestureMode,
|
|
732
798
|
);
|
|
733
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
|
+
|
|
734
817
|
const backgroundColor = `rgb(${palette.bgRgb[0]}, ${palette.bgRgb[1]}, ${palette.bgRgb[2]})`;
|
|
735
818
|
|
|
736
819
|
// Fade markers + reference lines out while scrubbing when
|
|
@@ -768,6 +851,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
768
851
|
scrubCfg,
|
|
769
852
|
seriesTooltipCfg,
|
|
770
853
|
gridStyleCfg,
|
|
854
|
+
xGridStyleCfg,
|
|
771
855
|
dotCfg,
|
|
772
856
|
dotOuterRadius,
|
|
773
857
|
legendCfg,
|
|
@@ -782,6 +866,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
782
866
|
// theme / layout / fonts
|
|
783
867
|
palette,
|
|
784
868
|
skiaFont,
|
|
869
|
+
fontProp,
|
|
785
870
|
seriesLabelInset,
|
|
786
871
|
strokeWidth,
|
|
787
872
|
effectivePadding,
|
|
@@ -800,6 +885,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
800
885
|
layoutHeight,
|
|
801
886
|
onLayout,
|
|
802
887
|
linePaths,
|
|
888
|
+
seriesClip,
|
|
803
889
|
activeSeriesCount,
|
|
804
890
|
lineColors,
|
|
805
891
|
lineStyles,
|
|
@@ -897,6 +983,7 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
|
|
|
897
983
|
lineStyles,
|
|
898
984
|
xAxisCfg,
|
|
899
985
|
xAxisEntries,
|
|
986
|
+
xGridStyleCfg,
|
|
900
987
|
degenCfg,
|
|
901
988
|
degenPack,
|
|
902
989
|
degenPackRevision,
|
|
@@ -920,6 +1007,7 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
|
|
|
920
1007
|
canvasMode,
|
|
921
1008
|
activeSeriesCount,
|
|
922
1009
|
refLineKeys,
|
|
1010
|
+
seriesClip,
|
|
923
1011
|
} = model;
|
|
924
1012
|
|
|
925
1013
|
return (
|
|
@@ -929,6 +1017,18 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
|
|
|
929
1017
|
variant={yAxisCfg?.side === "left" ? "grid" : "all"}
|
|
930
1018
|
/>
|
|
931
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
|
+
|
|
932
1032
|
{/* Fade group lets `scrub.hideOverlaysOnScrub` ease the lines out. Explicit
|
|
933
1033
|
ids keep each reference line mounted when the caller reorders it. */}
|
|
934
1034
|
<Group opacity={overlayScrubFade}>
|
|
@@ -938,6 +1038,8 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
|
|
|
938
1038
|
engine={engine}
|
|
939
1039
|
padding={effectivePadding}
|
|
940
1040
|
line={rl}
|
|
1041
|
+
valueAxis={{ metrics: model.metricsCfg.badge, fontSize: skiaFont.getSize() }}
|
|
1042
|
+
fontProp={model.fontProp}
|
|
941
1043
|
palette={palette}
|
|
942
1044
|
formatValue={formatValue}
|
|
943
1045
|
font={skiaFont}
|
|
@@ -961,7 +1063,7 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
|
|
|
961
1063
|
</Group>
|
|
962
1064
|
)}
|
|
963
1065
|
|
|
964
|
-
<Group opacity={reveal.lineOpacity}>
|
|
1066
|
+
<Group opacity={reveal.lineOpacity} clip={seriesClip}>
|
|
965
1067
|
{Array.from({ length: activeSeriesCount }, (_, i) => (
|
|
966
1068
|
<MultiSeriesStroke
|
|
967
1069
|
key={i}
|
|
@@ -1126,6 +1228,8 @@ function SeriesRefBadgeLayer({ model }: { model: LiveChartSeriesModel }) {
|
|
|
1126
1228
|
engine={engine}
|
|
1127
1229
|
padding={effectivePadding}
|
|
1128
1230
|
line={rl}
|
|
1231
|
+
valueAxis={{ metrics: model.metricsCfg.badge, fontSize: skiaFont.getSize() }}
|
|
1232
|
+
fontProp={model.fontProp}
|
|
1129
1233
|
palette={palette}
|
|
1130
1234
|
formatValue={formatValue}
|
|
1131
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
|
-
|
|
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
|
+
}
|