react-native-livechart 4.27.0 → 4.28.1
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/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/core/liveChartSeriesEngineTick.d.ts +15 -2
- package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
- package/dist/core/resolveConfig.d.ts.map +1 -1
- package/dist/core/useLiveChartEngine.d.ts +4 -0
- package/dist/core/useLiveChartEngine.d.ts.map +1 -1
- package/dist/core/useLiveChartSeriesEngine.d.ts +17 -4
- package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
- package/dist/draw/grid.d.ts +4 -2
- package/dist/draw/grid.d.ts.map +1 -1
- package/dist/draw/line.d.ts +8 -2
- 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/resolveChartLayout.d.ts +10 -2
- package/dist/hooks/resolveChartLayout.d.ts.map +1 -1
- package/dist/hooks/useCrosshairSeries.d.ts +3 -1
- package/dist/hooks/useCrosshairSeries.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/usePinchZoom.d.ts +7 -4
- package/dist/hooks/usePinchZoom.d.ts.map +1 -1
- package/dist/hooks/useReferenceDrag.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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/math/referenceLines.d.ts.map +1 -1
- package/dist/types.d.ts +69 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/LiveChart.tsx +20 -0
- package/src/components/LiveChartSeries.tsx +26 -6
- package/src/components/MultiSeriesDots.tsx +4 -2
- package/src/components/MultiSeriesValueLabels.tsx +4 -2
- package/src/components/MultiSeriesValueLines.tsx +4 -2
- package/src/core/liveChartSeriesEngineTick.ts +74 -14
- package/src/core/resolveConfig.ts +8 -5
- package/src/core/useLiveChartEngine.ts +4 -0
- package/src/core/useLiveChartSeriesEngine.ts +47 -6
- package/src/draw/grid.ts +15 -11
- package/src/draw/line.ts +36 -11
- package/src/hooks/crosshairSeries.ts +37 -5
- package/src/hooks/resolveChartLayout.ts +34 -3
- package/src/hooks/useCrosshairSeries.ts +28 -10
- package/src/hooks/useMultiSeriesDegen.ts +10 -5
- package/src/hooks/useMultiSeriesLinePaths.ts +8 -1
- package/src/hooks/usePinchZoom.ts +11 -4
- package/src/hooks/useReferenceDrag.ts +21 -3
- package/src/hooks/useYAxis.ts +1 -1
- package/src/hooks/useYAxisLabelWidth.ts +26 -0
- package/src/index.ts +1 -0
- package/src/math/referenceLines.ts +5 -0
- package/src/types.ts +65 -7
|
@@ -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
|
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { MOTION_METRICS_DEFAULTS } from "../constants";
|
|
2
2
|
import { lerp } from "../math/lerp";
|
|
3
3
|
import { rangeAnimationSpeed } from "../math/rangeAnimation";
|
|
4
|
-
import type {
|
|
4
|
+
import type { SeriesRangeAnimationConfig, SeriesConfig } from "../types";
|
|
5
5
|
|
|
6
6
|
export interface MultiEngineTickMutable {
|
|
7
7
|
displayMin: number;
|
|
8
8
|
displayMax: number;
|
|
9
|
+
/** Current clock before breathing-room buffer. */
|
|
10
|
+
currentTime?: number;
|
|
11
|
+
/** Unzoomed authoritative-history span, including buffer. */
|
|
12
|
+
fullHistoryWindow?: number | null;
|
|
13
|
+
/** Untransformed eased bounds, kept separate from presentation output. */
|
|
14
|
+
fittedMin?: number;
|
|
15
|
+
fittedMax?: number;
|
|
9
16
|
displayWindow: number;
|
|
10
17
|
timestamp: number;
|
|
11
18
|
/**
|
|
@@ -15,6 +22,8 @@ export interface MultiEngineTickMutable {
|
|
|
15
22
|
*/
|
|
16
23
|
liveEdge: number;
|
|
17
24
|
displayValues: number[];
|
|
25
|
+
/** Ease the newest recorded sample with its live tip, without editing history. */
|
|
26
|
+
smoothRecordedTail?: boolean;
|
|
18
27
|
opacities: number[];
|
|
19
28
|
/**
|
|
20
29
|
* Value + time of the lowest / highest point across the visible series — the
|
|
@@ -35,8 +44,10 @@ export interface MultiEngineTickInput {
|
|
|
35
44
|
canvasWidth: number;
|
|
36
45
|
canvasHeight: number;
|
|
37
46
|
timeWindow: number;
|
|
47
|
+
/** Authoritative Unix-second start for an expanding live history. */
|
|
48
|
+
historyStartTime?: number;
|
|
38
49
|
smoothing: number;
|
|
39
|
-
rangeAnimation?:
|
|
50
|
+
rangeAnimation?: SeriesRangeAnimationConfig;
|
|
40
51
|
exaggerate: boolean;
|
|
41
52
|
/** Extra catch-up speed added to `smoothing` when a series tip lags. Default `0.12`. */
|
|
42
53
|
adaptiveSpeedBoost?: number;
|
|
@@ -55,6 +66,8 @@ export interface MultiEngineTickInput {
|
|
|
55
66
|
nowSeconds?: number;
|
|
56
67
|
/** Override the engine's "now" (unix seconds). */
|
|
57
68
|
nowOverride?: number;
|
|
69
|
+
/** UI-thread presentation head, with precedence over nowOverride/wall time. */
|
|
70
|
+
presentationTime?: number;
|
|
58
71
|
/** Right-edge buffer as a fraction of the time window. */
|
|
59
72
|
windowBuffer?: number;
|
|
60
73
|
paused?: boolean;
|
|
@@ -110,8 +123,15 @@ export function tickLiveChartSeriesEngineFrame(
|
|
|
110
123
|
input: MultiEngineTickInput,
|
|
111
124
|
): void {
|
|
112
125
|
"worklet";
|
|
113
|
-
const baseNow = input.nowOverride ?? input.nowSeconds ?? Date.now() / 1000;
|
|
114
|
-
const
|
|
126
|
+
const baseNow = input.presentationTime ?? input.nowOverride ?? input.nowSeconds ?? Date.now() / 1000;
|
|
127
|
+
const buffer = input.windowBuffer ?? 0;
|
|
128
|
+
const start = input.historyStartTime;
|
|
129
|
+
const fullWindow = start != null && Number.isFinite(start) && start < baseNow &&
|
|
130
|
+
buffer >= 0 && buffer < 1 ? (baseNow - start) / (1 - buffer) : null;
|
|
131
|
+
state.currentTime = baseNow;
|
|
132
|
+
state.fullHistoryWindow = fullWindow;
|
|
133
|
+
const liveWindow = input.viewWindow ?? fullWindow ?? input.timeWindow;
|
|
134
|
+
const liveEdge = baseNow + buffer * liveWindow;
|
|
115
135
|
state.liveEdge = liveEdge;
|
|
116
136
|
const viewEnd = input.viewEnd;
|
|
117
137
|
// Earliest first-point time across visible series — the floor a frozen edge
|
|
@@ -123,6 +143,7 @@ export function tickLiveChartSeriesEngineFrame(
|
|
|
123
143
|
const d = input.series[i].data;
|
|
124
144
|
if (d.length > 0 && d[0].time < firstDataTime) firstDataTime = d[0].time;
|
|
125
145
|
}
|
|
146
|
+
if (fullWindow != null) firstDataTime = Math.min(firstDataTime, start!);
|
|
126
147
|
if (firstDataTime === Infinity) firstDataTime = -Infinity;
|
|
127
148
|
// Freeze the right edge while the gesture has parked `viewEnd` behind the live
|
|
128
149
|
// edge AND that edge still sits within the data; a stranded edge falls through
|
|
@@ -134,6 +155,7 @@ export function tickLiveChartSeriesEngineFrame(
|
|
|
134
155
|
viewEnd != null &&
|
|
135
156
|
viewEnd >= firstDataTime &&
|
|
136
157
|
(viewEnd < liveEdge || input.allowFutureViewEnd === true);
|
|
158
|
+
state.smoothRecordedTail = !scrolledBack && input.presentationTime == null;
|
|
137
159
|
if (scrolledBack) {
|
|
138
160
|
state.timestamp = viewEnd;
|
|
139
161
|
} else if (!input.paused) {
|
|
@@ -151,6 +173,11 @@ export function tickLiveChartSeriesEngineFrame(
|
|
|
151
173
|
|
|
152
174
|
if (input.canvasWidth === 0 || input.canvasHeight === 0) return;
|
|
153
175
|
|
|
176
|
+
// Never ease/fit against the previous frame's transformed output. Retain these
|
|
177
|
+
// even after removing the callback, so its expansion disappears in one frame.
|
|
178
|
+
state.displayMin = state.fittedMin ?? state.displayMin;
|
|
179
|
+
state.displayMax = state.fittedMax ?? state.displayMax;
|
|
180
|
+
|
|
154
181
|
const speed = input.smoothing;
|
|
155
182
|
// One-shot settle (snapKey change): collapse this frame's easing so the
|
|
156
183
|
// window / range / tips land on target instantly. See `MultiEngineTickInput.snap`.
|
|
@@ -170,23 +197,26 @@ export function tickLiveChartSeriesEngineFrame(
|
|
|
170
197
|
|
|
171
198
|
// Pinch-zoom: ease toward the zoom override when set, else the configured
|
|
172
199
|
// window (mirrors the single-series tick).
|
|
173
|
-
const
|
|
174
|
-
|
|
200
|
+
const anchoredFollowing = fullWindow != null && input.viewWindow == null &&
|
|
201
|
+
!scrolledBack && !input.paused && (input.returnT == null || input.returnT >= 1);
|
|
202
|
+
// Park the unzoomed width with a frozen edge. Resuming live restores the exact
|
|
203
|
+
// anchored span; easing a growing target would continuously lose the start.
|
|
204
|
+
const targetWindow = input.viewWindow ??
|
|
205
|
+
(fullWindow != null && (scrolledBack || input.paused) ? state.displayWindow : liveWindow);
|
|
206
|
+
state.displayWindow = snap || anchoredFollowing
|
|
175
207
|
? targetWindow
|
|
176
208
|
: lerp(state.displayWindow, targetWindow, speed, input.dt);
|
|
177
209
|
|
|
178
210
|
const winStart = state.timestamp - state.displayWindow;
|
|
179
211
|
const range = state.displayMax - state.displayMin;
|
|
180
212
|
|
|
181
|
-
//
|
|
182
|
-
//
|
|
183
|
-
//
|
|
184
|
-
// price while the line ends in the past. Mirrors single-series `edgeValue`.
|
|
185
|
-
// Reuses the gated `scrolledBack` computed above.
|
|
213
|
+
// Historical edges use recorded values. An edge parked in or beyond the
|
|
214
|
+
// future buffer still ends at the presentation head, using its presented
|
|
215
|
+
// value; samples after that head must never enter the tip or fitted range.
|
|
186
216
|
|
|
187
217
|
for (let i = 0; i < n; i++) {
|
|
188
218
|
let target = series[i].value;
|
|
189
|
-
if (scrolledBack) {
|
|
219
|
+
if (scrolledBack && state.timestamp < baseNow) {
|
|
190
220
|
const pts = series[i].data;
|
|
191
221
|
let elo = 0;
|
|
192
222
|
let ehi = pts.length;
|
|
@@ -205,7 +235,15 @@ export function tickLiveChartSeriesEngineFrame(
|
|
|
205
235
|
(1 - gapRatio) *
|
|
206
236
|
(input.adaptiveSpeedBoost ??
|
|
207
237
|
MOTION_METRICS_DEFAULTS.adaptiveSpeedBoost);
|
|
208
|
-
|
|
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).
|
|
242
|
+
const pts = series[i].data;
|
|
243
|
+
const latest = pts[pts.length - 1];
|
|
244
|
+
const targetIsPresented = input.presentationTime != null && !scrolledBack && latest != null &&
|
|
245
|
+
latest.time <= Math.min(state.timestamp, baseNow) && latest.value === target;
|
|
246
|
+
state.displayValues[i] = snap || targetIsPresented
|
|
209
247
|
? target
|
|
210
248
|
: lerp(cur, target, adaptiveSpeed, input.dt);
|
|
211
249
|
|
|
@@ -239,7 +277,8 @@ export function tickLiveChartSeriesEngineFrame(
|
|
|
239
277
|
// already track the edge value, so they stay in-range). Following live,
|
|
240
278
|
// keep the tail inclusive — feed timestamps can run slightly ahead of
|
|
241
279
|
// the local clock and must not flicker out of the range.
|
|
242
|
-
if (scrolledBack && points[j].time > state.timestamp)
|
|
280
|
+
if ((scrolledBack && points[j].time > state.timestamp) ||
|
|
281
|
+
(input.presentationTime != null && points[j].time > baseNow)) break;
|
|
243
282
|
const v = points[j].value;
|
|
244
283
|
/* istanbul ignore next -- trivial min/max */
|
|
245
284
|
if (v < tMin) tMin = v;
|
|
@@ -394,4 +433,25 @@ export function tickLiveChartSeriesEngineFrame(
|
|
|
394
433
|
);
|
|
395
434
|
}
|
|
396
435
|
}
|
|
436
|
+
|
|
437
|
+
state.fittedMin = state.displayMin;
|
|
438
|
+
state.fittedMax = state.displayMax;
|
|
439
|
+
const transform = input.rangeAnimation?.transform;
|
|
440
|
+
if (transform) {
|
|
441
|
+
const result = transform({
|
|
442
|
+
min: state.fittedMin,
|
|
443
|
+
max: state.fittedMax,
|
|
444
|
+
from: winStart,
|
|
445
|
+
to: state.timestamp,
|
|
446
|
+
});
|
|
447
|
+
if (
|
|
448
|
+
result &&
|
|
449
|
+
Number.isFinite(result.min) &&
|
|
450
|
+
Number.isFinite(result.max) &&
|
|
451
|
+
result.min < result.max
|
|
452
|
+
) {
|
|
453
|
+
state.displayMin = result.min;
|
|
454
|
+
state.displayMax = result.max;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
397
457
|
}
|
|
@@ -1069,12 +1069,15 @@ function resolvePerSeriesTooltip(
|
|
|
1069
1069
|
if (dash !== undefined) {
|
|
1070
1070
|
resolved.guideDashPattern = dash === true ? [3, 3] : dash || undefined;
|
|
1071
1071
|
}
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1072
|
+
// Boolean defaults may already be serialized/frozen by an earlier chart's
|
|
1073
|
+
// worklet. Normalize a fresh object rather than mutating that shared config.
|
|
1074
|
+
return {
|
|
1075
|
+
...resolved,
|
|
1076
|
+
maxLabelChars: Math.max(1, Math.floor(resolved.maxLabelChars)),
|
|
1077
|
+
bucketSeconds: resolved.bucketSeconds !== undefined && resolved.bucketSeconds > 0
|
|
1075
1078
|
? resolved.bucketSeconds
|
|
1076
|
-
: undefined
|
|
1077
|
-
|
|
1079
|
+
: undefined,
|
|
1080
|
+
};
|
|
1078
1081
|
}
|
|
1079
1082
|
|
|
1080
1083
|
/**
|
|
@@ -226,7 +226,11 @@ 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[]>;
|
|
232
|
+
/** Presented tip time, clamped to the viewport edge; absent uses timestamp. */
|
|
233
|
+
tipTime?: SharedValue<number>;
|
|
230
234
|
}
|
|
231
235
|
|
|
232
236
|
export type EngineState = SingleEngineState | MultiEngineState;
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
type SharedValue,
|
|
11
11
|
} from "react-native-reanimated";
|
|
12
12
|
import { MS_PER_FRAME_60FPS, RETURN_TO_LIVE_MS } from "../constants";
|
|
13
|
-
import type { LiveChartPoint,
|
|
13
|
+
import type { LiveChartPoint, SeriesRangeAnimationConfig, SeriesConfig } from "../types";
|
|
14
14
|
import {
|
|
15
15
|
tickLiveChartSeriesEngineFrame,
|
|
16
16
|
type MultiEngineTickInput,
|
|
@@ -21,8 +21,9 @@ import type { ChartEngineScroll, MultiEngineState } from "./useLiveChartEngine";
|
|
|
21
21
|
export interface MultiSeriesEngineConfig {
|
|
22
22
|
series: SharedValue<SeriesConfig[]>;
|
|
23
23
|
timeWindow: number;
|
|
24
|
+
historyStartTime?: number;
|
|
24
25
|
smoothing: number;
|
|
25
|
-
rangeAnimation?:
|
|
26
|
+
rangeAnimation?: SeriesRangeAnimationConfig;
|
|
26
27
|
/** Extra catch-up speed added to `smoothing` when a series tip lags. */
|
|
27
28
|
adaptiveSpeedBoost?: number;
|
|
28
29
|
exaggerate?: boolean;
|
|
@@ -34,6 +35,7 @@ export interface MultiSeriesEngineConfig {
|
|
|
34
35
|
/** Positive, finite live Y-range multiplier (1 = auto-fit); read each frame. */
|
|
35
36
|
yRangeScale?: SharedValue<number>;
|
|
36
37
|
nowOverride?: number;
|
|
38
|
+
presentationTime?: SharedValue<number | undefined>;
|
|
37
39
|
windowBuffer?: number;
|
|
38
40
|
paused?: boolean;
|
|
39
41
|
/**
|
|
@@ -69,16 +71,20 @@ export interface MultiEngineFrameRefs {
|
|
|
69
71
|
/** Drawing input published with this frame's range/tips. Optional for standalone callers. */
|
|
70
72
|
renderedSeries?: SharedValue<SeriesConfig[]>;
|
|
71
73
|
displaySeriesValues: SharedValue<number[]>;
|
|
74
|
+
smoothRecordedTail?: SharedValue<boolean>;
|
|
72
75
|
seriesOpacities: SharedValue<number[]>;
|
|
73
76
|
displayMin: SharedValue<number>;
|
|
74
77
|
displayMax: SharedValue<number>;
|
|
78
|
+
/** Persist untransformed fitted bounds even without a scratch container. */
|
|
79
|
+
fittedMinSV?: SharedValue<number | undefined>;
|
|
80
|
+
fittedMaxSV?: SharedValue<number | undefined>;
|
|
75
81
|
displayWindow: SharedValue<number>;
|
|
76
82
|
timestamp: SharedValue<number>;
|
|
77
83
|
canvasWidth: SharedValue<number>;
|
|
78
84
|
canvasHeight: SharedValue<number>;
|
|
79
85
|
timeWindow: SharedValue<number>;
|
|
80
86
|
smoothing: SharedValue<number>;
|
|
81
|
-
rangeAnimationSV?: SharedValue<
|
|
87
|
+
rangeAnimationSV?: SharedValue<SeriesRangeAnimationConfig | undefined>;
|
|
82
88
|
adaptiveSpeedBoostSV?: SharedValue<number | undefined>;
|
|
83
89
|
exaggerateSV: SharedValue<boolean>;
|
|
84
90
|
referenceValue: SharedValue<number | undefined>;
|
|
@@ -88,6 +94,10 @@ export interface MultiEngineFrameRefs {
|
|
|
88
94
|
minRangeSV?: SharedValue<number | undefined>;
|
|
89
95
|
yRangeScaleSV?: SharedValue<number>;
|
|
90
96
|
nowOverrideSV?: SharedValue<number | undefined>;
|
|
97
|
+
presentationTimeSV?: SharedValue<number | undefined>;
|
|
98
|
+
historyStartTimeSV?: SharedValue<number | undefined>;
|
|
99
|
+
currentTimeSV?: SharedValue<number>;
|
|
100
|
+
fullHistoryWindowSV?: SharedValue<number | null>;
|
|
91
101
|
windowBufferSV?: SharedValue<number>;
|
|
92
102
|
pausedSV: SharedValue<boolean>;
|
|
93
103
|
/** Pan-scroll right-edge override (null = follow live). Optional for callers/tests. */
|
|
@@ -219,6 +229,8 @@ export function applyLiveChartSeriesEngineFrame(
|
|
|
219
229
|
};
|
|
220
230
|
state.displayMin = sv.displayMin.value;
|
|
221
231
|
state.displayMax = sv.displayMax.value;
|
|
232
|
+
state.fittedMin = sv.fittedMinSV?.value ?? state.fittedMin;
|
|
233
|
+
state.fittedMax = sv.fittedMaxSV?.value ?? state.fittedMax;
|
|
222
234
|
state.displayWindow = sv.displayWindow.value;
|
|
223
235
|
state.timestamp = sv.timestamp.value;
|
|
224
236
|
state.liveEdge = sv.liveEdgeSV?.value ?? 0;
|
|
@@ -254,6 +266,8 @@ export function applyLiveChartSeriesEngineFrame(
|
|
|
254
266
|
input.minRange = sv.minRangeSV?.value;
|
|
255
267
|
input.yRangeScale = sv.yRangeScaleSV?.value ?? 1;
|
|
256
268
|
input.nowOverride = sv.nowOverrideSV?.value;
|
|
269
|
+
input.presentationTime = sv.presentationTimeSV?.value;
|
|
270
|
+
input.historyStartTime = sv.historyStartTimeSV?.value;
|
|
257
271
|
input.windowBuffer = sv.windowBufferSV?.value ?? 0;
|
|
258
272
|
input.series = seriesSnap;
|
|
259
273
|
input.nowSeconds = Date.now() / 1000;
|
|
@@ -267,10 +281,15 @@ export function applyLiveChartSeriesEngineFrame(
|
|
|
267
281
|
tickLiveChartSeriesEngineFrame(state, input);
|
|
268
282
|
sv.displayMin.value = state.displayMin;
|
|
269
283
|
sv.displayMax.value = state.displayMax;
|
|
284
|
+
if (sv.fittedMinSV) sv.fittedMinSV.value = state.fittedMin;
|
|
285
|
+
if (sv.fittedMaxSV) sv.fittedMaxSV.value = state.fittedMax;
|
|
270
286
|
sv.displayWindow.value = state.displayWindow;
|
|
271
287
|
sv.timestamp.value = state.timestamp;
|
|
272
288
|
if (sv.liveEdgeSV) sv.liveEdgeSV.value = state.liveEdge;
|
|
289
|
+
if (sv.currentTimeSV) sv.currentTimeSV.value = state.currentTime!;
|
|
290
|
+
if (sv.fullHistoryWindowSV) sv.fullHistoryWindowSV.value = state.fullHistoryWindow ?? null;
|
|
273
291
|
sv.displaySeriesValues.value = state.displayValues;
|
|
292
|
+
if (sv.smoothRecordedTail) sv.smoothRecordedTail.value = state.smoothRecordedTail ?? false;
|
|
274
293
|
sv.seriesOpacities.value = state.opacities;
|
|
275
294
|
sv.extremaMinValue.value = state.extremaMinValue;
|
|
276
295
|
sv.extremaMaxValue.value = state.extremaMaxValue;
|
|
@@ -301,11 +320,17 @@ export function applyLiveChartSeriesEngineFrame(
|
|
|
301
320
|
*/
|
|
302
321
|
export function useLiveChartSeriesEngine(
|
|
303
322
|
config: MultiSeriesEngineConfig,
|
|
304
|
-
): MultiEngineState & ChartEngineScroll {
|
|
323
|
+
): MultiEngineState & ChartEngineScroll & {
|
|
324
|
+
currentTime: SharedValue<number>;
|
|
325
|
+
fullHistoryWindow: SharedValue<number | null>;
|
|
326
|
+
} {
|
|
305
327
|
// Pinch-zoom window-width override (null = follow the configured window).
|
|
306
328
|
// Declared first so `timeWindow` folds it in — see useLiveChartEngine.
|
|
307
329
|
const viewWindow = useSharedValue<number | null>(null);
|
|
308
|
-
const
|
|
330
|
+
const fullHistoryWindow = useSharedValue<number | null>(null);
|
|
331
|
+
const timeWindow = useDerivedValue(() => viewWindow.value ?? fullHistoryWindow.value ?? config.timeWindow);
|
|
332
|
+
const configuredTimeWindow = useDerivedValue(() => config.timeWindow);
|
|
333
|
+
const historyStartTimeSV = useDerivedValue(() => config.historyStartTime);
|
|
309
334
|
const smoothing = useDerivedValue(() => config.smoothing);
|
|
310
335
|
const rangeAnimationSV = useDerivedValue(() => config.rangeAnimation);
|
|
311
336
|
const adaptiveSpeedBoostSV = useDerivedValue(() => config.adaptiveSpeedBoost);
|
|
@@ -332,12 +357,16 @@ export function useLiveChartSeriesEngine(
|
|
|
332
357
|
|
|
333
358
|
const displayMin = useSharedValue(0);
|
|
334
359
|
const displayMax = useSharedValue(1);
|
|
360
|
+
const fittedMinSV = useSharedValue<number | undefined>(undefined);
|
|
361
|
+
const fittedMaxSV = useSharedValue<number | undefined>(undefined);
|
|
335
362
|
const displayWindow = useSharedValue(config.timeWindow);
|
|
336
363
|
const canvasWidth = useSharedValue(0);
|
|
337
364
|
const canvasHeight = useSharedValue(0);
|
|
338
365
|
// Seed once; overwritten by the frame callback on the first tick.
|
|
339
366
|
const [initialTimestamp] = useState(() => Date.now() / 1000);
|
|
340
367
|
const timestamp = useSharedValue(initialTimestamp);
|
|
368
|
+
const currentTime = useSharedValue(initialTimestamp);
|
|
369
|
+
const tipTime = useDerivedValue(() => Math.min(timestamp.value, currentTime.value));
|
|
341
370
|
|
|
342
371
|
// Pan-scroll state (see useLiveChartEngine). Defaults to following live.
|
|
343
372
|
const viewEnd = useSharedValue<number | null>(null);
|
|
@@ -348,6 +377,7 @@ export function useLiveChartSeriesEngine(
|
|
|
348
377
|
const returnFrom = useSharedValue(0);
|
|
349
378
|
|
|
350
379
|
const displaySeriesValues = useSharedValue<number[]>([]);
|
|
380
|
+
const smoothRecordedTail = useSharedValue(false);
|
|
351
381
|
const seriesOpacities = useSharedValue<number[]>([]);
|
|
352
382
|
const renderedSeries = useSharedValue<SeriesConfig[]>([]);
|
|
353
383
|
|
|
@@ -387,14 +417,19 @@ export function useLiveChartSeriesEngine(
|
|
|
387
417
|
series,
|
|
388
418
|
renderedSeries,
|
|
389
419
|
displaySeriesValues,
|
|
420
|
+
smoothRecordedTail,
|
|
390
421
|
seriesOpacities,
|
|
391
422
|
displayMin,
|
|
392
423
|
displayMax,
|
|
424
|
+
fittedMinSV,
|
|
425
|
+
fittedMaxSV,
|
|
393
426
|
displayWindow,
|
|
394
427
|
timestamp,
|
|
395
428
|
canvasWidth,
|
|
396
429
|
canvasHeight,
|
|
397
|
-
timeWindow,
|
|
430
|
+
timeWindow: configuredTimeWindow,
|
|
431
|
+
historyStartTimeSV,
|
|
432
|
+
fullHistoryWindowSV: fullHistoryWindow,
|
|
398
433
|
smoothing,
|
|
399
434
|
rangeAnimationSV,
|
|
400
435
|
adaptiveSpeedBoostSV,
|
|
@@ -406,6 +441,8 @@ export function useLiveChartSeriesEngine(
|
|
|
406
441
|
minRangeSV,
|
|
407
442
|
yRangeScaleSV: config.yRangeScale,
|
|
408
443
|
nowOverrideSV,
|
|
444
|
+
presentationTimeSV: config.presentationTime,
|
|
445
|
+
currentTimeSV: currentTime,
|
|
409
446
|
windowBufferSV,
|
|
410
447
|
pausedSV,
|
|
411
448
|
viewEndSV: viewEnd,
|
|
@@ -473,8 +510,12 @@ export function useLiveChartSeriesEngine(
|
|
|
473
510
|
viewEnd,
|
|
474
511
|
viewWindow,
|
|
475
512
|
liveEdge,
|
|
513
|
+
currentTime,
|
|
514
|
+
tipTime,
|
|
515
|
+
fullHistoryWindow,
|
|
476
516
|
series: renderedSeries,
|
|
477
517
|
displaySeriesValues,
|
|
518
|
+
smoothRecordedTail,
|
|
478
519
|
seriesOpacities,
|
|
479
520
|
extremaMinValue,
|
|
480
521
|
extremaMaxValue,
|
package/src/draw/grid.ts
CHANGED
|
@@ -17,6 +17,16 @@ export interface RightAnchoredYAxisColumnLayout {
|
|
|
17
17
|
gridEndX: number;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/** Width used by the painted right-anchored column, including fading entries. */
|
|
21
|
+
export function widestYAxisLabelWidth(entries: readonly YAxisEntry[], font: SkFont): number {
|
|
22
|
+
"worklet";
|
|
23
|
+
let width = 0;
|
|
24
|
+
for (let i = 0; i < entries.length; i++) {
|
|
25
|
+
width = Math.max(width, measureFontTextWidth(font, entries[i].label));
|
|
26
|
+
}
|
|
27
|
+
return width;
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
/**
|
|
21
31
|
* Measure the widest Y-axis label and anchor the shared left-aligned column to
|
|
22
32
|
* a fixed canvas-edge margin. Shared by the axis, reference-line and live-badge
|
|
@@ -30,13 +40,7 @@ export function rightAnchoredYAxisColumnLayout(
|
|
|
30
40
|
gridEndGap = 0,
|
|
31
41
|
): RightAnchoredYAxisColumnLayout {
|
|
32
42
|
"worklet";
|
|
33
|
-
|
|
34
|
-
for (let i = 0; i < entries.length; i++) {
|
|
35
|
-
maxTextW = Math.max(
|
|
36
|
-
maxTextW,
|
|
37
|
-
measureFontTextWidth(font, entries[i].label),
|
|
38
|
-
);
|
|
39
|
-
}
|
|
43
|
+
const maxTextW = widestYAxisLabelWidth(entries, font);
|
|
40
44
|
const labelX = canvasWidth - labelRightMargin - maxTextW;
|
|
41
45
|
return { labelX, gridEndX: labelX - gridEndGap };
|
|
42
46
|
}
|
|
@@ -59,7 +63,7 @@ export function fixedGridEntries(
|
|
|
59
63
|
padTop: number,
|
|
60
64
|
count: number,
|
|
61
65
|
minGap: number,
|
|
62
|
-
formatValue: (v: number) => string,
|
|
66
|
+
formatValue: (v: number, tickStep?: number) => string,
|
|
63
67
|
): YAxisEntry[] {
|
|
64
68
|
"worklet";
|
|
65
69
|
// minGap floor: at most `floor(chartH / minGap)` gaps fit ⇒ that many + 1 labels.
|
|
@@ -73,7 +77,7 @@ export function fixedGridEntries(
|
|
|
73
77
|
for (let i = 0; i < n; i++) {
|
|
74
78
|
const y = padTop + i * stepPx;
|
|
75
79
|
const val = displayMax - i * stepVal;
|
|
76
|
-
entries.push({ y, label: formatValue(val), alpha: 1 });
|
|
80
|
+
entries.push({ y, label: formatValue(val, stepVal), alpha: 1 });
|
|
77
81
|
}
|
|
78
82
|
return entries;
|
|
79
83
|
}
|
|
@@ -164,7 +168,7 @@ export function computeGridEntries(
|
|
|
164
168
|
padBottom: number,
|
|
165
169
|
prevInterval: number,
|
|
166
170
|
labelAlphas: Record<number, number>,
|
|
167
|
-
formatValue: (v: number) => string,
|
|
171
|
+
formatValue: (v: number, tickStep?: number) => string,
|
|
168
172
|
dt: number,
|
|
169
173
|
minGap = 36,
|
|
170
174
|
grid: GridMetrics = GRID_METRICS_DEFAULTS,
|
|
@@ -299,7 +303,7 @@ export function computeGridEntries(
|
|
|
299
303
|
const y = gridValueToY(val, displayMax, valRange, padTop, chartH);
|
|
300
304
|
/* istanbul ignore next -- vertical clip; y stays in-band when val comes from tracked keys */
|
|
301
305
|
if (y < padTop - 10 || y > canvasHeight - padBottom + 10) continue;
|
|
302
|
-
entries.push({ y, label: formatValue(val), alpha });
|
|
306
|
+
entries.push({ y, label: formatValue(val, fine), alpha });
|
|
303
307
|
}
|
|
304
308
|
|
|
305
309
|
return { entries, interval };
|
package/src/draw/line.ts
CHANGED
|
@@ -237,10 +237,24 @@ export function seriesPlotClip(
|
|
|
237
237
|
};
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
+
/** Project a presented head, clamped to the viewport edge, into the plot. */
|
|
241
|
+
export function lineTipX(
|
|
242
|
+
viewportEnd: number,
|
|
243
|
+
windowSecs: number,
|
|
244
|
+
tipTime: number,
|
|
245
|
+
canvasWidth: number,
|
|
246
|
+
padding: ChartPadding,
|
|
247
|
+
): number {
|
|
248
|
+
"worklet";
|
|
249
|
+
const chartW = canvasWidth - padding.left - padding.right;
|
|
250
|
+
if (windowSecs <= 0 || chartW <= 0) return -100;
|
|
251
|
+
return padding.left + ((Math.min(viewportEnd, tipTime) - (viewportEnd - windowSecs)) / windowSecs) * chartW;
|
|
252
|
+
}
|
|
253
|
+
|
|
240
254
|
/**
|
|
241
255
|
* Build screen-space points as a flat number array [x0, y0, x1, y1, ...].
|
|
242
256
|
* Includes one point before the window for smooth left-edge entry,
|
|
243
|
-
* and appends a live tip at (now, displayValue).
|
|
257
|
+
* and appends a live tip at (min(now, tipTime), displayValue).
|
|
244
258
|
*
|
|
245
259
|
* Flat layout avoids ~150 tuple object allocations per frame.
|
|
246
260
|
*
|
|
@@ -263,6 +277,10 @@ export function buildLinePoints(
|
|
|
263
277
|
padding: ChartPadding,
|
|
264
278
|
out?: number[],
|
|
265
279
|
omitTipBeyondData = false,
|
|
280
|
+
/** Optional presentation head; viewport end still determines the projection. */
|
|
281
|
+
tipTime = now,
|
|
282
|
+
/** Present only the newest recorded sample at the live tip's eased value. */
|
|
283
|
+
liveTailValue?: number,
|
|
266
284
|
): number[] {
|
|
267
285
|
"worklet";
|
|
268
286
|
const pts: number[] = out ?? [];
|
|
@@ -275,6 +293,8 @@ export function buildLinePoints(
|
|
|
275
293
|
return pts;
|
|
276
294
|
|
|
277
295
|
const winStart = now - windowSecs;
|
|
296
|
+
const head = Math.min(now, tipTime);
|
|
297
|
+
if (head < winStart || windowSecs <= 0) return pts;
|
|
278
298
|
|
|
279
299
|
// Binary search for first point >= winStart
|
|
280
300
|
let lo = 0;
|
|
@@ -291,10 +311,14 @@ export function buildLinePoints(
|
|
|
291
311
|
let ehi = data.length;
|
|
292
312
|
while (elo < ehi) {
|
|
293
313
|
const emid = (elo + ehi) >> 1;
|
|
294
|
-
if (data[emid].time <=
|
|
314
|
+
if (data[emid].time <= head) elo = emid + 1;
|
|
295
315
|
else ehi = emid;
|
|
296
316
|
}
|
|
297
317
|
const endIdx = elo;
|
|
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;
|
|
298
322
|
|
|
299
323
|
const xScale = chartW / windowSecs;
|
|
300
324
|
const yScale = chartH / valRange;
|
|
@@ -311,7 +335,7 @@ export function buildLinePoints(
|
|
|
311
335
|
for (let i = startIdx; i < endIdx; i++) {
|
|
312
336
|
pts.push(
|
|
313
337
|
padding.left + (data[i].time - winStart) * xScale,
|
|
314
|
-
padding.top + (displayMax - data[i].value) * yScale,
|
|
338
|
+
padding.top + (displayMax - (i === tailIdx ? liveTailValue! : data[i].value)) * yScale,
|
|
315
339
|
);
|
|
316
340
|
}
|
|
317
341
|
} else {
|
|
@@ -333,12 +357,12 @@ export function buildLinePoints(
|
|
|
333
357
|
const b = minIdx <= maxIdx ? maxIdx : minIdx;
|
|
334
358
|
pts.push(
|
|
335
359
|
padding.left + (data[a].time - winStart) * xScale,
|
|
336
|
-
padding.top + (displayMax - data[a].value) * yScale,
|
|
360
|
+
padding.top + (displayMax - (a === tailIdx ? liveTailValue! : data[a].value)) * yScale,
|
|
337
361
|
);
|
|
338
362
|
if (b !== a) {
|
|
339
363
|
pts.push(
|
|
340
364
|
padding.left + (data[b].time - winStart) * xScale,
|
|
341
|
-
padding.top + (displayMax - data[b].value) * yScale,
|
|
365
|
+
padding.top + (displayMax - (b === tailIdx ? liveTailValue! : data[b].value)) * yScale,
|
|
342
366
|
);
|
|
343
367
|
}
|
|
344
368
|
}
|
|
@@ -346,8 +370,9 @@ export function buildLinePoints(
|
|
|
346
370
|
minIdx = i;
|
|
347
371
|
maxIdx = i;
|
|
348
372
|
} else {
|
|
349
|
-
|
|
350
|
-
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;
|
|
351
376
|
}
|
|
352
377
|
}
|
|
353
378
|
// Flush the final column.
|
|
@@ -355,12 +380,12 @@ export function buildLinePoints(
|
|
|
355
380
|
const b = minIdx <= maxIdx ? maxIdx : minIdx;
|
|
356
381
|
pts.push(
|
|
357
382
|
padding.left + (data[a].time - winStart) * xScale,
|
|
358
|
-
padding.top + (displayMax - data[a].value) * yScale,
|
|
383
|
+
padding.top + (displayMax - (a === tailIdx ? liveTailValue! : data[a].value)) * yScale,
|
|
359
384
|
);
|
|
360
385
|
if (b !== a) {
|
|
361
386
|
pts.push(
|
|
362
387
|
padding.left + (data[b].time - winStart) * xScale,
|
|
363
|
-
padding.top + (displayMax - data[b].value) * yScale,
|
|
388
|
+
padding.top + (displayMax - (b === tailIdx ? liveTailValue! : data[b].value)) * yScale,
|
|
364
389
|
);
|
|
365
390
|
}
|
|
366
391
|
}
|
|
@@ -372,14 +397,14 @@ export function buildLinePoints(
|
|
|
372
397
|
if (
|
|
373
398
|
omitTipBeyondData &&
|
|
374
399
|
endIdx === data.length &&
|
|
375
|
-
data[endIdx - 1].time <
|
|
400
|
+
data[endIdx - 1].time < head
|
|
376
401
|
) {
|
|
377
402
|
return pts;
|
|
378
403
|
}
|
|
379
404
|
|
|
380
405
|
// Live tip at current time with smoothed value
|
|
381
406
|
pts.push(
|
|
382
|
-
|
|
407
|
+
lineTipX(now, windowSecs, head, canvasWidth, padding),
|
|
383
408
|
padding.top + ((displayMax - displayValue) / valRange) * chartH,
|
|
384
409
|
);
|
|
385
410
|
|