react-native-livechart 4.28.0 → 4.28.2
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/LiveChartSeries.d.ts.map +1 -1
- package/dist/components/SeriesToggleChips.d.ts +7 -5
- package/dist/components/SeriesToggleChips.d.ts.map +1 -1
- package/dist/core/liveChartSeriesEngineTick.d.ts +2 -0
- package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
- package/dist/core/useLiveChartEngine.d.ts +2 -0
- package/dist/core/useLiveChartEngine.d.ts.map +1 -1
- package/dist/core/useLiveChartSeriesEngine.d.ts +21 -15
- package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
- package/dist/draw/line.d.ts +3 -1
- package/dist/draw/line.d.ts.map +1 -1
- package/dist/hooks/useMultiSeriesDegen.d.ts +7 -1
- package/dist/hooks/useMultiSeriesDegen.d.ts.map +1 -1
- package/dist/hooks/useMultiSeriesLinePaths.d.ts.map +1 -1
- package/dist/hooks/useSeriesPresentation.d.ts +13 -0
- package/dist/hooks/useSeriesPresentation.d.ts.map +1 -0
- package/dist/types.d.ts +12 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/LiveChartSeries.tsx +45 -103
- package/src/components/SeriesToggleChips.tsx +14 -37
- package/src/core/liveChartSeriesEngineTick.ts +9 -5
- package/src/core/useLiveChartEngine.ts +2 -0
- package/src/core/useLiveChartSeriesEngine.ts +61 -37
- package/src/draw/line.ts +13 -7
- package/src/hooks/useMultiSeriesDegen.ts +17 -8
- package/src/hooks/useMultiSeriesLinePaths.ts +6 -1
- package/src/hooks/useSeriesPresentation.ts +133 -0
- package/src/types.ts +12 -2
|
@@ -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, useCallback, useImperativeHandle, useState } from "react";
|
|
8
|
+
import { forwardRef, useCallback, useEffect, 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, {
|
|
@@ -25,8 +25,6 @@ import {
|
|
|
25
25
|
} from "../constants";
|
|
26
26
|
import { hasMultiSeriesChartData } from "../core/chartDataPresence";
|
|
27
27
|
import {
|
|
28
|
-
lineColorsSignatureFromArray,
|
|
29
|
-
lineStyleSignatureFromArray,
|
|
30
28
|
resolveMultiSeriesLineColorsSnapshot,
|
|
31
29
|
resolveMultiSeriesLineStylesSnapshot,
|
|
32
30
|
} from "../core/multiSeriesLayout";
|
|
@@ -60,7 +58,6 @@ import {
|
|
|
60
58
|
import {
|
|
61
59
|
resolveChartLayout,
|
|
62
60
|
shouldMeasureYAxisLabels,
|
|
63
|
-
shouldResampleLayoutValue,
|
|
64
61
|
} from "../hooks/resolveChartLayout";
|
|
65
62
|
import { useCanvasLayout } from "../hooks/useCanvasLayout";
|
|
66
63
|
import { useChartReveal } from "../hooks/useChartReveal";
|
|
@@ -131,57 +128,11 @@ import { MultiSeriesValueLabels } from "./MultiSeriesValueLabels";
|
|
|
131
128
|
import { MultiSeriesValueLines } from "./MultiSeriesValueLines";
|
|
132
129
|
import { PerSeriesTooltipOverlay } from "./PerSeriesTooltipOverlay";
|
|
133
130
|
import { ReferenceLineOverlay } from "./ReferenceLineOverlay";
|
|
134
|
-
import {
|
|
131
|
+
import { SeriesToggleChipsView } from "./SeriesToggleChips";
|
|
132
|
+
import { useSeriesPresentation } from "../hooks/useSeriesPresentation";
|
|
135
133
|
import { XAxisGridLines, XAxisOverlay } from "./XAxisOverlay";
|
|
136
134
|
import { YAxisOverlay } from "./YAxisOverlay";
|
|
137
135
|
|
|
138
|
-
/**
|
|
139
|
-
* Signature of the per-series *config* (colors, stroke styles, labels, count) —
|
|
140
|
-
* everything the snapshot below feeds into layout and rendering. Excludes the
|
|
141
|
-
* per-tick `data`, so the snapshot only refreshes on real config changes.
|
|
142
|
-
*/
|
|
143
|
-
function seriesConfigSig(s: SharedValue<SeriesConfig[]>) {
|
|
144
|
-
"worklet";
|
|
145
|
-
const arr = s.value;
|
|
146
|
-
let out =
|
|
147
|
-
lineColorsSignatureFromArray(arr) +
|
|
148
|
-
"\x1d" +
|
|
149
|
-
lineStyleSignatureFromArray(arr);
|
|
150
|
-
for (let i = 0; i < arr.length; i++) {
|
|
151
|
-
out += "\x1d" + (arr[i].label ?? arr[i].id);
|
|
152
|
-
}
|
|
153
|
-
return out;
|
|
154
|
-
}
|
|
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
|
-
|
|
185
136
|
/**
|
|
186
137
|
* Resolves props → configs → theme/layout → engine → per-frame derived values,
|
|
187
138
|
* overlay hooks and the color/style reaction state, returning a single render
|
|
@@ -529,11 +480,8 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
529
480
|
palette.labelFontSize,
|
|
530
481
|
);
|
|
531
482
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
// subsequent configuration change without reading the SharedValue in render.
|
|
535
|
-
const [seriesSnapshot, setSeriesSnapshot] = useState<SeriesConfig[]>([]);
|
|
536
|
-
const valueLayoutSample = useSeriesLayoutValueSample(series);
|
|
483
|
+
const { snapshot: seriesSnapshot, valueLayoutSample, refresh: refreshSeriesPresentation } =
|
|
484
|
+
useSeriesPresentation(series);
|
|
537
485
|
|
|
538
486
|
// Mount per-series drawing worklets only for real series. The previous fixed
|
|
539
487
|
// 12-slot render kept 144 derived-value mappers alive for the default stroke,
|
|
@@ -644,29 +592,11 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
644
592
|
),
|
|
645
593
|
);
|
|
646
594
|
|
|
647
|
-
//
|
|
648
|
-
//
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
setSeriesSnapshot(series.get().slice());
|
|
653
|
-
};
|
|
654
|
-
|
|
655
|
-
useAnimatedReaction(
|
|
656
|
-
() => seriesConfigSig(series),
|
|
657
|
-
/* istanbul ignore next -- scheduleOnRN from UI-thread reaction */
|
|
658
|
-
(sig, prev) => {
|
|
659
|
-
if (sig !== prev) scheduleOnRN(syncSnapshot);
|
|
660
|
-
},
|
|
661
|
-
[series, syncSnapshot],
|
|
662
|
-
);
|
|
663
|
-
|
|
664
|
-
const {
|
|
665
|
-
pack: degenPack,
|
|
666
|
-
packRevision: degenPackRevision,
|
|
667
|
-
particleTimestamp: degenParticleTimestamp,
|
|
668
|
-
shakeTransform: degenShakeTransform,
|
|
669
|
-
} = useMultiSeriesDegen(engine, effectivePadding, degenCfg, onDegenShake);
|
|
595
|
+
// Keep one transform for the drawing stack; the optional particle runtime
|
|
596
|
+
// mounts with its layer instead of allocating 27 SharedValues while off.
|
|
597
|
+
const degenShakeTransform = useSharedValue<[{ translateX: number }, { translateY: number }]>([
|
|
598
|
+
{ translateX: 0 }, { translateY: 0 },
|
|
599
|
+
]);
|
|
670
600
|
|
|
671
601
|
const { yAxisEntries } = useYAxis(
|
|
672
602
|
engine,
|
|
@@ -876,6 +806,7 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
876
806
|
dotOuterRadius,
|
|
877
807
|
legendCfg,
|
|
878
808
|
degenCfg,
|
|
809
|
+
onDegenShake,
|
|
879
810
|
metricsCfg,
|
|
880
811
|
allRefLines,
|
|
881
812
|
refLineKeys,
|
|
@@ -904,14 +835,13 @@ function useLiveChartSeriesController(props: LiveChartSeriesProps) {
|
|
|
904
835
|
effectiveSeries,
|
|
905
836
|
layoutHeight,
|
|
906
837
|
onLayout,
|
|
838
|
+
seriesSnapshot,
|
|
839
|
+
refreshSeriesPresentation,
|
|
907
840
|
linePaths,
|
|
908
841
|
seriesClip,
|
|
909
842
|
activeSeriesCount,
|
|
910
843
|
lineColors,
|
|
911
844
|
lineStyles,
|
|
912
|
-
degenPack,
|
|
913
|
-
degenPackRevision,
|
|
914
|
-
degenParticleTimestamp,
|
|
915
845
|
degenShakeTransform,
|
|
916
846
|
yAxisEntries,
|
|
917
847
|
xAxisEntries,
|
|
@@ -1005,9 +935,6 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
|
|
|
1005
935
|
xAxisEntries,
|
|
1006
936
|
xGridStyleCfg,
|
|
1007
937
|
degenCfg,
|
|
1008
|
-
degenPack,
|
|
1009
|
-
degenPackRevision,
|
|
1010
|
-
degenParticleTimestamp,
|
|
1011
938
|
markersActive,
|
|
1012
939
|
markersSV,
|
|
1013
940
|
markerClusterCfg,
|
|
@@ -1132,20 +1059,7 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
|
|
|
1132
1059
|
dim — which now covers the dots + pulse rings — never clips them.
|
|
1133
1060
|
They track each series' live value, not the scrub point. */}
|
|
1134
1061
|
|
|
1135
|
-
{degenCfg &&
|
|
1136
|
-
<Group opacity={reveal.dotOpacity}>
|
|
1137
|
-
<DegenParticlesOverlay
|
|
1138
|
-
pack={degenPack}
|
|
1139
|
-
packRevision={degenPackRevision}
|
|
1140
|
-
particleTimestamp={degenParticleTimestamp}
|
|
1141
|
-
palette={palette}
|
|
1142
|
-
particleSlotCount={degenCfg.particleSlotCount}
|
|
1143
|
-
particleBurstDurationSec={degenCfg.particleBurstDurationSec}
|
|
1144
|
-
particleOpacity={degenCfg.particleOpacity}
|
|
1145
|
-
colors={degenCfg.colors ?? lineColors}
|
|
1146
|
-
/>
|
|
1147
|
-
</Group>
|
|
1148
|
-
)}
|
|
1062
|
+
{degenCfg && <SeriesDegenLayer model={model} config={degenCfg} />}
|
|
1149
1063
|
|
|
1150
1064
|
{markersActive && (
|
|
1151
1065
|
<Group opacity={markerGroupOpacity}>
|
|
@@ -1185,6 +1099,32 @@ function SeriesChartStack({ model }: { model: LiveChartSeriesModel }) {
|
|
|
1185
1099
|
);
|
|
1186
1100
|
}
|
|
1187
1101
|
|
|
1102
|
+
/** Allocate particle buffers, config SharedValues, and the frame loop only when enabled. */
|
|
1103
|
+
function SeriesDegenLayer({ model, config }: {
|
|
1104
|
+
model: LiveChartSeriesModel;
|
|
1105
|
+
config: NonNullable<LiveChartSeriesModel["degenCfg"]>;
|
|
1106
|
+
}) {
|
|
1107
|
+
const { engine, effectivePadding, onDegenShake, degenShakeTransform, reveal, palette, lineColors } = model;
|
|
1108
|
+
const effect = useMultiSeriesDegen(engine, effectivePadding, config, onDegenShake, degenShakeTransform);
|
|
1109
|
+
useEffect(() => () => {
|
|
1110
|
+
degenShakeTransform.set([{ translateX: 0 }, { translateY: 0 }]);
|
|
1111
|
+
}, [degenShakeTransform]);
|
|
1112
|
+
return (
|
|
1113
|
+
<Group opacity={reveal.dotOpacity}>
|
|
1114
|
+
<DegenParticlesOverlay
|
|
1115
|
+
pack={effect.pack}
|
|
1116
|
+
packRevision={effect.packRevision}
|
|
1117
|
+
particleTimestamp={effect.particleTimestamp}
|
|
1118
|
+
palette={palette}
|
|
1119
|
+
particleSlotCount={config.particleSlotCount}
|
|
1120
|
+
particleBurstDurationSec={config.particleBurstDurationSec}
|
|
1121
|
+
particleOpacity={config.particleOpacity}
|
|
1122
|
+
colors={config.colors ?? lineColors}
|
|
1123
|
+
/>
|
|
1124
|
+
</Group>
|
|
1125
|
+
);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1188
1128
|
/** Per-series live-value labels, drawn above the scrub dim so the dim (which
|
|
1189
1129
|
* covers the dots + pulse rings) never clips them. Keeps the degen shake
|
|
1190
1130
|
* transform so they track the shaken stack. */
|
|
@@ -1331,10 +1271,12 @@ function SeriesLegend({
|
|
|
1331
1271
|
model: LiveChartSeriesModel;
|
|
1332
1272
|
position: "top" | "bottom";
|
|
1333
1273
|
}) {
|
|
1334
|
-
const { legendCfg, series, palette, onSeriesToggle } = model;
|
|
1335
|
-
if (legendCfg.position !== position) return null;
|
|
1274
|
+
const { legendCfg, series, palette, onSeriesToggle, seriesSnapshot, refreshSeriesPresentation } = model;
|
|
1275
|
+
if (!legendCfg.visible || legendCfg.position !== position) return null;
|
|
1336
1276
|
return (
|
|
1337
|
-
<
|
|
1277
|
+
<SeriesToggleChipsView
|
|
1278
|
+
snapshot={seriesSnapshot}
|
|
1279
|
+
onSnapshotChange={refreshSeriesPresentation}
|
|
1338
1280
|
series={series}
|
|
1339
1281
|
legend={legendCfg}
|
|
1340
1282
|
palette={palette}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
2
1
|
import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
3
|
-
import {
|
|
4
|
-
import { scheduleOnRN } from "react-native-worklets";
|
|
2
|
+
import type { SharedValue } from "react-native-reanimated";
|
|
5
3
|
import { MONO_FONT_FAMILY } from "../lib/monoFontFamily";
|
|
6
4
|
import type { ResolvedLegendConfig } from "../core/resolveConfig";
|
|
7
5
|
import type { LiveChartPalette, SeriesConfig } from "../types";
|
|
8
|
-
import {
|
|
6
|
+
import { useSeriesPresentation } from "../hooks/useSeriesPresentation";
|
|
9
7
|
|
|
10
8
|
export interface SeriesToggleChipsProps {
|
|
11
9
|
series: SharedValue<SeriesConfig[]>;
|
|
@@ -40,39 +38,18 @@ function legendColorDefaults(palette: LiveChartPalette | undefined) {
|
|
|
40
38
|
};
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
legend,
|
|
49
|
-
palette,
|
|
50
|
-
onSeriesToggle,
|
|
51
|
-
}: SeriesToggleChipsProps) {
|
|
52
|
-
// Seed from the current series at mount; the reaction below keeps it in sync.
|
|
53
|
-
const [snapshot, setSnapshot] = useState<SeriesConfig[]>(() =>
|
|
54
|
-
series.get().slice(),
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
// Read the `series` prop from closure rather than a SharedValue passed
|
|
58
|
-
// through `scheduleOnRN`: the handle serialized across the worklet→JS
|
|
59
|
-
// boundary exposes the native `.value` accessor but NOT the `.get()` method,
|
|
60
|
-
// so calling `.get()` on it throws ("sv.get is not a function").
|
|
61
|
-
const pullSnapshot = () => {
|
|
62
|
-
setSnapshot(series.get().slice());
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
useAnimatedReaction(
|
|
66
|
-
() => seriesMetaSig(series.get()),
|
|
67
|
-
/* istanbul ignore next -- Reanimated reaction; snapshot seeded at mount, pulled here on change */
|
|
68
|
-
(sig, prev) => {
|
|
69
|
-
if (sig !== prev) {
|
|
70
|
-
scheduleOnRN(pullSnapshot);
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
[series, pullSnapshot],
|
|
74
|
-
);
|
|
41
|
+
/** Standalone wrapper; LiveChartSeries shares its controller snapshot instead. */
|
|
42
|
+
export function SeriesToggleChips(props: SeriesToggleChipsProps) {
|
|
43
|
+
const { snapshot, refresh } = useSeriesPresentation(props.series);
|
|
44
|
+
return <SeriesToggleChipsView {...props} snapshot={snapshot} onSnapshotChange={refresh} />;
|
|
45
|
+
}
|
|
75
46
|
|
|
47
|
+
export function SeriesToggleChipsView({
|
|
48
|
+
series, legend, palette, onSeriesToggle, snapshot, onSnapshotChange,
|
|
49
|
+
}: SeriesToggleChipsProps & {
|
|
50
|
+
snapshot: SeriesConfig[];
|
|
51
|
+
onSnapshotChange: () => void;
|
|
52
|
+
}) {
|
|
76
53
|
if (!legend.visible) return null;
|
|
77
54
|
|
|
78
55
|
const toggle = (id: string) => {
|
|
@@ -86,7 +63,7 @@ export function SeriesToggleChips({
|
|
|
86
63
|
i === idx ? { ...s, visible: nextVisible } : s,
|
|
87
64
|
);
|
|
88
65
|
series.set(next);
|
|
89
|
-
|
|
66
|
+
onSnapshotChange();
|
|
90
67
|
onSeriesToggle?.(id, nextVisible);
|
|
91
68
|
};
|
|
92
69
|
|
|
@@ -22,6 +22,8 @@ export interface MultiEngineTickMutable {
|
|
|
22
22
|
*/
|
|
23
23
|
liveEdge: number;
|
|
24
24
|
displayValues: number[];
|
|
25
|
+
/** Ease the newest recorded sample with its live tip, without editing history. */
|
|
26
|
+
smoothRecordedTail?: boolean;
|
|
25
27
|
opacities: number[];
|
|
26
28
|
/**
|
|
27
29
|
* Value + time of the lowest / highest point across the visible series — the
|
|
@@ -153,6 +155,7 @@ export function tickLiveChartSeriesEngineFrame(
|
|
|
153
155
|
viewEnd != null &&
|
|
154
156
|
viewEnd >= firstDataTime &&
|
|
155
157
|
(viewEnd < liveEdge || input.allowFutureViewEnd === true);
|
|
158
|
+
state.smoothRecordedTail = !scrolledBack && input.presentationTime == null;
|
|
156
159
|
if (scrolledBack) {
|
|
157
160
|
state.timestamp = viewEnd;
|
|
158
161
|
} else if (!input.paused) {
|
|
@@ -232,14 +235,15 @@ export function tickLiveChartSeriesEngineFrame(
|
|
|
232
235
|
(1 - gapRatio) *
|
|
233
236
|
(input.adaptiveSpeedBoost ??
|
|
234
237
|
MOTION_METRICS_DEFAULTS.adaptiveSpeedBoost);
|
|
235
|
-
//
|
|
236
|
-
//
|
|
237
|
-
//
|
|
238
|
+
// An explicit replay head already presents its value; do not ease it twice.
|
|
239
|
+
// Ordinary live appends must still ease the price. The line builder presents
|
|
240
|
+
// the newest recorded sample at the same eased value so the line cannot
|
|
241
|
+
// bend back from an already-snapped sample to a lagging dot (#393).
|
|
238
242
|
const pts = series[i].data;
|
|
239
243
|
const latest = pts[pts.length - 1];
|
|
240
|
-
const
|
|
244
|
+
const targetIsPresented = input.presentationTime != null && !scrolledBack && latest != null &&
|
|
241
245
|
latest.time <= Math.min(state.timestamp, baseNow) && latest.value === target;
|
|
242
|
-
state.displayValues[i] = snap ||
|
|
246
|
+
state.displayValues[i] = snap || targetIsPresented
|
|
243
247
|
? target
|
|
244
248
|
: lerp(cur, target, adaptiveSpeed, input.dt);
|
|
245
249
|
|
|
@@ -226,6 +226,8 @@ export interface MultiEngineState
|
|
|
226
226
|
/** Entries captured by the last measured engine frame; history arrays remain shared. */
|
|
227
227
|
series: SharedValue<SeriesConfig[]>;
|
|
228
228
|
displaySeriesValues: SharedValue<number[]>;
|
|
229
|
+
/** Live-tail presentation only; source history and explicit replay stay exact. */
|
|
230
|
+
smoothRecordedTail?: SharedValue<boolean>;
|
|
229
231
|
seriesOpacities: SharedValue<number[]>;
|
|
230
232
|
/** Presented tip time, clamped to the viewport edge; absent uses timestamp. */
|
|
231
233
|
tipTime?: SharedValue<number>;
|
|
@@ -66,11 +66,15 @@ export interface MultiSeriesEngineConfig {
|
|
|
66
66
|
snapKey?: string | number;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/** Constant React props copied with the frame worklet; no mapper/SharedValue is needed. */
|
|
70
|
+
type FrameParameter<T> = Pick<SharedValue<T>, "value">;
|
|
71
|
+
|
|
69
72
|
export interface MultiEngineFrameRefs {
|
|
70
73
|
series: SharedValue<SeriesConfig[]>;
|
|
71
74
|
/** Drawing input published with this frame's range/tips. Optional for standalone callers. */
|
|
72
75
|
renderedSeries?: SharedValue<SeriesConfig[]>;
|
|
73
76
|
displaySeriesValues: SharedValue<number[]>;
|
|
77
|
+
smoothRecordedTail?: SharedValue<boolean>;
|
|
74
78
|
seriesOpacities: SharedValue<number[]>;
|
|
75
79
|
displayMin: SharedValue<number>;
|
|
76
80
|
displayMax: SharedValue<number>;
|
|
@@ -81,28 +85,28 @@ export interface MultiEngineFrameRefs {
|
|
|
81
85
|
timestamp: SharedValue<number>;
|
|
82
86
|
canvasWidth: SharedValue<number>;
|
|
83
87
|
canvasHeight: SharedValue<number>;
|
|
84
|
-
timeWindow:
|
|
85
|
-
smoothing:
|
|
86
|
-
rangeAnimationSV?:
|
|
87
|
-
adaptiveSpeedBoostSV?:
|
|
88
|
-
exaggerateSV:
|
|
89
|
-
referenceValue:
|
|
90
|
-
referenceValues?:
|
|
91
|
-
nonNegativeSV?:
|
|
92
|
-
maxValueSV?:
|
|
93
|
-
minRangeSV?:
|
|
88
|
+
timeWindow: FrameParameter<number>;
|
|
89
|
+
smoothing: FrameParameter<number>;
|
|
90
|
+
rangeAnimationSV?: FrameParameter<SeriesRangeAnimationConfig | undefined>;
|
|
91
|
+
adaptiveSpeedBoostSV?: FrameParameter<number | undefined>;
|
|
92
|
+
exaggerateSV: FrameParameter<boolean>;
|
|
93
|
+
referenceValue: FrameParameter<number | undefined>;
|
|
94
|
+
referenceValues?: FrameParameter<number[] | undefined>;
|
|
95
|
+
nonNegativeSV?: FrameParameter<boolean>;
|
|
96
|
+
maxValueSV?: FrameParameter<number | undefined>;
|
|
97
|
+
minRangeSV?: FrameParameter<number | undefined>;
|
|
94
98
|
yRangeScaleSV?: SharedValue<number>;
|
|
95
|
-
nowOverrideSV?:
|
|
99
|
+
nowOverrideSV?: FrameParameter<number | undefined>;
|
|
96
100
|
presentationTimeSV?: SharedValue<number | undefined>;
|
|
97
|
-
historyStartTimeSV?:
|
|
101
|
+
historyStartTimeSV?: FrameParameter<number | undefined>;
|
|
98
102
|
currentTimeSV?: SharedValue<number>;
|
|
99
103
|
fullHistoryWindowSV?: SharedValue<number | null>;
|
|
100
|
-
windowBufferSV?:
|
|
101
|
-
pausedSV:
|
|
104
|
+
windowBufferSV?: FrameParameter<number>;
|
|
105
|
+
pausedSV: FrameParameter<boolean>;
|
|
102
106
|
/** Pan-scroll right-edge override (null = follow live). Optional for callers/tests. */
|
|
103
107
|
viewEndSV?: SharedValue<number | null>;
|
|
104
108
|
/** Honor a `viewEnd` past the live edge (timeScroll.overscroll). Optional. */
|
|
105
|
-
allowFutureViewEndSV?:
|
|
109
|
+
allowFutureViewEndSV?: FrameParameter<boolean>;
|
|
106
110
|
/** "Return to live" glide progress (0→1); the right edge eases to live. Optional. */
|
|
107
111
|
returnTSV?: SharedValue<number>;
|
|
108
112
|
/** Frozen right-edge time the return glide starts from. Optional. */
|
|
@@ -117,6 +121,8 @@ export interface MultiEngineFrameRefs {
|
|
|
117
121
|
* tick. Optional for callers/tests.
|
|
118
122
|
*/
|
|
119
123
|
snapSV?: SharedValue<boolean>;
|
|
124
|
+
/** Wait for measured, visible data before fitting the initial range. */
|
|
125
|
+
initialFitPendingSV?: SharedValue<boolean>;
|
|
120
126
|
extremaMinValue: SharedValue<number>;
|
|
121
127
|
extremaMaxValue: SharedValue<number>;
|
|
122
128
|
extremaMinTime: SharedValue<number>;
|
|
@@ -197,6 +203,16 @@ export function applyLiveChartSeriesEngineFrame(
|
|
|
197
203
|
// and clear it below so only this frame snaps (live ticks stay smoothed).
|
|
198
204
|
const snap = sv.snapSV?.value ?? false;
|
|
199
205
|
const seriesSnap = sv.series.value;
|
|
206
|
+
let initialFit = false;
|
|
207
|
+
if (sv.initialFitPendingSV?.value && sv.canvasWidth.value > 0 && sv.canvasHeight.value > 0) {
|
|
208
|
+
for (let i = 0; i < seriesSnap.length; i++) {
|
|
209
|
+
const s = seriesSnap[i];
|
|
210
|
+
if (s.visible !== false && s.data.length > 0 && Number.isFinite(s.value)) {
|
|
211
|
+
initialFit = true;
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
200
216
|
const curDv = sv.displaySeriesValues.value;
|
|
201
217
|
const curOp = sv.seriesOpacities.value;
|
|
202
218
|
let displayValues: number[];
|
|
@@ -271,7 +287,7 @@ export function applyLiveChartSeriesEngineFrame(
|
|
|
271
287
|
input.series = seriesSnap;
|
|
272
288
|
input.nowSeconds = Date.now() / 1000;
|
|
273
289
|
input.paused = sv.pausedSV.value;
|
|
274
|
-
input.snap = snap;
|
|
290
|
+
input.snap = snap || initialFit;
|
|
275
291
|
input.viewEnd = sv.viewEndSV?.value;
|
|
276
292
|
input.allowFutureViewEnd = sv.allowFutureViewEndSV?.value ?? false;
|
|
277
293
|
input.returnT = sv.returnTSV?.value;
|
|
@@ -288,6 +304,7 @@ export function applyLiveChartSeriesEngineFrame(
|
|
|
288
304
|
if (sv.currentTimeSV) sv.currentTimeSV.value = state.currentTime!;
|
|
289
305
|
if (sv.fullHistoryWindowSV) sv.fullHistoryWindowSV.value = state.fullHistoryWindow ?? null;
|
|
290
306
|
sv.displaySeriesValues.value = state.displayValues;
|
|
307
|
+
if (sv.smoothRecordedTail) sv.smoothRecordedTail.value = state.smoothRecordedTail ?? false;
|
|
291
308
|
sv.seriesOpacities.value = state.opacities;
|
|
292
309
|
sv.extremaMinValue.value = state.extremaMinValue;
|
|
293
310
|
sv.extremaMaxValue.value = state.extremaMaxValue;
|
|
@@ -304,6 +321,7 @@ export function applyLiveChartSeriesEngineFrame(
|
|
|
304
321
|
}
|
|
305
322
|
sv.renderedSeries.value = rendered;
|
|
306
323
|
}
|
|
324
|
+
if (initialFit && sv.initialFitPendingSV) sv.initialFitPendingSV.value = false;
|
|
307
325
|
// Clear the one-shot snap so the next frame eases normally again — but only
|
|
308
326
|
// once a real (measured) frame consumed it (the tick early-returns on a
|
|
309
327
|
// zero-size canvas before applying the snap). See applyLiveChartEngineFrame.
|
|
@@ -327,31 +345,30 @@ export function useLiveChartSeriesEngine(
|
|
|
327
345
|
const viewWindow = useSharedValue<number | null>(null);
|
|
328
346
|
const fullHistoryWindow = useSharedValue<number | null>(null);
|
|
329
347
|
const timeWindow = useDerivedValue(() => viewWindow.value ?? fullHistoryWindow.value ?? config.timeWindow);
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
const
|
|
335
|
-
const
|
|
336
|
-
const
|
|
337
|
-
const
|
|
338
|
-
const
|
|
339
|
-
const
|
|
340
|
-
const
|
|
341
|
-
const
|
|
342
|
-
const
|
|
343
|
-
const
|
|
348
|
+
// These are React props, not UI-thread signals. The registered frame and
|
|
349
|
+
// return-to-live worklets capture a fresh snapshot when props change. Keeping
|
|
350
|
+
// them as plain values avoids one native mutable and mapper per parameter.
|
|
351
|
+
const configuredTimeWindow = { value: config.timeWindow };
|
|
352
|
+
const historyStartTimeSV = { value: config.historyStartTime };
|
|
353
|
+
const smoothing = { value: config.smoothing };
|
|
354
|
+
const rangeAnimationSV = { value: config.rangeAnimation };
|
|
355
|
+
const adaptiveSpeedBoostSV = { value: config.adaptiveSpeedBoost };
|
|
356
|
+
const exaggerateSV = { value: config.exaggerate ?? false };
|
|
357
|
+
const referenceValue = { value: config.referenceValue };
|
|
358
|
+
const referenceValues = { value: config.referenceValues };
|
|
359
|
+
const nonNegativeSV = { value: config.nonNegative ?? false };
|
|
360
|
+
const maxValueSV = { value: config.maxValue };
|
|
361
|
+
const minRangeSV = { value: config.minRange };
|
|
362
|
+
const nowOverrideSV = { value: config.nowOverride };
|
|
363
|
+
const windowBufferSV = { value: config.windowBuffer ?? 0 };
|
|
364
|
+
const pausedSV = { value: config.paused ?? false };
|
|
344
365
|
// Whether time-scroll is active — drives the return-to-live reaction below.
|
|
345
366
|
// Defaults to enabled (legacy behavior).
|
|
346
|
-
const scrollEnabledSV =
|
|
367
|
+
const scrollEnabledSV = { value: config.scrollEnabled ?? true };
|
|
347
368
|
// Honor a viewEnd parked past the live edge (timeScroll.overscroll).
|
|
348
|
-
const allowFutureViewEndSV =
|
|
349
|
-
() => config.allowFutureViewEnd ?? false,
|
|
350
|
-
);
|
|
369
|
+
const allowFutureViewEndSV = { value: config.allowFutureViewEnd ?? false };
|
|
351
370
|
// Return-to-live glide duration (ms); 0 = instant snap. Read by the reaction.
|
|
352
|
-
const returnToLiveMsSV =
|
|
353
|
-
() => config.returnToLiveMs ?? RETURN_TO_LIVE_MS,
|
|
354
|
-
);
|
|
371
|
+
const returnToLiveMsSV = { value: config.returnToLiveMs ?? RETURN_TO_LIVE_MS };
|
|
355
372
|
|
|
356
373
|
const displayMin = useSharedValue(0);
|
|
357
374
|
const displayMax = useSharedValue(1);
|
|
@@ -375,6 +392,7 @@ export function useLiveChartSeriesEngine(
|
|
|
375
392
|
const returnFrom = useSharedValue(0);
|
|
376
393
|
|
|
377
394
|
const displaySeriesValues = useSharedValue<number[]>([]);
|
|
395
|
+
const smoothRecordedTail = useSharedValue(false);
|
|
378
396
|
const seriesOpacities = useSharedValue<number[]>([]);
|
|
379
397
|
const renderedSeries = useSharedValue<SeriesConfig[]>([]);
|
|
380
398
|
|
|
@@ -391,6 +409,9 @@ export function useLiveChartSeriesEngine(
|
|
|
391
409
|
// One-shot "snap the framing" flag — flipped by the effect when `snapKey`
|
|
392
410
|
// changes, consumed + cleared by the next frame (mirrors useLiveChartEngine).
|
|
393
411
|
const snapSV = useSharedValue(false);
|
|
412
|
+
// A placeholder 0–1 range must not delay the first visible chart when
|
|
413
|
+
// expansion animation is enabled. Consume this only after data and size arrive.
|
|
414
|
+
const initialFitPendingSV = useSharedValue(true);
|
|
394
415
|
const lastSnapKey = useRef(config.snapKey);
|
|
395
416
|
// Layout effect so the snap flag lands before the commit paints — a passive
|
|
396
417
|
// effect leaves one frame of new data in the old framing (mirrors useLiveChartEngine).
|
|
@@ -414,6 +435,7 @@ export function useLiveChartSeriesEngine(
|
|
|
414
435
|
series,
|
|
415
436
|
renderedSeries,
|
|
416
437
|
displaySeriesValues,
|
|
438
|
+
smoothRecordedTail,
|
|
417
439
|
seriesOpacities,
|
|
418
440
|
displayMin,
|
|
419
441
|
displayMax,
|
|
@@ -448,6 +470,7 @@ export function useLiveChartSeriesEngine(
|
|
|
448
470
|
viewWindowSV: viewWindow,
|
|
449
471
|
liveEdgeSV: liveEdge,
|
|
450
472
|
snapSV,
|
|
473
|
+
initialFitPendingSV,
|
|
451
474
|
extremaMinValue,
|
|
452
475
|
extremaMaxValue,
|
|
453
476
|
extremaMinTime,
|
|
@@ -511,6 +534,7 @@ export function useLiveChartSeriesEngine(
|
|
|
511
534
|
fullHistoryWindow,
|
|
512
535
|
series: renderedSeries,
|
|
513
536
|
displaySeriesValues,
|
|
537
|
+
smoothRecordedTail,
|
|
514
538
|
seriesOpacities,
|
|
515
539
|
extremaMinValue,
|
|
516
540
|
extremaMaxValue,
|
package/src/draw/line.ts
CHANGED
|
@@ -279,6 +279,8 @@ export function buildLinePoints(
|
|
|
279
279
|
omitTipBeyondData = false,
|
|
280
280
|
/** Optional presentation head; viewport end still determines the projection. */
|
|
281
281
|
tipTime = now,
|
|
282
|
+
/** Present only the newest recorded sample at the live tip's eased value. */
|
|
283
|
+
liveTailValue?: number,
|
|
282
284
|
): number[] {
|
|
283
285
|
"worklet";
|
|
284
286
|
const pts: number[] = out ?? [];
|
|
@@ -314,6 +316,9 @@ export function buildLinePoints(
|
|
|
314
316
|
}
|
|
315
317
|
const endIdx = elo;
|
|
316
318
|
if (endIdx <= startIdx) return pts;
|
|
319
|
+
// The authoritative array is never mutated. Historical viewports/future
|
|
320
|
+
// samples keep their recorded geometry; only a following live tail is eased.
|
|
321
|
+
const tailIdx = liveTailValue != null && endIdx === data.length ? endIdx - 1 : -1;
|
|
317
322
|
|
|
318
323
|
const xScale = chartW / windowSecs;
|
|
319
324
|
const yScale = chartH / valRange;
|
|
@@ -330,7 +335,7 @@ export function buildLinePoints(
|
|
|
330
335
|
for (let i = startIdx; i < endIdx; i++) {
|
|
331
336
|
pts.push(
|
|
332
337
|
padding.left + (data[i].time - winStart) * xScale,
|
|
333
|
-
padding.top + (displayMax - data[i].value) * yScale,
|
|
338
|
+
padding.top + (displayMax - (i === tailIdx ? liveTailValue! : data[i].value)) * yScale,
|
|
334
339
|
);
|
|
335
340
|
}
|
|
336
341
|
} else {
|
|
@@ -352,12 +357,12 @@ export function buildLinePoints(
|
|
|
352
357
|
const b = minIdx <= maxIdx ? maxIdx : minIdx;
|
|
353
358
|
pts.push(
|
|
354
359
|
padding.left + (data[a].time - winStart) * xScale,
|
|
355
|
-
padding.top + (displayMax - data[a].value) * yScale,
|
|
360
|
+
padding.top + (displayMax - (a === tailIdx ? liveTailValue! : data[a].value)) * yScale,
|
|
356
361
|
);
|
|
357
362
|
if (b !== a) {
|
|
358
363
|
pts.push(
|
|
359
364
|
padding.left + (data[b].time - winStart) * xScale,
|
|
360
|
-
padding.top + (displayMax - data[b].value) * yScale,
|
|
365
|
+
padding.top + (displayMax - (b === tailIdx ? liveTailValue! : data[b].value)) * yScale,
|
|
361
366
|
);
|
|
362
367
|
}
|
|
363
368
|
}
|
|
@@ -365,8 +370,9 @@ export function buildLinePoints(
|
|
|
365
370
|
minIdx = i;
|
|
366
371
|
maxIdx = i;
|
|
367
372
|
} else {
|
|
368
|
-
|
|
369
|
-
if (
|
|
373
|
+
const value = i === tailIdx ? liveTailValue! : data[i].value;
|
|
374
|
+
if (value < (minIdx === tailIdx ? liveTailValue! : data[minIdx].value)) minIdx = i;
|
|
375
|
+
if (value > (maxIdx === tailIdx ? liveTailValue! : data[maxIdx].value)) maxIdx = i;
|
|
370
376
|
}
|
|
371
377
|
}
|
|
372
378
|
// Flush the final column.
|
|
@@ -374,12 +380,12 @@ export function buildLinePoints(
|
|
|
374
380
|
const b = minIdx <= maxIdx ? maxIdx : minIdx;
|
|
375
381
|
pts.push(
|
|
376
382
|
padding.left + (data[a].time - winStart) * xScale,
|
|
377
|
-
padding.top + (displayMax - data[a].value) * yScale,
|
|
383
|
+
padding.top + (displayMax - (a === tailIdx ? liveTailValue! : data[a].value)) * yScale,
|
|
378
384
|
);
|
|
379
385
|
if (b !== a) {
|
|
380
386
|
pts.push(
|
|
381
387
|
padding.left + (data[b].time - winStart) * xScale,
|
|
382
|
-
padding.top + (displayMax - data[b].value) * yScale,
|
|
388
|
+
padding.top + (displayMax - (b === tailIdx ? liveTailValue! : data[b].value)) * yScale,
|
|
383
389
|
);
|
|
384
390
|
}
|
|
385
391
|
}
|