react-native-livechart 4.31.0 → 4.32.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/README.md +3 -0
- package/dist/components/ChartOverlayLayer.d.ts +3 -1
- package/dist/components/ChartOverlayLayer.d.ts.map +1 -1
- package/dist/components/CrosshairOverlay.d.ts +3 -1
- package/dist/components/CrosshairOverlay.d.ts.map +1 -1
- package/dist/components/CustomMarkerOverlay.d.ts +2 -2
- package/dist/components/CustomMarkerOverlay.d.ts.map +1 -1
- package/dist/components/FreeCrosshairOverlay.d.ts +25 -0
- package/dist/components/FreeCrosshairOverlay.d.ts.map +1 -0
- package/dist/components/LiveChart.d.ts.map +1 -1
- package/dist/components/LiveChartSeries.d.ts.map +1 -1
- package/dist/components/MarkerOverlay.d.ts +2 -2
- package/dist/components/MarkerOverlay.d.ts.map +1 -1
- package/dist/components/ScrubActionOverlay.d.ts +7 -1
- package/dist/components/ScrubActionOverlay.d.ts.map +1 -1
- package/dist/core/liveChartEngineTick.d.ts +2 -0
- package/dist/core/liveChartEngineTick.d.ts.map +1 -1
- package/dist/core/liveChartSeriesEngineTick.d.ts +6 -0
- package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
- package/dist/core/resolveConfig.d.ts +4 -0
- package/dist/core/resolveConfig.d.ts.map +1 -1
- package/dist/core/useLiveChartEngine.d.ts +7 -2
- package/dist/core/useLiveChartEngine.d.ts.map +1 -1
- package/dist/core/useLiveChartSeriesEngine.d.ts +9 -1
- package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
- package/dist/hooks/crosshairSeries.d.ts +1 -1
- package/dist/hooks/crosshairSeries.d.ts.map +1 -1
- package/dist/hooks/crosshairShared.d.ts +4 -2
- package/dist/hooks/crosshairShared.d.ts.map +1 -1
- package/dist/hooks/useCrosshair.d.ts +5 -1
- package/dist/hooks/useCrosshair.d.ts.map +1 -1
- package/dist/hooks/useCrosshairSeries.d.ts.map +1 -1
- package/dist/hooks/useMarkers.d.ts +2 -2
- package/dist/hooks/useMarkers.d.ts.map +1 -1
- package/dist/hooks/usePanScroll.d.ts +2 -0
- package/dist/hooks/usePanScroll.d.ts.map +1 -1
- package/dist/hooks/usePinchZoom.d.ts +2 -0
- package/dist/hooks/usePinchZoom.d.ts.map +1 -1
- package/dist/hooks/useReferenceLineSeries.d.ts +1 -1
- package/dist/hooks/useReferenceLineSeries.d.ts.map +1 -1
- package/dist/hooks/useScrubMarkers.d.ts +2 -1
- package/dist/hooks/useScrubMarkers.d.ts.map +1 -1
- package/dist/hooks/useVisibleRange.d.ts +8 -17
- package/dist/hooks/useVisibleRange.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/math/markers.d.ts +6 -0
- package/dist/math/markers.d.ts.map +1 -1
- package/dist/math/referenceLineSeries.d.ts +1 -1
- package/dist/math/referenceLineSeries.d.ts.map +1 -1
- package/dist/math/scrubMarkers.d.ts +1 -1
- package/dist/math/scrubMarkers.d.ts.map +1 -1
- package/dist/math/spline.d.ts +3 -2
- package/dist/math/spline.d.ts.map +1 -1
- package/dist/types.d.ts +51 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/ChartOverlayLayer.tsx +9 -3
- package/src/components/CrosshairOverlay.tsx +7 -0
- package/src/components/CustomMarkerOverlay.tsx +5 -2
- package/src/components/FreeCrosshairOverlay.tsx +87 -0
- package/src/components/LiveChart.tsx +105 -75
- package/src/components/LiveChartSeries.tsx +41 -22
- package/src/components/MarkerOverlay.tsx +24 -14
- package/src/components/ScrubActionOverlay.tsx +24 -5
- package/src/core/liveChartEngineTick.ts +3 -0
- package/src/core/liveChartSeriesEngineTick.ts +25 -4
- package/src/core/resolveConfig.ts +13 -0
- package/src/core/useLiveChartEngine.ts +14 -2
- package/src/core/useLiveChartSeriesEngine.ts +44 -7
- package/src/hooks/crosshairSeries.ts +4 -4
- package/src/hooks/crosshairShared.ts +18 -12
- package/src/hooks/useCrosshair.ts +29 -5
- package/src/hooks/useCrosshairSeries.ts +10 -4
- package/src/hooks/useMarkers.ts +7 -4
- package/src/hooks/usePanScroll.ts +3 -1
- package/src/hooks/usePinchZoom.ts +8 -5
- package/src/hooks/useReferenceLineSeries.ts +8 -4
- package/src/hooks/useScrubMarkers.ts +5 -2
- package/src/hooks/useVisibleRange.ts +96 -66
- package/src/index.ts +1 -0
- package/src/math/markers.ts +25 -8
- package/src/math/referenceLineSeries.ts +4 -3
- package/src/math/scrubMarkers.ts +4 -1
- package/src/math/spline.ts +41 -25
- package/src/types.ts +49 -7
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef } from "react";
|
|
2
2
|
import {
|
|
3
|
+
makeMutable,
|
|
4
|
+
startMapper,
|
|
5
|
+
stopMapper,
|
|
3
6
|
useAnimatedReaction,
|
|
4
7
|
type SharedValue,
|
|
5
8
|
} from "react-native-reanimated";
|
|
6
|
-
import { scheduleOnRN } from "react-native-worklets";
|
|
9
|
+
import { scheduleOnRN, scheduleOnUI } from "react-native-worklets";
|
|
7
10
|
|
|
8
11
|
import type { VisibleRange } from "../types";
|
|
12
|
+
import { useLatestCallback } from "./useLatestCallback";
|
|
9
13
|
|
|
10
14
|
export type { VisibleRange };
|
|
11
15
|
|
|
@@ -13,13 +17,16 @@ export type { VisibleRange };
|
|
|
13
17
|
export interface VisibleRangeEngineRefs {
|
|
14
18
|
timestamp: SharedValue<number>;
|
|
15
19
|
displayWindow: SharedValue<number>;
|
|
16
|
-
|
|
20
|
+
following: SharedValue<boolean>;
|
|
21
|
+
/** Ordinary viewport before the multi-series future horizon is applied. */
|
|
22
|
+
navigationEnd?: SharedValue<number>;
|
|
23
|
+
navigationWindow?: SharedValue<number>;
|
|
17
24
|
}
|
|
18
25
|
|
|
19
26
|
export interface UseVisibleRangeOptions {
|
|
20
27
|
engine: VisibleRangeEngineRefs;
|
|
21
|
-
/** Earliest retained time
|
|
22
|
-
minTime: SharedValue<number>;
|
|
28
|
+
/** Earliest retained time in seconds, or null until the chart has a history bound. */
|
|
29
|
+
minTime: Pick<SharedValue<number | null>, "get">;
|
|
23
30
|
/** Fires (throttled to ~1 Hz) when the visible window's edges change. */
|
|
24
31
|
onVisibleRangeChange?: (range: VisibleRange) => void;
|
|
25
32
|
/**
|
|
@@ -30,21 +37,6 @@ export interface UseVisibleRangeOptions {
|
|
|
30
37
|
onReachStart?: () => void;
|
|
31
38
|
}
|
|
32
39
|
|
|
33
|
-
/**
|
|
34
|
-
* Throttle key for a visible range: integer seconds of each edge plus the
|
|
35
|
-
* near-start flag. The reaction emits only when this changes, so a live chart
|
|
36
|
-
* (whose right edge slides every frame) notifies at most ~once per second rather
|
|
37
|
-
* than per frame, and `onReachStart` edge-triggers off the trailing flag.
|
|
38
|
-
*/
|
|
39
|
-
export function rangeSignature(
|
|
40
|
-
startSec: number,
|
|
41
|
-
endSec: number,
|
|
42
|
-
near: boolean,
|
|
43
|
-
): string {
|
|
44
|
-
"worklet";
|
|
45
|
-
return `${Math.round(startSec)}|${Math.round(endSec)}|${near ? 1 : 0}`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
40
|
/** Whether the window's left edge is within `threshold` seconds of the oldest data. */
|
|
49
41
|
export function isNearStart(
|
|
50
42
|
winStart: number,
|
|
@@ -55,65 +47,103 @@ export function isNearStart(
|
|
|
55
47
|
return winStart <= minTime + threshold;
|
|
56
48
|
}
|
|
57
49
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
*/
|
|
50
|
+
// React Native supplies this monotonic clock. The library builds without DOM types.
|
|
51
|
+
declare const performance: { now(): number };
|
|
52
|
+
|
|
53
|
+
const RANGE_INTERVAL_MS = 1000;
|
|
54
|
+
|
|
55
|
+
/** Report the drawn viewport to JS paging callbacks on either chart. */
|
|
64
56
|
export function useVisibleRange({
|
|
65
|
-
engine,
|
|
57
|
+
engine: { timestamp, displayWindow, following, navigationEnd = timestamp, navigationWindow = displayWindow },
|
|
66
58
|
minTime,
|
|
67
59
|
onVisibleRangeChange,
|
|
68
60
|
onReachStart,
|
|
69
61
|
}: UseVisibleRangeOptions): void {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
const readRange = useCallback((): VisibleRange => {
|
|
63
|
+
"worklet";
|
|
64
|
+
const endSec = timestamp.get();
|
|
65
|
+
return { startSec: endSec - displayWindow.get(), endSec, following: following.get() };
|
|
66
|
+
}, [timestamp, displayWindow, following]);
|
|
67
|
+
const lastReport = useRef<{ range: VisibleRange; time: number } | null>(null);
|
|
68
|
+
const emitRange = useLatestCallback((range: VisibleRange) => {
|
|
69
|
+
const previous = lastReport.current?.range;
|
|
70
|
+
if (!onVisibleRangeChange) return;
|
|
71
|
+
if (
|
|
72
|
+
previous?.startSec === range.startSec &&
|
|
73
|
+
previous.endSec === range.endSec &&
|
|
74
|
+
previous.following === range.following
|
|
75
|
+
) return;
|
|
76
|
+
lastReport.current = { range, time: performance.now() };
|
|
77
|
+
onVisibleRangeChange(range);
|
|
78
|
+
});
|
|
79
|
+
const emitReachStart = useLatestCallback((range: VisibleRange) => {
|
|
80
|
+
if (!onReachStart) return;
|
|
81
|
+
// Paging loaders read the last reported range synchronously in onReachStart.
|
|
82
|
+
emitRange(range);
|
|
83
|
+
onReachStart();
|
|
84
|
+
});
|
|
85
|
+
const watchRange = onVisibleRangeChange != null;
|
|
86
|
+
const watchStart = onReachStart != null;
|
|
87
|
+
|
|
74
88
|
useEffect(() => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
89
|
+
if (!watchRange) return;
|
|
90
|
+
const pending = makeMutable(false);
|
|
91
|
+
let active = true;
|
|
92
|
+
let timeout: ReturnType<typeof setTimeout>;
|
|
78
93
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
function deliver(range: VisibleRange) {
|
|
95
|
+
if (!active) return;
|
|
96
|
+
emitRange(range);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function flush() {
|
|
100
|
+
// Sample all three fields on the same UI frame, including the final range
|
|
101
|
+
// when the chart has stopped producing frames during the throttle interval.
|
|
102
|
+
scheduleOnUI(() => {
|
|
103
|
+
"worklet";
|
|
104
|
+
pending.set(false);
|
|
105
|
+
scheduleOnRN(deliver, readRange());
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function requestReport() {
|
|
110
|
+
if (!active) return;
|
|
111
|
+
const lastTime = lastReport.current?.time ?? -Infinity;
|
|
112
|
+
const remaining = RANGE_INTERVAL_MS - (performance.now() - lastTime);
|
|
113
|
+
// A paging callback can report a newer viewport while the timer is waiting.
|
|
114
|
+
if (remaining > 0) timeout = setTimeout(requestReport, Math.ceil(remaining));
|
|
115
|
+
else flush();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Subscribe only to the viewport. Keep one JS request in flight while any
|
|
119
|
+
// number of pan, zoom, or horizon frames update the range underneath it.
|
|
120
|
+
const mapper = startMapper(() => {
|
|
121
|
+
"worklet";
|
|
122
|
+
if (!pending.get()) {
|
|
123
|
+
pending.set(true);
|
|
124
|
+
scheduleOnRN(requestReport);
|
|
125
|
+
}
|
|
126
|
+
}, [timestamp, displayWindow, following]);
|
|
93
127
|
|
|
94
|
-
|
|
128
|
+
return () => {
|
|
129
|
+
active = false;
|
|
130
|
+
lastReport.current = null;
|
|
131
|
+
stopMapper(mapper);
|
|
132
|
+
clearTimeout(timeout);
|
|
133
|
+
};
|
|
134
|
+
}, [watchRange, timestamp, displayWindow, following, readRange, emitRange]);
|
|
95
135
|
|
|
96
136
|
useAnimatedReaction(
|
|
97
|
-
/* istanbul ignore next -- Reanimated reaction worklet; runs on the UI thread, not in Jest */
|
|
98
137
|
() => {
|
|
99
|
-
if (!
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
return
|
|
138
|
+
if (!watchStart) return false;
|
|
139
|
+
const oldest = minTime.get();
|
|
140
|
+
if (oldest === null) return false;
|
|
141
|
+
const width = navigationWindow.get();
|
|
142
|
+
return isNearStart(navigationEnd.get() - width, oldest, width);
|
|
104
143
|
},
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (!active || curr === "" || curr === prev) return;
|
|
108
|
-
const end = engine.timestamp.value;
|
|
109
|
-
const win = engine.displayWindow.value;
|
|
110
|
-
const start = end - win;
|
|
111
|
-
const following = engine.viewEnd.value == null;
|
|
112
|
-
const near = isNearStart(start, minTime.value, win);
|
|
113
|
-
const wasNear = typeof prev === "string" && prev.endsWith("|1");
|
|
114
|
-
scheduleOnRN(emitRange, start, end, following);
|
|
115
|
-
if (near && !wasNear) scheduleOnRN(emitReachStart);
|
|
144
|
+
(near, wasNear) => {
|
|
145
|
+
if (near && !wasNear) scheduleOnRN(emitReachStart, readRange());
|
|
116
146
|
},
|
|
117
|
-
[
|
|
147
|
+
[watchStart, navigationEnd, navigationWindow, minTime, readRange, emitReachStart],
|
|
118
148
|
);
|
|
119
149
|
}
|
package/src/index.ts
CHANGED
package/src/math/markers.ts
CHANGED
|
@@ -33,6 +33,10 @@ export interface ProjectMarkersOpts {
|
|
|
33
33
|
displayWindow: number;
|
|
34
34
|
displayMin: number;
|
|
35
35
|
displayMax: number;
|
|
36
|
+
/** Last time with a presented series anchor; the viewport may extend beyond it. */
|
|
37
|
+
tipTime?: number;
|
|
38
|
+
displaySeriesValues?: number[];
|
|
39
|
+
smoothRecordedTail?: boolean;
|
|
36
40
|
/** Multi-series data, used to anchor markers by `seriesId`. */
|
|
37
41
|
series?: SeriesConfig[];
|
|
38
42
|
/** Single-series line data; anchors markers that omit `value` (and `seriesId`). */
|
|
@@ -63,6 +67,17 @@ const CULL_MARGIN = 24;
|
|
|
63
67
|
*/
|
|
64
68
|
const EDGE_SLOP = 0.5;
|
|
65
69
|
|
|
70
|
+
/** Absolute-value events can appear ahead of a series tip. */
|
|
71
|
+
export function isFutureSeriesMarker(
|
|
72
|
+
time: number,
|
|
73
|
+
value: number | undefined,
|
|
74
|
+
seriesId: string | undefined,
|
|
75
|
+
tipTime: number | undefined,
|
|
76
|
+
): boolean {
|
|
77
|
+
"worklet";
|
|
78
|
+
return tipTime !== undefined && time > tipTime && value === undefined && seriesId !== undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
66
81
|
/**
|
|
67
82
|
* Project one marker (given its primitive anchor fields) into `target`,
|
|
68
83
|
* without allocation. Primitives only, so per-glyph worklet closures don't
|
|
@@ -96,7 +111,8 @@ function projectInto(
|
|
|
96
111
|
h === 0 ||
|
|
97
112
|
chartW <= 0 ||
|
|
98
113
|
opts.displayWindow <= 0 ||
|
|
99
|
-
valRange <= 0
|
|
114
|
+
valRange <= 0 ||
|
|
115
|
+
isFutureSeriesMarker(time, value, seriesId, opts.tipTime)
|
|
100
116
|
) {
|
|
101
117
|
target.visible = false;
|
|
102
118
|
return;
|
|
@@ -107,13 +123,14 @@ function projectInto(
|
|
|
107
123
|
} else if (seriesId !== undefined && opts.series) {
|
|
108
124
|
for (let j = 0; j < opts.series.length; j++) {
|
|
109
125
|
if (opts.series[j].id === seriesId) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
126
|
+
const series = opts.series[j];
|
|
127
|
+
const tip = opts.tipTime === undefined ? undefined : {
|
|
128
|
+
time: opts.tipTime,
|
|
129
|
+
value: opts.displaySeriesValues?.[j] ?? series.value,
|
|
130
|
+
};
|
|
131
|
+
const latest = series.data[series.data.length - 1];
|
|
132
|
+
v = splineValueAtTime(series.data, time, series.curve === "linear", tip,
|
|
133
|
+
opts.smoothRecordedTail && latest?.value === series.value);
|
|
117
134
|
break;
|
|
118
135
|
}
|
|
119
136
|
}
|
|
@@ -13,7 +13,7 @@ import { thresholdLineY } from "./threshold";
|
|
|
13
13
|
*/
|
|
14
14
|
export function buildReferenceLineSeriesPoints(
|
|
15
15
|
points: LiveChartPoint[],
|
|
16
|
-
|
|
16
|
+
viewportEnd: number,
|
|
17
17
|
windowSecs: number,
|
|
18
18
|
displayMin: number,
|
|
19
19
|
displayMax: number,
|
|
@@ -23,6 +23,7 @@ export function buildReferenceLineSeriesPoints(
|
|
|
23
23
|
extendToStart: boolean,
|
|
24
24
|
extendToNow: boolean,
|
|
25
25
|
out?: number[],
|
|
26
|
+
headTime = viewportEnd,
|
|
26
27
|
): number[] {
|
|
27
28
|
"worklet";
|
|
28
29
|
const result = out ?? [];
|
|
@@ -43,13 +44,13 @@ export function buildReferenceLineSeriesPoints(
|
|
|
43
44
|
return result;
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
const windowStart =
|
|
47
|
+
const windowStart = viewportEnd - windowSecs;
|
|
47
48
|
const firstTime = points[0].time;
|
|
48
49
|
const lastTime = points[points.length - 1].time;
|
|
49
50
|
const startTime = extendToStart
|
|
50
51
|
? windowStart
|
|
51
52
|
: Math.max(windowStart, firstTime);
|
|
52
|
-
const endTime = extendToNow ?
|
|
53
|
+
const endTime = extendToNow ? headTime : Math.min(headTime, lastTime);
|
|
53
54
|
if (endTime < startTime) return result;
|
|
54
55
|
|
|
55
56
|
const startValue = interpolateAtTime(points, startTime);
|
package/src/math/scrubMarkers.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Marker } from "../types";
|
|
2
|
+
import { isFutureSeriesMarker } from "./markers";
|
|
2
3
|
|
|
3
4
|
export interface ScrubMarkerRange {
|
|
4
5
|
from: number;
|
|
@@ -11,12 +12,14 @@ export interface ScrubMarkerRange {
|
|
|
11
12
|
export function matchScrubMarkers(
|
|
12
13
|
markers: Marker[],
|
|
13
14
|
range: ScrubMarkerRange | null,
|
|
15
|
+
tipTime?: number,
|
|
14
16
|
): Marker[] {
|
|
15
17
|
"worklet";
|
|
16
18
|
if (!range) return [];
|
|
17
19
|
return markers.filter(
|
|
18
20
|
(marker) => marker.time >= range.from &&
|
|
19
|
-
(range.exclusiveEnd ? marker.time < range.to : marker.time <= range.to)
|
|
21
|
+
(range.exclusiveEnd ? marker.time < range.to : marker.time <= range.to) &&
|
|
22
|
+
!isFutureSeriesMarker(marker.time, marker.value, marker.seriesId, tipTime),
|
|
20
23
|
);
|
|
21
24
|
}
|
|
22
25
|
|
package/src/math/spline.ts
CHANGED
|
@@ -146,7 +146,8 @@ export function drawSpline(
|
|
|
146
146
|
* Value of the Fritsch–Carlson monotone cubic — the same curve {@link drawSpline}
|
|
147
147
|
* renders — at `time`. Use this to anchor overlays (e.g. markers) exactly on the
|
|
148
148
|
* rendered line instead of on the straight chord between data points. Returns
|
|
149
|
-
* `null` for empty data
|
|
149
|
+
* `null` for empty data. A supplied tip replaces buffered future points and
|
|
150
|
+
* terminates the curve at its presented value. Linear series use the chord.
|
|
150
151
|
*
|
|
151
152
|
* The data→pixel mapping is affine, so evaluating the monotone cubic in data
|
|
152
153
|
* space and then projecting matches the pixel-space spline. Tangents use the
|
|
@@ -157,46 +158,61 @@ export function drawSpline(
|
|
|
157
158
|
export function splineValueAtTime(
|
|
158
159
|
points: LiveChartPoint[],
|
|
159
160
|
time: number,
|
|
161
|
+
linear = false,
|
|
162
|
+
tip?: LiveChartPoint,
|
|
163
|
+
smoothRecordedTail = false,
|
|
160
164
|
): number | null {
|
|
161
165
|
"worklet";
|
|
162
166
|
const n = points.length;
|
|
163
|
-
if (n
|
|
164
|
-
|
|
165
|
-
|
|
167
|
+
if (!n) return null;
|
|
168
|
+
const first = points[0];
|
|
169
|
+
const last = points[n - 1];
|
|
170
|
+
if (tip && (first.time > tip.time || time > tip.time)) return null;
|
|
171
|
+
if (tip && time === tip.time) return tip.value;
|
|
172
|
+
// buildLinePoints can ease the final recorded vertex together with the tip.
|
|
173
|
+
const tailValue = smoothRecordedTail && tip ? tip.value : last.value;
|
|
174
|
+
if (time <= first.time) return n === 1 ? tailValue : first.value;
|
|
175
|
+
if (!tip && time >= last.time) return last.value;
|
|
166
176
|
|
|
167
|
-
//
|
|
177
|
+
// Find the recorded vertex at or before the marker. Resolve only its local
|
|
178
|
+
// neighbors, so clipping at the head never copies the series history.
|
|
168
179
|
let lo = 0;
|
|
169
|
-
let hi = n
|
|
180
|
+
let hi = n;
|
|
170
181
|
while (hi - lo > 1) {
|
|
171
182
|
const mid = (lo + hi) >> 1;
|
|
172
183
|
if (points[mid].time <= time) lo = mid;
|
|
173
184
|
else hi = mid;
|
|
174
185
|
}
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
const
|
|
178
|
-
const
|
|
179
|
-
const
|
|
186
|
+
const left = points[lo];
|
|
187
|
+
const candidate = points[lo + 1];
|
|
188
|
+
const right = candidate && (!tip || candidate.time <= tip.time) ? candidate : tip!;
|
|
189
|
+
const ti = left.time;
|
|
190
|
+
const vi = left === last ? tailValue : left.value;
|
|
191
|
+
const tj = right.time;
|
|
192
|
+
const vj = right === last ? tailValue : right.value;
|
|
180
193
|
const hSeg = tj - ti;
|
|
181
|
-
|
|
182
|
-
if (hSeg <= 0) return vi;
|
|
194
|
+
if (hSeg <= 0 || time === ti) return vi;
|
|
183
195
|
|
|
184
196
|
const deltaI = (vj - vi) / hSeg;
|
|
185
|
-
if (
|
|
197
|
+
if (linear) return vi + deltaI * (time - ti);
|
|
186
198
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
199
|
+
const before = points[lo - 1];
|
|
200
|
+
const next = points[lo + 2];
|
|
201
|
+
let after: LiveChartPoint | undefined = next;
|
|
202
|
+
if (tip && (!next || next.time > tip.time)) {
|
|
203
|
+
after = right === tip ? undefined : tip;
|
|
204
|
+
}
|
|
205
|
+
if (!before && !after) return vi + deltaI * (time - ti);
|
|
206
|
+
|
|
207
|
+
let mi = deltaI;
|
|
208
|
+
if (before) {
|
|
209
|
+
const dPrev = ti === before.time ? 0 : (vi - before.value) / (ti - before.time);
|
|
193
210
|
mi = dPrev * deltaI <= 0 ? 0 : (dPrev + deltaI) / 2;
|
|
194
211
|
}
|
|
195
|
-
let mj
|
|
196
|
-
if (
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const dNext = (points[i + 2].value - vj) / (points[i + 2].time - tj);
|
|
212
|
+
let mj = deltaI;
|
|
213
|
+
if (after) {
|
|
214
|
+
const afterValue = after === last ? tailValue : after.value;
|
|
215
|
+
const dNext = after.time === tj ? 0 : (afterValue - vj) / (after.time - tj);
|
|
200
216
|
mj = deltaI * dNext <= 0 ? 0 : (deltaI + dNext) / 2;
|
|
201
217
|
}
|
|
202
218
|
|
package/src/types.ts
CHANGED
|
@@ -1109,7 +1109,7 @@ export interface ScrubConfig {
|
|
|
1109
1109
|
* to the standard `"future"` behavior. When the finger is in a gap between
|
|
1110
1110
|
* candle buckets no candle is selected. Volume bars are unchanged. The
|
|
1111
1111
|
* vertical crosshair and scrub selection dot are hidden so the focused
|
|
1112
|
-
* candle is the sole position indicator.
|
|
1112
|
+
* candle is the sole position indicator unless `freeCrosshair` enables both guides.
|
|
1113
1113
|
*
|
|
1114
1114
|
* Default `"future"`.
|
|
1115
1115
|
*/
|
|
@@ -1244,6 +1244,30 @@ export interface ScrubConfig {
|
|
|
1244
1244
|
* candles keeps the raw finger X; no effect in line mode. Default `false`.
|
|
1245
1245
|
*/
|
|
1246
1246
|
snapToCandles?: boolean;
|
|
1247
|
+
/**
|
|
1248
|
+
* Free X/Y crosshair. While scrubbing, a horizontal line follows the
|
|
1249
|
+
* finger's Y with a price pill in the price-axis gutter (the price at that
|
|
1250
|
+
* Y, not the line value), and a time pill marks the crosshair X on the time
|
|
1251
|
+
* axis below any volume band. The price pill follows `yAxis.side`. Both guides
|
|
1252
|
+
* and pills follow the configured edge fade, including with `otherCandles`.
|
|
1253
|
+
* `onScrub` keeps the selected series value. The pills use `tooltipBackground`
|
|
1254
|
+
* and `tooltipColor`. The horizontal line uses the crosshair color, width
|
|
1255
|
+
* and dash. Pair with
|
|
1256
|
+
* `tooltip: false` and `selectionDot={false}` for a guide-only readout.
|
|
1257
|
+
* `true` formats the time pill with the chart's `formatTime`; an object can
|
|
1258
|
+
* pass its own worklet. Single-series `LiveChart` only. Default `false`.
|
|
1259
|
+
*/
|
|
1260
|
+
freeCrosshair?: boolean | FreeCrosshairConfig;
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
/** Options for {@link ScrubConfig.freeCrosshair}. */
|
|
1264
|
+
export interface FreeCrosshairConfig {
|
|
1265
|
+
/**
|
|
1266
|
+
* Worklet that formats the time pill (unix seconds in). Omit to use the
|
|
1267
|
+
* chart's `formatTime`, which is tuned for axis ticks and often too coarse
|
|
1268
|
+
* for a single point.
|
|
1269
|
+
*/
|
|
1270
|
+
formatTime?: (time: number) => string;
|
|
1247
1271
|
}
|
|
1248
1272
|
|
|
1249
1273
|
/**
|
|
@@ -1602,7 +1626,7 @@ export interface Marker {
|
|
|
1602
1626
|
time: number;
|
|
1603
1627
|
/** Glyph kind. */
|
|
1604
1628
|
kind: MarkerKind;
|
|
1605
|
-
/** Anchor y to this series' line at `time` (multi-series). */
|
|
1629
|
+
/** Anchor y to this series' line at `time` once its presentation head reaches that time (multi-series). */
|
|
1606
1630
|
seriesId?: string;
|
|
1607
1631
|
/**
|
|
1608
1632
|
* Absolute y value in data space. Takes precedence over `seriesId`. Omit it on
|
|
@@ -2350,7 +2374,7 @@ export interface VisibleRange {
|
|
|
2350
2374
|
startSec: number;
|
|
2351
2375
|
/** Right-edge time of the visible window (unix seconds). */
|
|
2352
2376
|
endSec: number;
|
|
2353
|
-
/** True
|
|
2377
|
+
/** True while following live, including after retained history evicts a parked edge. False while parked, paused or gliding back. */
|
|
2354
2378
|
following: boolean;
|
|
2355
2379
|
}
|
|
2356
2380
|
|
|
@@ -2811,7 +2835,9 @@ export interface LiveChartCoreProps {
|
|
|
2811
2835
|
/**
|
|
2812
2836
|
* Selection dot drawn at the scrub intersection while scrubbing. `true` =
|
|
2813
2837
|
* built-in dot, `false` = hidden, or pass `SelectionDotConfig` (`size`,
|
|
2814
|
-
* `color`, `ring`, or a custom `component`).
|
|
2838
|
+
* `color`, `ring`, or a custom `component`). With `scrub.freeCrosshair` it
|
|
2839
|
+
* marks the crosshair intersection under the finger instead of the series
|
|
2840
|
+
* value, in candle mode too.
|
|
2815
2841
|
*
|
|
2816
2842
|
* Defaults differ per chart: `LiveChart` shows it (`true`); `LiveChartSeries`
|
|
2817
2843
|
* hides it (`false`) — with multiple lines the dot can only track the leading
|
|
@@ -2827,6 +2853,8 @@ export interface LiveChartCoreProps {
|
|
|
2827
2853
|
/**
|
|
2828
2854
|
* Called as the visible time window changes (throttled to ~1 Hz), with the
|
|
2829
2855
|
* window's edges in unix seconds and whether the chart is at the live edge.
|
|
2856
|
+
* Rapid changes are coalesced and the final settled range is delivered.
|
|
2857
|
+
* A change that triggers onReachStart is reported immediately, before the paging callback.
|
|
2830
2858
|
* Useful for paging data sources alongside `timeScroll` / `zoom`.
|
|
2831
2859
|
*
|
|
2832
2860
|
* @experimental
|
|
@@ -2835,7 +2863,9 @@ export interface LiveChartCoreProps {
|
|
|
2835
2863
|
/**
|
|
2836
2864
|
* Called once when the visible window's left edge comes within one
|
|
2837
2865
|
* window-width of the earliest retained data — the cue to lazily load older
|
|
2838
|
-
* history.
|
|
2866
|
+
* history. The paging width excludes the future span added by `timeHorizon`.
|
|
2867
|
+
* Multi-series paging starts with the first measured viewport containing retained samples.
|
|
2868
|
+
* Re-arms after the edge moves back out.
|
|
2839
2869
|
*
|
|
2840
2870
|
* @experimental
|
|
2841
2871
|
*/
|
|
@@ -3160,11 +3190,13 @@ export interface LiveChartProps extends LiveChartCoreProps {
|
|
|
3160
3190
|
* The returned tree is mounted as an RN sibling of the `<Canvas>` (like
|
|
3161
3191
|
* `renderMarker` / `renderTooltip`), full-bleed with `pointerEvents="box-none"`
|
|
3162
3192
|
* so empty areas still scrub while an interactive leaf can receive touches.
|
|
3163
|
-
*
|
|
3193
|
+
* It stays mounted during loading/empty states, with opacity following the
|
|
3194
|
+
* chart's marker reveal. Also available on LiveChartSeries.
|
|
3164
3195
|
*/
|
|
3165
3196
|
renderOverlay?: (ctx: ChartOverlayContext) => ReactElement | null | undefined;
|
|
3166
3197
|
/**
|
|
3167
|
-
* JS-thread callback while scrubbing
|
|
3198
|
+
* JS-thread callback while scrubbing. Receives `null` when scrub ends.
|
|
3199
|
+
* With `scrub.freeCrosshair`, the point still carries the series value. With
|
|
3168
3200
|
* `scrub.markers` enabled, includes matching markers and also sends `null`
|
|
3169
3201
|
* when a valid point becomes unavailable (for example an unpriced gap).
|
|
3170
3202
|
*/
|
|
@@ -3274,6 +3306,14 @@ export interface LiveChartSeriesProps extends LiveChartCoreProps {
|
|
|
3274
3306
|
* restores following. A non-finite or future start falls back to timeWindow.
|
|
3275
3307
|
*/
|
|
3276
3308
|
historyStartTime?: number;
|
|
3309
|
+
/**
|
|
3310
|
+
* Reveal a future Unix-second timestamp while following live. Animate
|
|
3311
|
+
* `progress` from 0 (normal viewport) to 1 (right edge at `at`) and back.
|
|
3312
|
+
* The left edge follows its ordinary clock and the live tips stay at the
|
|
3313
|
+
* data head. Pan, pinch, pause and return-to-live take precedence.
|
|
3314
|
+
* To also expand Y on hold, use the same progress in `rangeAnimation.transform`.
|
|
3315
|
+
*/
|
|
3316
|
+
timeHorizon?: { at: number; progress: SharedValue<number> };
|
|
3277
3317
|
/**
|
|
3278
3318
|
* Shared-range easing plus an optional reversible UI-thread presentation
|
|
3279
3319
|
* transform. See {@link SeriesRangeAnimationConfig}; recorded values remain unchanged.
|
|
@@ -3287,6 +3327,8 @@ export interface LiveChartSeriesProps extends LiveChartCoreProps {
|
|
|
3287
3327
|
* and mapping worklets to position React Native UI against this chart's resolved
|
|
3288
3328
|
* plot bounds (including any axis or explicit inset). The tree mounts full-bleed
|
|
3289
3329
|
* with `pointerEvents="box-none"`; return `null`/`undefined` for no overlay.
|
|
3330
|
+
* It stays mounted during loading/empty states, with opacity following the
|
|
3331
|
+
* chart's marker reveal.
|
|
3290
3332
|
*/
|
|
3291
3333
|
renderOverlay?: (ctx: ChartOverlayContext) => ReactElement | null | undefined;
|
|
3292
3334
|
/**
|