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
|
@@ -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,23 +47,33 @@ 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
|
+
shouldMeasureYAxisLabels,
|
|
63
|
+
shouldResampleLayoutValue,
|
|
64
|
+
} from "../hooks/resolveChartLayout";
|
|
56
65
|
import { useCanvasLayout } from "../hooks/useCanvasLayout";
|
|
57
66
|
import { useChartReveal } from "../hooks/useChartReveal";
|
|
58
67
|
import { useChartOverlayContext } from "../hooks/useChartOverlayContext";
|
|
59
68
|
import { useChartSkiaFont } from "../hooks/useChartSkiaFont";
|
|
60
69
|
import { useCrosshairSeries } from "../hooks/useCrosshairSeries";
|
|
70
|
+
import { resolveScrubMarkerOptions } from "../hooks/useScrubMarkers";
|
|
61
71
|
import { useCrosshairVisibleOpacity } from "../hooks/useCrosshairVisibleOpacity";
|
|
62
72
|
import { useLoadingLook } from "../hooks/useLoadingLook";
|
|
63
73
|
import { useMarkers } from "../hooks/useMarkers";
|
|
64
74
|
import { useMultiSeriesDegen } from "../hooks/useMultiSeriesDegen";
|
|
65
75
|
import { useMultiSeriesLinePaths } from "../hooks/useMultiSeriesLinePaths";
|
|
66
|
-
import { usePanScroll } from "../hooks/usePanScroll";
|
|
76
|
+
import { AXIS_GRAB_MIN_PX, usePanScroll } from "../hooks/usePanScroll";
|
|
67
77
|
import { resetPinchZoom, usePinchZoom } from "../hooks/usePinchZoom";
|
|
68
78
|
import { useMultiSeriesReverseMorphInputs } from "../hooks/useReverseMorphEngineInputs";
|
|
69
79
|
import {
|
|
@@ -72,7 +82,12 @@ import {
|
|
|
72
82
|
} from "../hooks/useSeriesIndicatorOpacity";
|
|
73
83
|
import { useVisibleRange } from "../hooks/useVisibleRange";
|
|
74
84
|
import { useXAxis } from "../hooks/useXAxis";
|
|
85
|
+
import { useYAxisLabelWidth } from "../hooks/useYAxisLabelWidth";
|
|
75
86
|
import { useYAxis } from "../hooks/useYAxis";
|
|
87
|
+
import {
|
|
88
|
+
useYAxisScaleGesture,
|
|
89
|
+
useYAxisScaleValue,
|
|
90
|
+
} from "../hooks/useYAxisScaleGesture";
|
|
76
91
|
import {
|
|
77
92
|
formatTime as defaultFormatTime,
|
|
78
93
|
formatValue as defaultFormatValue,
|
|
@@ -117,7 +132,7 @@ import { MultiSeriesValueLines } from "./MultiSeriesValueLines";
|
|
|
117
132
|
import { PerSeriesTooltipOverlay } from "./PerSeriesTooltipOverlay";
|
|
118
133
|
import { ReferenceLineOverlay } from "./ReferenceLineOverlay";
|
|
119
134
|
import { SeriesToggleChips } from "./SeriesToggleChips";
|
|
120
|
-
import { XAxisOverlay } from "./XAxisOverlay";
|
|
135
|
+
import { XAxisGridLines, XAxisOverlay } from "./XAxisOverlay";
|
|
121
136
|
import { YAxisOverlay } from "./YAxisOverlay";
|
|
122
137
|
|
|
123
138
|
/**
|
|
@@ -138,6 +153,35 @@ function seriesConfigSig(s: SharedValue<SeriesConfig[]>) {
|
|
|
138
153
|
return out;
|
|
139
154
|
}
|
|
140
155
|
|
|
156
|
+
/** Largest finite magnitude — zeros and invalid placeholders cannot mask it. */
|
|
157
|
+
function seriesLayoutValue(s: SharedValue<SeriesConfig[]>) {
|
|
158
|
+
"worklet";
|
|
159
|
+
const arr = s.value;
|
|
160
|
+
let sample = 0;
|
|
161
|
+
for (let i = 0; i < arr.length; i++) {
|
|
162
|
+
const value = arr[i].value;
|
|
163
|
+
if (Number.isFinite(value) && Math.abs(value) > Math.abs(sample)) {
|
|
164
|
+
sample = value;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return sample;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function useSeriesLayoutValueSample(series: SharedValue<SeriesConfig[]>) {
|
|
171
|
+
const [sample, setSample] = useState<number | undefined>(undefined);
|
|
172
|
+
const sampled = useSharedValue(0);
|
|
173
|
+
useAnimatedReaction(
|
|
174
|
+
() => seriesLayoutValue(series),
|
|
175
|
+
(current) => {
|
|
176
|
+
if (!shouldResampleLayoutValue(current, sampled.get())) return;
|
|
177
|
+
sampled.set(current);
|
|
178
|
+
scheduleOnRN(setSample, current);
|
|
179
|
+
},
|
|
180
|
+
[sampled, series],
|
|
181
|
+
);
|
|
182
|
+
return sample;
|
|
183
|
+
}
|
|
184
|
+
|
|
141
185
|
/**
|
|
142
186
|
* Resolves props → configs → theme/layout → engine → per-frame derived values,
|
|
143
187
|
* overlay hooks and the color/style reaction state, returning a single render
|
|
@@ -163,9 +207,12 @@ function resolveLiveChartSeriesInputs({
|
|
|
163
207
|
exaggerate = false,
|
|
164
208
|
nonNegative = false,
|
|
165
209
|
maxValue,
|
|
210
|
+
minRange,
|
|
166
211
|
yRangeScale,
|
|
167
212
|
windowBuffer = 0,
|
|
168
213
|
nowOverride,
|
|
214
|
+
presentationTime,
|
|
215
|
+
historyStartTime,
|
|
169
216
|
accessibilityLabel,
|
|
170
217
|
accessibilityRole = "image",
|
|
171
218
|
emptyText = "No data",
|
|
@@ -234,6 +281,10 @@ function resolveLiveChartSeriesInputs({
|
|
|
234
281
|
: (scrubCfg?.panGestureDelay ?? 0);
|
|
235
282
|
const selectionDotCfg = resolveSelectionDot(selectionDot ?? false);
|
|
236
283
|
const gridStyleCfg = resolveGridStyle(gridStyle);
|
|
284
|
+
const xGridStyleCfg = resolveXAxisGridStyle(
|
|
285
|
+
xAxisCfg?.gridLines ?? null,
|
|
286
|
+
gridStyleCfg,
|
|
287
|
+
);
|
|
237
288
|
const dotCfg = resolveMultiSeriesDot(dotProp);
|
|
238
289
|
const dotOuterRadius = Math.max(
|
|
239
290
|
dotCfg.radius + (dotCfg.ring?.width ?? 0),
|
|
@@ -281,9 +332,12 @@ function resolveLiveChartSeriesInputs({
|
|
|
281
332
|
exaggerate,
|
|
282
333
|
nonNegative,
|
|
283
334
|
maxValue,
|
|
335
|
+
minRange,
|
|
284
336
|
yRangeScale,
|
|
285
337
|
windowBuffer,
|
|
286
338
|
nowOverride,
|
|
339
|
+
presentationTime,
|
|
340
|
+
historyStartTime,
|
|
287
341
|
accessibilityLabel,
|
|
288
342
|
accessibilityRole,
|
|
289
343
|
emptyText,
|
|
@@ -306,6 +360,7 @@ function resolveLiveChartSeriesInputs({
|
|
|
306
360
|
scrubHoldMs,
|
|
307
361
|
selectionDotCfg,
|
|
308
362
|
gridStyleCfg,
|
|
363
|
+
xGridStyleCfg,
|
|
309
364
|
dotCfg,
|
|
310
365
|
dotOuterRadius,
|
|
311
366
|
legendCfg,
|
|
@@ -354,8 +409,6 @@ function resolveSeriesSnapshotLayout(
|
|
|
354
409
|
return {
|
|
355
410
|
maxLabelWidth,
|
|
356
411
|
labelInset: dot.valueLabel ? dotOuterRadius + 8 + maxLabelWidth + 8 : 0,
|
|
357
|
-
representativeValue:
|
|
358
|
-
snapshot.length > 0 ? Math.max(...snapshot.map((item) => item.value)) : 0,
|
|
359
412
|
colors: resolveMultiSeriesLineColorsSnapshot(snapshot),
|
|
360
413
|
styles: resolveMultiSeriesLineStylesSnapshot(snapshot),
|
|
361
414
|
};
|
|
@@ -404,9 +457,12 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
404
457
|
exaggerate,
|
|
405
458
|
nonNegative,
|
|
406
459
|
maxValue,
|
|
460
|
+
minRange,
|
|
407
461
|
yRangeScale,
|
|
408
462
|
windowBuffer,
|
|
409
463
|
nowOverride,
|
|
464
|
+
presentationTime,
|
|
465
|
+
historyStartTime,
|
|
410
466
|
accessibilityLabel,
|
|
411
467
|
accessibilityRole,
|
|
412
468
|
emptyText,
|
|
@@ -429,6 +485,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
429
485
|
scrubHoldMs,
|
|
430
486
|
selectionDotCfg,
|
|
431
487
|
gridStyleCfg,
|
|
488
|
+
xGridStyleCfg,
|
|
432
489
|
dotCfg,
|
|
433
490
|
dotOuterRadius,
|
|
434
491
|
legendCfg,
|
|
@@ -476,6 +533,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
476
533
|
// rendering. The animated reaction below emits the initial snapshot and every
|
|
477
534
|
// subsequent configuration change without reading the SharedValue in render.
|
|
478
535
|
const [seriesSnapshot, setSeriesSnapshot] = useState<SeriesConfig[]>([]);
|
|
536
|
+
const valueLayoutSample = useSeriesLayoutValueSample(series);
|
|
479
537
|
|
|
480
538
|
// Mount per-series drawing worklets only for real series. The previous fixed
|
|
481
539
|
// 12-slot render kept 144 derived-value mappers alive for the default stroke,
|
|
@@ -485,7 +543,6 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
485
543
|
const {
|
|
486
544
|
maxLabelWidth: maxSeriesLabelWidth,
|
|
487
545
|
labelInset: seriesLabelInset,
|
|
488
|
-
representativeValue,
|
|
489
546
|
colors: lineColors,
|
|
490
547
|
styles: lineStyles,
|
|
491
548
|
} = resolveSeriesSnapshotLayout(
|
|
@@ -495,17 +552,22 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
495
552
|
skiaFont,
|
|
496
553
|
);
|
|
497
554
|
|
|
555
|
+
const [yAxisLabelWidth, setYAxisLabelWidth] = useState<number | undefined>();
|
|
556
|
+
const measureYAxisLabels = shouldMeasureYAxisLabels(yAxisCfg, insets?.right);
|
|
498
557
|
const { strokeWidth, padding: effectivePadding } = resolveChartLayout({
|
|
499
558
|
palette,
|
|
500
559
|
lineWidthOverride: lineProp?.width,
|
|
501
560
|
insetsOverride: insets,
|
|
502
561
|
yAxis: yAxisCfg !== null,
|
|
503
|
-
|
|
562
|
+
labelRightMargin: measureYAxisLabels ? yAxisCfg?.labelRightMargin : undefined,
|
|
563
|
+
yAxisLabelWidth,
|
|
564
|
+
dotRadius: dotOuterRadius,
|
|
565
|
+
badge: allRefLines.some(line => typeof line.valueBadge === "object" && line.valueBadge.position === "axis"),
|
|
504
566
|
badgeMetrics: metricsCfg.badge,
|
|
505
567
|
xAxis: xAxisCfg !== null,
|
|
506
568
|
font: skiaFont,
|
|
507
569
|
formatValue,
|
|
508
|
-
currentValue:
|
|
570
|
+
currentValue: valueLayoutSample,
|
|
509
571
|
pulse: dotCfg.pulse,
|
|
510
572
|
dotGlow: dotCfg.glow,
|
|
511
573
|
multiSeriesDotRadius: dotOuterRadius,
|
|
@@ -544,6 +606,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
544
606
|
morphT: reveal.morphT,
|
|
545
607
|
});
|
|
546
608
|
|
|
609
|
+
const effectiveYRangeScale = useYAxisScaleValue(yRangeScale);
|
|
547
610
|
const engine = useLiveChartSeriesEngine({
|
|
548
611
|
series: effectiveSeries,
|
|
549
612
|
timeWindow,
|
|
@@ -559,9 +622,12 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
559
622
|
referenceValues: refValues,
|
|
560
623
|
nonNegative,
|
|
561
624
|
maxValue,
|
|
562
|
-
|
|
625
|
+
minRange,
|
|
626
|
+
yRangeScale: effectiveYRangeScale,
|
|
563
627
|
windowBuffer,
|
|
564
628
|
nowOverride,
|
|
629
|
+
presentationTime,
|
|
630
|
+
historyStartTime,
|
|
565
631
|
});
|
|
566
632
|
const { layoutHeight, onLayout } = useCanvasLayout(engine);
|
|
567
633
|
const linePaths = useMultiSeriesLinePaths(
|
|
@@ -570,6 +636,13 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
570
636
|
activeSeriesCount,
|
|
571
637
|
lineProp?.simplify,
|
|
572
638
|
);
|
|
639
|
+
const seriesClip = useDerivedValue(() =>
|
|
640
|
+
seriesPlotClip(
|
|
641
|
+
effectivePadding,
|
|
642
|
+
engine.canvasWidth.get(),
|
|
643
|
+
engine.canvasHeight.get(),
|
|
644
|
+
),
|
|
645
|
+
);
|
|
573
646
|
|
|
574
647
|
// Read the `series` prop from closure, not a SharedValue passed through
|
|
575
648
|
// `scheduleOnRN`: the handle serialized across the worklet→JS boundary keeps
|
|
@@ -606,11 +679,14 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
606
679
|
yAxisCfg?.intervalScale ?? 1,
|
|
607
680
|
);
|
|
608
681
|
|
|
682
|
+
useYAxisLabelWidth(yAxisEntries, skiaFont, measureYAxisLabels, setYAxisLabelWidth);
|
|
683
|
+
|
|
609
684
|
const { xAxisEntries } = useXAxis(
|
|
610
685
|
engine,
|
|
611
686
|
effectivePadding,
|
|
612
687
|
formatTime,
|
|
613
688
|
skiaFont,
|
|
689
|
+
xAxisCfg?.minGap,
|
|
614
690
|
);
|
|
615
691
|
|
|
616
692
|
// Cross-gesture arbitration for the one-finger touch. `Gesture.Race` below is
|
|
@@ -620,11 +696,10 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
620
696
|
// long-press guard) makes "the scroll already won" a hard fact; `scrubActive`
|
|
621
697
|
// (written by the crosshair, read by the scroll pan) is the mirror image.
|
|
622
698
|
const scrollActive = useSharedValue(false);
|
|
623
|
-
|
|
624
|
-
//
|
|
625
|
-
// that future buffer.
|
|
699
|
+
const axisScaleActive = useSharedValue(false);
|
|
700
|
+
// The tooltip shares the crosshair/path cutoff, including historical edges.
|
|
626
701
|
const tooltipMaxTime = useDerivedValue(
|
|
627
|
-
() => engine.
|
|
702
|
+
() => engine.tipTime?.get() ?? engine.currentTime.get(),
|
|
628
703
|
);
|
|
629
704
|
|
|
630
705
|
const crosshair = useCrosshairSeries(
|
|
@@ -647,6 +722,11 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
647
722
|
}
|
|
648
723
|
: undefined,
|
|
649
724
|
scrubCfg?.clampToPlot ?? false,
|
|
725
|
+
resolveScrubMarkerOptions(scrubCfg, markersSV),
|
|
726
|
+
axisScaleActive,
|
|
727
|
+
timeScrollEnabled && scrollGestureMode === "axisDrag"
|
|
728
|
+
? Math.max(effectivePadding.bottom, AXIS_GRAB_MIN_PX)
|
|
729
|
+
: 0,
|
|
650
730
|
);
|
|
651
731
|
|
|
652
732
|
// Capture only the shared value in the worklets below. Referencing
|
|
@@ -657,7 +737,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
657
737
|
|
|
658
738
|
// `projected` is used internally by the hit-test gesture; the overlay
|
|
659
739
|
// self-projects, so we only need the gesture here.
|
|
660
|
-
const { tapGesture: markerTapGesture } = useMarkers(
|
|
740
|
+
const { tapGesture: markerTapGesture, hitTest: markerHitTest } = useMarkers(
|
|
661
741
|
engine,
|
|
662
742
|
effectivePadding,
|
|
663
743
|
markersSV,
|
|
@@ -676,7 +756,8 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
676
756
|
// scrollable history) so panning is a no-op.
|
|
677
757
|
const scrollMinTime = useDerivedValue(() => {
|
|
678
758
|
const s = engine.series.get();
|
|
679
|
-
let min =
|
|
759
|
+
let min = historyStartTime != null && Number.isFinite(historyStartTime)
|
|
760
|
+
? historyStartTime : Infinity;
|
|
680
761
|
for (let i = 0; i < s.length; i++) {
|
|
681
762
|
const d = s[i].data;
|
|
682
763
|
if (d.length > 0 && d[0].time < min) min = d[0].time;
|
|
@@ -707,6 +788,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
707
788
|
padding: effectivePadding,
|
|
708
789
|
minTime: scrollMinTime,
|
|
709
790
|
timeWindow,
|
|
791
|
+
fullHistoryWindow: engine.fullHistoryWindow,
|
|
710
792
|
enabled: zoomEnabled,
|
|
711
793
|
minTimeWindow: zoomCfg?.minTimeWindow,
|
|
712
794
|
maxTimeWindow: zoomCfg?.maxTimeWindow,
|
|
@@ -724,7 +806,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
724
806
|
onReachStart,
|
|
725
807
|
});
|
|
726
808
|
|
|
727
|
-
const
|
|
809
|
+
const plotGesture = composeSeriesRootGesture(
|
|
728
810
|
crosshair.gesture,
|
|
729
811
|
markerTapGesture,
|
|
730
812
|
panScrollGesture,
|
|
@@ -735,6 +817,23 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
735
817
|
scrollGestureMode,
|
|
736
818
|
);
|
|
737
819
|
|
|
820
|
+
const clearCrosshair = useCallback(() => {
|
|
821
|
+
"worklet";
|
|
822
|
+
crosshairScrubActive.set(false);
|
|
823
|
+
}, [crosshairScrubActive]);
|
|
824
|
+
const rootGesture = useYAxisScaleGesture({
|
|
825
|
+
engine,
|
|
826
|
+
padding: effectivePadding,
|
|
827
|
+
axis: yAxisCfg,
|
|
828
|
+
entries: yAxisEntries,
|
|
829
|
+
font: skiaFont,
|
|
830
|
+
scale: effectiveYRangeScale,
|
|
831
|
+
gesture: plotGesture,
|
|
832
|
+
deferHit: markerHitTest,
|
|
833
|
+
onStart: clearCrosshair,
|
|
834
|
+
active: axisScaleActive,
|
|
835
|
+
});
|
|
836
|
+
|
|
738
837
|
const backgroundColor = `rgb(${palette.bgRgb[0]}, ${palette.bgRgb[1]}, ${palette.bgRgb[2]})`;
|
|
739
838
|
|
|
740
839
|
// Fade markers + reference lines out while scrubbing when
|
|
@@ -772,6 +871,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
772
871
|
scrubCfg,
|
|
773
872
|
seriesTooltipCfg,
|
|
774
873
|
gridStyleCfg,
|
|
874
|
+
xGridStyleCfg,
|
|
775
875
|
dotCfg,
|
|
776
876
|
dotOuterRadius,
|
|
777
877
|
legendCfg,
|
|
@@ -786,6 +886,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
786
886
|
// theme / layout / fonts
|
|
787
887
|
palette,
|
|
788
888
|
skiaFont,
|
|
889
|
+
fontProp,
|
|
789
890
|
seriesLabelInset,
|
|
790
891
|
strokeWidth,
|
|
791
892
|
effectivePadding,
|
|
@@ -804,6 +905,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
804
905
|
layoutHeight,
|
|
805
906
|
onLayout,
|
|
806
907
|
linePaths,
|
|
908
|
+
seriesClip,
|
|
807
909
|
activeSeriesCount,
|
|
808
910
|
lineColors,
|
|
809
911
|
lineStyles,
|
|
@@ -901,6 +1003,7 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
|
|
|
901
1003
|
lineStyles,
|
|
902
1004
|
xAxisCfg,
|
|
903
1005
|
xAxisEntries,
|
|
1006
|
+
xGridStyleCfg,
|
|
904
1007
|
degenCfg,
|
|
905
1008
|
degenPack,
|
|
906
1009
|
degenPackRevision,
|
|
@@ -924,6 +1027,7 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
|
|
|
924
1027
|
canvasMode,
|
|
925
1028
|
activeSeriesCount,
|
|
926
1029
|
refLineKeys,
|
|
1030
|
+
seriesClip,
|
|
927
1031
|
} = model;
|
|
928
1032
|
|
|
929
1033
|
return (
|
|
@@ -933,6 +1037,18 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
|
|
|
933
1037
|
variant={yAxisCfg?.side === "left" ? "grid" : "all"}
|
|
934
1038
|
/>
|
|
935
1039
|
|
|
1040
|
+
{/* Vertical grid at the time ticks (`xAxis.gridLines`), behind the
|
|
1041
|
+
series like the horizontal grid. */}
|
|
1042
|
+
{xAxisCfg && xGridStyleCfg && (
|
|
1043
|
+
<XAxisGridLines
|
|
1044
|
+
entries={xAxisEntries}
|
|
1045
|
+
engine={engine}
|
|
1046
|
+
padding={effectivePadding}
|
|
1047
|
+
palette={palette}
|
|
1048
|
+
gridStyle={xGridStyleCfg}
|
|
1049
|
+
/>
|
|
1050
|
+
)}
|
|
1051
|
+
|
|
936
1052
|
{/* Fade group lets `scrub.hideOverlaysOnScrub` ease the lines out. Explicit
|
|
937
1053
|
ids keep each reference line mounted when the caller reorders it. */}
|
|
938
1054
|
<Group opacity={overlayScrubFade}>
|
|
@@ -942,6 +1058,8 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
|
|
|
942
1058
|
engine={engine}
|
|
943
1059
|
padding={effectivePadding}
|
|
944
1060
|
line={rl}
|
|
1061
|
+
valueAxis={{ metrics: model.metricsCfg.badge, fontSize: skiaFont.getSize() }}
|
|
1062
|
+
fontProp={model.fontProp}
|
|
945
1063
|
palette={palette}
|
|
946
1064
|
formatValue={formatValue}
|
|
947
1065
|
font={skiaFont}
|
|
@@ -965,7 +1083,7 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
|
|
|
965
1083
|
</Group>
|
|
966
1084
|
)}
|
|
967
1085
|
|
|
968
|
-
<Group opacity={reveal.lineOpacity}>
|
|
1086
|
+
<Group opacity={reveal.lineOpacity} clip={seriesClip}>
|
|
969
1087
|
{Array.from({ length: activeSeriesCount }, (_, i) => (
|
|
970
1088
|
<MultiSeriesStroke
|
|
971
1089
|
key={i}
|
|
@@ -1130,6 +1248,8 @@ function SeriesRefBadgeLayer({ model }: { model: LiveChartSeriesModel }) {
|
|
|
1130
1248
|
engine={engine}
|
|
1131
1249
|
padding={effectivePadding}
|
|
1132
1250
|
line={rl}
|
|
1251
|
+
valueAxis={{ metrics: model.metricsCfg.badge, fontSize: skiaFont.getSize() }}
|
|
1252
|
+
fontProp={model.fontProp}
|
|
1133
1253
|
palette={palette}
|
|
1134
1254
|
formatValue={formatValue}
|
|
1135
1255
|
font={skiaFont}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BlurMask, Circle, Group } from "@shopify/react-native-skia";
|
|
2
2
|
|
|
3
3
|
import { useDerivedValue, type SharedValue } from "react-native-reanimated";
|
|
4
|
-
import type
|
|
4
|
+
import { lineTipX, type ChartPadding } from "../draw/line";
|
|
5
5
|
import type {
|
|
6
6
|
ResolvedDotGlowConfig,
|
|
7
7
|
ResolvedDotRingConfig,
|
|
@@ -42,7 +42,7 @@ function SeriesDotAtIndex({
|
|
|
42
42
|
const dotX = useDerivedValue(() => {
|
|
43
43
|
const w = engine.canvasWidth.value;
|
|
44
44
|
if (w === 0) return -100;
|
|
45
|
-
return w
|
|
45
|
+
return lineTipX(engine.timestamp.get(), engine.displayWindow.get(), engine.tipTime?.get() ?? engine.timestamp.get(), w, padding);
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
const dotY = useDerivedValue(() => {
|
|
@@ -64,6 +64,8 @@ function SeriesDotAtIndex({
|
|
|
64
64
|
const s = engine.series.value;
|
|
65
65
|
const op = engine.seriesOpacities.value;
|
|
66
66
|
if (index >= s.length || index >= op.length) return 0;
|
|
67
|
+
const head = engine.tipTime?.get() ?? engine.timestamp.get();
|
|
68
|
+
if (s[index].data.length === 0 || s[index].data[0].time > head || head < engine.timestamp.get() - engine.displayWindow.get()) return 0;
|
|
67
69
|
return op[index] ?? 0;
|
|
68
70
|
});
|
|
69
71
|
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from "@shopify/react-native-skia";
|
|
6
6
|
import { useDerivedValue } from "react-native-reanimated";
|
|
7
7
|
|
|
8
|
-
import type
|
|
8
|
+
import { lineTipX, type ChartPadding } from "../draw/line";
|
|
9
9
|
import type { MultiEngineState } from "../core/useLiveChartEngine";
|
|
10
10
|
|
|
11
11
|
const LABEL_GAP = 8;
|
|
@@ -28,7 +28,7 @@ function SeriesValueLabelAtIndex({
|
|
|
28
28
|
const labelX = useDerivedValue(() => {
|
|
29
29
|
const w = engine.canvasWidth.value;
|
|
30
30
|
if (w === 0) return -200;
|
|
31
|
-
return
|
|
31
|
+
return lineTipX(engine.timestamp.get(), engine.displayWindow.get(), engine.tipTime?.get() ?? engine.timestamp.get(), w, padding) + dotRadius + LABEL_GAP;
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
const labelY = useDerivedValue(() => {
|
|
@@ -61,6 +61,8 @@ function SeriesValueLabelAtIndex({
|
|
|
61
61
|
const s = engine.series.value;
|
|
62
62
|
const op = engine.seriesOpacities.value;
|
|
63
63
|
if (index >= s.length || index >= op.length) return 0;
|
|
64
|
+
const head = engine.tipTime?.get() ?? engine.timestamp.get();
|
|
65
|
+
if (s[index].data.length === 0 || s[index].data[0].time > head || head < engine.timestamp.get() - engine.displayWindow.get()) return 0;
|
|
64
66
|
return op[index] ?? 0;
|
|
65
67
|
});
|
|
66
68
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DashPathEffect, Group, Path } from "@shopify/react-native-skia";
|
|
2
2
|
|
|
3
3
|
import { useDerivedValue } from "react-native-reanimated";
|
|
4
|
-
import type
|
|
4
|
+
import { lineTipX, type ChartPadding } from "../draw/line";
|
|
5
5
|
import type { ResolvedValueLineConfig } from "../core/resolveConfig";
|
|
6
6
|
import type { MultiEngineState } from "../core/useLiveChartEngine";
|
|
7
7
|
import { usePathBuilder } from "../hooks/usePathBuilder";
|
|
@@ -39,7 +39,7 @@ function SeriesValueLineAtIndex({
|
|
|
39
39
|
|
|
40
40
|
if (y >= 0) {
|
|
41
41
|
b.moveTo(padding.left, y);
|
|
42
|
-
b.lineTo(engine.
|
|
42
|
+
b.lineTo(lineTipX(engine.timestamp.get(), engine.displayWindow.get(), engine.tipTime?.get() ?? engine.timestamp.get(), engine.canvasWidth.get(), padding), y);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
return b.detach();
|
|
@@ -49,6 +49,8 @@ function SeriesValueLineAtIndex({
|
|
|
49
49
|
const s = engine.series.get();
|
|
50
50
|
const op = engine.seriesOpacities.get();
|
|
51
51
|
if (index >= s.length || index >= op.length) return 0;
|
|
52
|
+
const head = engine.tipTime?.get() ?? engine.timestamp.get();
|
|
53
|
+
if (s[index].data.length === 0 || s[index].data[0].time > head || head < engine.timestamp.get() - engine.displayWindow.get()) return 0;
|
|
52
54
|
return (op[index] ?? 0) * 0.4;
|
|
53
55
|
});
|
|
54
56
|
|