react-native-livechart 4.25.0 → 4.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CustomReferenceLineOverlay.d.ts +8 -1
- package/dist/components/CustomReferenceLineOverlay.d.ts.map +1 -1
- package/dist/components/CustomTooltipOverlay.d.ts +3 -2
- package/dist/components/CustomTooltipOverlay.d.ts.map +1 -1
- package/dist/components/LiveChart.d.ts +1 -1
- package/dist/components/LiveChart.d.ts.map +1 -1
- package/dist/components/LiveChartSeries.d.ts.map +1 -1
- package/dist/components/ReferenceLineOverlay.d.ts +4 -0
- package/dist/components/ReferenceLineOverlay.d.ts.map +1 -1
- package/dist/components/ReferenceValueBadge.d.ts +15 -0
- package/dist/components/ReferenceValueBadge.d.ts.map +1 -0
- package/dist/components/XAxisOverlay.d.ts +17 -0
- package/dist/components/XAxisOverlay.d.ts.map +1 -1
- package/dist/core/liveChartEngineTick.d.ts +6 -1
- package/dist/core/liveChartEngineTick.d.ts.map +1 -1
- package/dist/core/liveChartSeriesEngineTick.d.ts +4 -1
- package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
- package/dist/core/resolveConfig.d.ts +28 -1
- package/dist/core/resolveConfig.d.ts.map +1 -1
- package/dist/core/useLiveChartEngine.d.ts +10 -1
- package/dist/core/useLiveChartEngine.d.ts.map +1 -1
- package/dist/core/useLiveChartSeriesEngine.d.ts +5 -1
- package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
- package/dist/draw/grid.d.ts +2 -2
- package/dist/draw/line.d.ts +15 -1
- package/dist/draw/line.d.ts.map +1 -1
- package/dist/hooks/crosshairShared.d.ts +24 -1
- package/dist/hooks/crosshairShared.d.ts.map +1 -1
- package/dist/hooks/referenceBadgeFont.d.ts +5 -0
- package/dist/hooks/referenceBadgeFont.d.ts.map +1 -0
- package/dist/hooks/resolveChartLayout.d.ts +8 -0
- package/dist/hooks/resolveChartLayout.d.ts.map +1 -1
- package/dist/hooks/useBadge.d.ts +16 -1
- package/dist/hooks/useBadge.d.ts.map +1 -1
- package/dist/hooks/useChartSkiaFont.d.ts +1 -0
- package/dist/hooks/useChartSkiaFont.d.ts.map +1 -1
- package/dist/hooks/useCrosshair.d.ts +7 -2
- package/dist/hooks/useCrosshair.d.ts.map +1 -1
- package/dist/hooks/useCrosshairSeries.d.ts +4 -1
- package/dist/hooks/useCrosshairSeries.d.ts.map +1 -1
- package/dist/hooks/useLatestCallback.d.ts +6 -0
- package/dist/hooks/useLatestCallback.d.ts.map +1 -0
- package/dist/hooks/useMarkers.d.ts.map +1 -1
- package/dist/hooks/usePanScroll.d.ts +3 -1
- package/dist/hooks/usePanScroll.d.ts.map +1 -1
- package/dist/hooks/usePinchZoom.d.ts.map +1 -1
- package/dist/hooks/useReferenceDrag.d.ts +23 -7
- package/dist/hooks/useReferenceDrag.d.ts.map +1 -1
- package/dist/hooks/useReferenceLine.d.ts +24 -12
- package/dist/hooks/useReferenceLine.d.ts.map +1 -1
- package/dist/hooks/useReferenceLineGrouping.d.ts +19 -0
- package/dist/hooks/useReferenceLineGrouping.d.ts.map +1 -0
- package/dist/hooks/useReferenceLinePress.d.ts +4 -2
- package/dist/hooks/useReferenceLinePress.d.ts.map +1 -1
- package/dist/hooks/useReferenceTagStack.d.ts +31 -0
- package/dist/hooks/useReferenceTagStack.d.ts.map +1 -0
- package/dist/hooks/useScrubMarkers.d.ts +12 -0
- package/dist/hooks/useScrubMarkers.d.ts.map +1 -0
- package/dist/hooks/useXAxis.d.ts +1 -1
- package/dist/hooks/useXAxis.d.ts.map +1 -1
- package/dist/hooks/useYAxisScaleGesture.d.ts +34 -0
- package/dist/hooks/useYAxisScaleGesture.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/math/axisBadgeLayout.d.ts +16 -0
- package/dist/math/axisBadgeLayout.d.ts.map +1 -0
- package/dist/math/markers.d.ts +3 -0
- package/dist/math/markers.d.ts.map +1 -1
- package/dist/math/range.d.ts +1 -1
- package/dist/math/range.d.ts.map +1 -1
- package/dist/math/rangeAnimation.d.ts +4 -0
- package/dist/math/rangeAnimation.d.ts.map +1 -0
- package/dist/math/referenceDrag.d.ts +17 -5
- package/dist/math/referenceDrag.d.ts.map +1 -1
- package/dist/math/referenceGroup.d.ts +2 -2
- package/dist/math/referenceTagStack.d.ts +36 -0
- package/dist/math/referenceTagStack.d.ts.map +1 -0
- package/dist/math/scrubMarkers.d.ts +12 -0
- package/dist/math/scrubMarkers.d.ts.map +1 -0
- package/dist/types.d.ts +240 -30
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/CustomReferenceLineOverlay.tsx +50 -8
- package/src/components/CustomTooltipOverlay.tsx +5 -1
- package/src/components/LiveChart.tsx +563 -200
- package/src/components/LiveChartSeries.tsx +117 -13
- package/src/components/ReferenceLineOverlay.tsx +62 -26
- package/src/components/ReferenceValueBadge.tsx +102 -0
- package/src/components/XAxisOverlay.tsx +104 -1
- package/src/core/liveChartEngineTick.ts +66 -10
- package/src/core/liveChartSeriesEngineTick.ts +55 -5
- package/src/core/resolveConfig.ts +95 -2
- package/src/core/useLiveChartEngine.ts +53 -11
- package/src/core/useLiveChartSeriesEngine.ts +11 -1
- package/src/draw/grid.ts +2 -2
- package/src/draw/line.ts +23 -1
- package/src/hooks/crosshairShared.ts +85 -1
- package/src/hooks/referenceBadgeFont.ts +35 -0
- package/src/hooks/resolveChartLayout.ts +17 -0
- package/src/hooks/useBadge.ts +44 -5
- package/src/hooks/useChartSkiaFont.ts +1 -1
- package/src/hooks/useCrosshair.ts +446 -300
- package/src/hooks/useCrosshairSeries.ts +29 -10
- package/src/hooks/useLatestCallback.ts +15 -0
- package/src/hooks/useMarkers.ts +51 -39
- package/src/hooks/usePanScroll.ts +155 -127
- package/src/hooks/usePinchZoom.ts +84 -63
- package/src/hooks/useReferenceDrag.ts +395 -146
- package/src/hooks/useReferenceLine.ts +453 -277
- package/src/hooks/useReferenceLineGrouping.ts +72 -0
- package/src/hooks/useReferenceLinePress.ts +121 -53
- package/src/hooks/useReferenceTagStack.ts +81 -0
- package/src/hooks/useScrubMarkers.ts +79 -0
- package/src/hooks/useXAxis.ts +11 -2
- package/src/hooks/useYAxisScaleGesture.ts +263 -0
- package/src/index.ts +11 -0
- package/src/math/axisBadgeLayout.ts +37 -0
- package/src/math/markers.ts +28 -3
- package/src/math/range.ts +35 -0
- package/src/math/rangeAnimation.ts +28 -0
- package/src/math/referenceDrag.ts +21 -4
- package/src/math/referenceGroup.ts +2 -2
- package/src/math/referenceTagStack.ts +112 -0
- package/src/math/scrubMarkers.ts +55 -0
- package/src/types.ts +246 -30
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DashPathEffect,
|
|
3
|
+
Group,
|
|
4
|
+
Path,
|
|
5
|
+
type SkFont,
|
|
6
|
+
type SkPath,
|
|
7
|
+
} from "@shopify/react-native-skia";
|
|
2
8
|
import { useDerivedValue, type SharedValue } from "react-native-reanimated";
|
|
3
9
|
import { X_AXIS_LABEL_OFFSET_Y } from "../constants";
|
|
10
|
+
import type { ResolvedGridStyleConfig } from "../core/resolveConfig";
|
|
4
11
|
import type { ChartEngineLayout } from "../core/useLiveChartEngine";
|
|
5
12
|
import type { ChartPadding } from "../draw/line";
|
|
6
13
|
import type { XAxisEntry } from "../hooks/useXAxis";
|
|
@@ -95,3 +102,99 @@ export function XAxisOverlay({
|
|
|
95
102
|
</Group>
|
|
96
103
|
);
|
|
97
104
|
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Vertical grid lines at the time-axis ticks (`xAxis.gridLines`). The chart
|
|
108
|
+
* draws this behind the series, in the horizontal grid's layer; the axis line,
|
|
109
|
+
* ticks, and labels stay in {@link XAxisOverlay} above it. One pooled line per
|
|
110
|
+
* label slot, so each line fades with its label instead of popping in at the
|
|
111
|
+
* plot edges.
|
|
112
|
+
*/
|
|
113
|
+
export function XAxisGridLines({
|
|
114
|
+
entries,
|
|
115
|
+
engine,
|
|
116
|
+
padding,
|
|
117
|
+
palette,
|
|
118
|
+
gridStyle,
|
|
119
|
+
volumeBandHeight = 0,
|
|
120
|
+
}: {
|
|
121
|
+
entries: SharedValue<XAxisEntry[]>;
|
|
122
|
+
engine: ChartEngineLayout;
|
|
123
|
+
padding: ChartPadding;
|
|
124
|
+
palette: LiveChartPalette;
|
|
125
|
+
gridStyle: ResolvedGridStyleConfig;
|
|
126
|
+
/** Reserved volume-band height (px); the lines run through it to the axis line. */
|
|
127
|
+
volumeBandHeight?: number;
|
|
128
|
+
}) {
|
|
129
|
+
const segmentBuilder = usePathBuilder();
|
|
130
|
+
// Capturing the whole engine subscribes this immutable segment to its live
|
|
131
|
+
// clock/range too. Only layout changes should allocate a new segment path.
|
|
132
|
+
const { canvasWidth, canvasHeight } = engine;
|
|
133
|
+
const { left, right, top, bottom } = padding;
|
|
134
|
+
|
|
135
|
+
// One vertical segment, from the plot top down to the axis line, shared by
|
|
136
|
+
// the whole pool: each line only translates it to its tick.
|
|
137
|
+
const segment = useDerivedValue(() => {
|
|
138
|
+
"worklet";
|
|
139
|
+
const b = segmentBuilder.value;
|
|
140
|
+
b.moveTo(0, top);
|
|
141
|
+
b.lineTo(
|
|
142
|
+
0,
|
|
143
|
+
canvasHeight.get() - bottom + volumeBandHeight,
|
|
144
|
+
);
|
|
145
|
+
return b.detach();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Fading ticks can remain just outside the plot. Keep their strokes out of
|
|
149
|
+
// the axis gutters while retaining the full candle volume-band height.
|
|
150
|
+
const clip = useDerivedValue(() => ({
|
|
151
|
+
x: left,
|
|
152
|
+
y: top,
|
|
153
|
+
width: Math.max(0, canvasWidth.get() - left - right),
|
|
154
|
+
height: Math.max(0, canvasHeight.get() - bottom + volumeBandHeight - top),
|
|
155
|
+
}));
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<Group opacity={gridStyle.opacity} clip={clip}>
|
|
159
|
+
{Array.from({ length: MAX_X_LABELS }, (_, i) => (
|
|
160
|
+
<XAxisGridLine
|
|
161
|
+
key={i}
|
|
162
|
+
entries={entries}
|
|
163
|
+
index={i}
|
|
164
|
+
segment={segment}
|
|
165
|
+
color={gridStyle.color ?? palette.gridLine}
|
|
166
|
+
strokeWidth={gridStyle.strokeWidth}
|
|
167
|
+
intervals={gridStyle.intervals}
|
|
168
|
+
/>
|
|
169
|
+
))}
|
|
170
|
+
</Group>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function XAxisGridLine({
|
|
175
|
+
entries,
|
|
176
|
+
index,
|
|
177
|
+
segment,
|
|
178
|
+
color,
|
|
179
|
+
strokeWidth,
|
|
180
|
+
intervals,
|
|
181
|
+
}: {
|
|
182
|
+
entries: SharedValue<XAxisEntry[]>;
|
|
183
|
+
index: number;
|
|
184
|
+
segment: SharedValue<SkPath>;
|
|
185
|
+
color: string;
|
|
186
|
+
strokeWidth: number;
|
|
187
|
+
intervals: number[];
|
|
188
|
+
}) {
|
|
189
|
+
const transform = useDerivedValue(() => [
|
|
190
|
+
{ translateX: entries.get()[index]?.x ?? -200 },
|
|
191
|
+
]);
|
|
192
|
+
const opacity = useDerivedValue(() => entries.get()[index]?.alpha ?? 0);
|
|
193
|
+
return (
|
|
194
|
+
<Group transform={transform} opacity={opacity}>
|
|
195
|
+
<Path path={segment} style="stroke" strokeWidth={strokeWidth} color={color}>
|
|
196
|
+
{intervals.length > 0 && <DashPathEffect intervals={intervals} />}
|
|
197
|
+
</Path>
|
|
198
|
+
</Group>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
CandleGap,
|
|
3
|
+
CandlePoint,
|
|
4
|
+
LiveChartPoint,
|
|
5
|
+
RangeAnimationConfig,
|
|
6
|
+
} from "../types";
|
|
2
7
|
|
|
3
8
|
import {
|
|
4
9
|
historyRange,
|
|
@@ -8,6 +13,7 @@ import {
|
|
|
8
13
|
|
|
9
14
|
import { MOTION_METRICS_DEFAULTS } from "../constants";
|
|
10
15
|
import { lerp } from "../math/lerp";
|
|
16
|
+
import { rangeAnimationSpeed } from "../math/rangeAnimation";
|
|
11
17
|
import { thresholdRangeMinMax } from "../math/threshold";
|
|
12
18
|
import { previousCandleCloseAtTime } from "../math/candleGaps";
|
|
13
19
|
|
|
@@ -59,6 +65,7 @@ export interface EngineTickInput {
|
|
|
59
65
|
canvasHeight: number;
|
|
60
66
|
timeWindow: number;
|
|
61
67
|
smoothing: number;
|
|
68
|
+
rangeAnimation?: RangeAnimationConfig;
|
|
62
69
|
exaggerate: boolean;
|
|
63
70
|
/** Extra catch-up speed added to `smoothing` when the live value lags. Default `0.12`. */
|
|
64
71
|
adaptiveSpeedBoost?: number;
|
|
@@ -81,6 +88,8 @@ export interface EngineTickInput {
|
|
|
81
88
|
nonNegative?: boolean;
|
|
82
89
|
/** Hard cap for the computed upper bound. */
|
|
83
90
|
maxValue?: number;
|
|
91
|
+
/** Smallest fitted span, in data units; widened around the data. */
|
|
92
|
+
minRange?: number;
|
|
84
93
|
/** Positive, finite Y-range multiplier around the fitted midpoint (1 = auto-fit). */
|
|
85
94
|
yRangeScale?: number;
|
|
86
95
|
targetValue: number;
|
|
@@ -141,6 +150,8 @@ export interface EngineTickInput {
|
|
|
141
150
|
* overrides its width. `displayWindow` eases toward this when set.
|
|
142
151
|
*/
|
|
143
152
|
viewWindow?: number | null;
|
|
153
|
+
/** Ease a non-null viewWindow override. False adopts a leader's drawn width exactly. Default true. */
|
|
154
|
+
viewWindowSmoothing?: boolean;
|
|
144
155
|
/** Chart mode — `"candle"` uses OHLC bars for Y range instead of line points. */
|
|
145
156
|
mode?: "line" | "candle";
|
|
146
157
|
/** Committed OHLC bars (sorted by time). Used when mode is `"candle"`. */
|
|
@@ -200,6 +211,12 @@ export function tickLiveChartEngineFrame(
|
|
|
200
211
|
"worklet";
|
|
201
212
|
const baseNow = input.nowOverride ?? input.nowSeconds ?? Date.now() / 1000;
|
|
202
213
|
const liveEdge = baseNow + (input.windowBuffer ?? 0) * input.timeWindow;
|
|
214
|
+
const targetWindow = input.viewWindow ?? input.timeWindow;
|
|
215
|
+
// Keep clock rounding below half a pixel of the displayed window as it
|
|
216
|
+
// changes. Using only the target window during expansion can leave "now"
|
|
217
|
+
// several visible pixels past the edge and hide a live marker.
|
|
218
|
+
const timestampSecondsPerPixel =
|
|
219
|
+
Math.min(state.displayWindow, targetWindow) / input.canvasWidth;
|
|
203
220
|
const viewEnd = input.viewEnd;
|
|
204
221
|
// First time of the visible series' data — the floor a frozen edge must stay
|
|
205
222
|
// at or above. `-Infinity` when there's no data to bound against, so the freeze
|
|
@@ -231,7 +248,7 @@ export function tickLiveChartEngineFrame(
|
|
|
231
248
|
? advanceTimestampByPixel(
|
|
232
249
|
state.liveEdge,
|
|
233
250
|
liveEdge,
|
|
234
|
-
|
|
251
|
+
timestampSecondsPerPixel,
|
|
235
252
|
)
|
|
236
253
|
: liveEdge;
|
|
237
254
|
if (scrolledBack) {
|
|
@@ -253,7 +270,7 @@ export function tickLiveChartEngineFrame(
|
|
|
253
270
|
state.timestamp = advanceTimestampByPixel(
|
|
254
271
|
state.timestamp,
|
|
255
272
|
liveEdge,
|
|
256
|
-
|
|
273
|
+
timestampSecondsPerPixel,
|
|
257
274
|
);
|
|
258
275
|
} else {
|
|
259
276
|
state.timestamp = liveEdge;
|
|
@@ -297,8 +314,8 @@ export function tickLiveChartEngineFrame(
|
|
|
297
314
|
|
|
298
315
|
// Pinch-zoom: ease toward the zoom override when set, else the configured
|
|
299
316
|
// window. Mirrors the viewEnd freeze above (width vs. right edge).
|
|
300
|
-
|
|
301
|
-
|
|
317
|
+
state.displayWindow = snap ||
|
|
318
|
+
(input.viewWindow != null && input.viewWindowSmoothing === false)
|
|
302
319
|
? targetWindow
|
|
303
320
|
: lerpAndSettle(
|
|
304
321
|
state.displayWindow,
|
|
@@ -438,6 +455,41 @@ export function tickLiveChartEngineFrame(
|
|
|
438
455
|
tMax += margin;
|
|
439
456
|
}
|
|
440
457
|
|
|
458
|
+
const floorRange = input.minRange;
|
|
459
|
+
// Compare the bounded fit: a clamp can shrink an otherwise wider range.
|
|
460
|
+
// Slide a widened fit off either bound; both hard bounds win if the floor
|
|
461
|
+
// cannot fit between them. Resolve this before the optional manual zoom.
|
|
462
|
+
if (floorRange !== undefined && floorRange > 0 && Number.isFinite(floorRange)) {
|
|
463
|
+
const boundedMin = input.nonNegative && tMin < 0 ? 0 : tMin;
|
|
464
|
+
const boundedMax =
|
|
465
|
+
input.maxValue !== undefined && tMax > input.maxValue ? input.maxValue : tMax;
|
|
466
|
+
if (floorRange > boundedMax - boundedMin) {
|
|
467
|
+
// Halve before adding so large finite prices cannot overflow the midpoint.
|
|
468
|
+
const mid = tMin / 2 + tMax / 2;
|
|
469
|
+
let nextMin = mid - floorRange / 2;
|
|
470
|
+
let nextMax = mid + floorRange / 2;
|
|
471
|
+
if (input.nonNegative && nextMin < 0) {
|
|
472
|
+
nextMax -= nextMin;
|
|
473
|
+
nextMin = 0;
|
|
474
|
+
}
|
|
475
|
+
if (input.maxValue !== undefined && nextMax > input.maxValue) {
|
|
476
|
+
nextMin -= nextMax - input.maxValue;
|
|
477
|
+
nextMax = input.maxValue;
|
|
478
|
+
}
|
|
479
|
+
if (input.nonNegative && nextMin < 0) nextMin = 0;
|
|
480
|
+
// Ignore a floor that would overflow or round the bounds onto each other.
|
|
481
|
+
if (
|
|
482
|
+
Number.isFinite(nextMin) &&
|
|
483
|
+
Number.isFinite(nextMax) &&
|
|
484
|
+
nextMin < nextMax &&
|
|
485
|
+
Number.isFinite(nextMax - nextMin)
|
|
486
|
+
) {
|
|
487
|
+
tMin = nextMin;
|
|
488
|
+
tMax = nextMax;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
441
493
|
// Treat malformed gesture output as auto-fit. A zero/negative multiplier
|
|
442
494
|
// collapses or inverts the range; a non-finite/overflowing one poisons every
|
|
443
495
|
// downstream price-to-Y projection. Keep the guard here on the UI thread so
|
|
@@ -478,26 +530,30 @@ export function tickLiveChartEngineFrame(
|
|
|
478
530
|
const maxV = input.maxValue;
|
|
479
531
|
if (maxV !== undefined && tMax > maxV) tMax = maxV;
|
|
480
532
|
|
|
481
|
-
const
|
|
482
|
-
|
|
533
|
+
const disjoint = tMin >= state.displayMax || tMax <= state.displayMin;
|
|
534
|
+
// A subpixel settle must not jump across the other bound of a disjoint fit.
|
|
535
|
+
const rangeUnitsPerPixel = disjoint && input.rangeAnimation?.animateExpansion
|
|
536
|
+
? 0
|
|
537
|
+
: (tMax - tMin) / input.canvasHeight;
|
|
538
|
+
if (snap || yScaleDragging) {
|
|
483
539
|
state.displayMin = tMin;
|
|
484
540
|
} else {
|
|
485
541
|
state.displayMin = lerpAndSettle(
|
|
486
542
|
state.displayMin,
|
|
487
543
|
tMin,
|
|
488
|
-
speed,
|
|
544
|
+
rangeAnimationSpeed(speed, input.rangeAnimation, tMin < state.displayMin, disjoint),
|
|
489
545
|
input.dt,
|
|
490
546
|
rangeUnitsPerPixel,
|
|
491
547
|
);
|
|
492
548
|
}
|
|
493
549
|
|
|
494
|
-
if (snap || yScaleDragging
|
|
550
|
+
if (snap || yScaleDragging) {
|
|
495
551
|
state.displayMax = tMax;
|
|
496
552
|
} else {
|
|
497
553
|
state.displayMax = lerpAndSettle(
|
|
498
554
|
state.displayMax,
|
|
499
555
|
tMax,
|
|
500
|
-
speed,
|
|
556
|
+
rangeAnimationSpeed(speed, input.rangeAnimation, tMax > state.displayMax, disjoint),
|
|
501
557
|
input.dt,
|
|
502
558
|
rangeUnitsPerPixel,
|
|
503
559
|
);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MOTION_METRICS_DEFAULTS } from "../constants";
|
|
2
2
|
import { lerp } from "../math/lerp";
|
|
3
|
-
import
|
|
3
|
+
import { rangeAnimationSpeed } from "../math/rangeAnimation";
|
|
4
|
+
import type { RangeAnimationConfig, SeriesConfig } from "../types";
|
|
4
5
|
|
|
5
6
|
export interface MultiEngineTickMutable {
|
|
6
7
|
displayMin: number;
|
|
@@ -35,6 +36,7 @@ export interface MultiEngineTickInput {
|
|
|
35
36
|
canvasHeight: number;
|
|
36
37
|
timeWindow: number;
|
|
37
38
|
smoothing: number;
|
|
39
|
+
rangeAnimation?: RangeAnimationConfig;
|
|
38
40
|
exaggerate: boolean;
|
|
39
41
|
/** Extra catch-up speed added to `smoothing` when a series tip lags. Default `0.12`. */
|
|
40
42
|
adaptiveSpeedBoost?: number;
|
|
@@ -45,6 +47,8 @@ export interface MultiEngineTickInput {
|
|
|
45
47
|
nonNegative?: boolean;
|
|
46
48
|
/** Hard cap for the computed upper bound. */
|
|
47
49
|
maxValue?: number;
|
|
50
|
+
/** Smallest fitted span, in data units; widened around the data. */
|
|
51
|
+
minRange?: number;
|
|
48
52
|
/** Positive, finite Y-range multiplier around the fitted midpoint (1 = auto-fit). */
|
|
49
53
|
yRangeScale?: number;
|
|
50
54
|
series: SeriesConfig[];
|
|
@@ -296,6 +300,41 @@ export function tickLiveChartSeriesEngineFrame(
|
|
|
296
300
|
tMax += margin;
|
|
297
301
|
}
|
|
298
302
|
|
|
303
|
+
const floorRange = input.minRange;
|
|
304
|
+
// Compare the bounded fit: a clamp can shrink an otherwise wider range.
|
|
305
|
+
// Slide a widened fit off either bound; both hard bounds win if the floor
|
|
306
|
+
// cannot fit between them. Resolve this before the optional manual zoom.
|
|
307
|
+
if (floorRange !== undefined && floorRange > 0 && Number.isFinite(floorRange)) {
|
|
308
|
+
const boundedMin = input.nonNegative && tMin < 0 ? 0 : tMin;
|
|
309
|
+
const boundedMax =
|
|
310
|
+
input.maxValue !== undefined && tMax > input.maxValue ? input.maxValue : tMax;
|
|
311
|
+
if (floorRange > boundedMax - boundedMin) {
|
|
312
|
+
// Halve before adding so large finite prices cannot overflow the midpoint.
|
|
313
|
+
const mid = tMin / 2 + tMax / 2;
|
|
314
|
+
let nextMin = mid - floorRange / 2;
|
|
315
|
+
let nextMax = mid + floorRange / 2;
|
|
316
|
+
if (input.nonNegative && nextMin < 0) {
|
|
317
|
+
nextMax -= nextMin;
|
|
318
|
+
nextMin = 0;
|
|
319
|
+
}
|
|
320
|
+
if (input.maxValue !== undefined && nextMax > input.maxValue) {
|
|
321
|
+
nextMin -= nextMax - input.maxValue;
|
|
322
|
+
nextMax = input.maxValue;
|
|
323
|
+
}
|
|
324
|
+
if (input.nonNegative && nextMin < 0) nextMin = 0;
|
|
325
|
+
// Ignore a floor that would overflow or round the bounds onto each other.
|
|
326
|
+
if (
|
|
327
|
+
Number.isFinite(nextMin) &&
|
|
328
|
+
Number.isFinite(nextMax) &&
|
|
329
|
+
nextMin < nextMax &&
|
|
330
|
+
Number.isFinite(nextMax - nextMin)
|
|
331
|
+
) {
|
|
332
|
+
tMin = nextMin;
|
|
333
|
+
tMax = nextMax;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
299
338
|
// Keep this behavior in parity with the single-series engine: malformed
|
|
300
339
|
// gesture output must never collapse, invert, or poison the shared axis.
|
|
301
340
|
const requestedYScale = input.yRangeScale ?? 1;
|
|
@@ -332,16 +371,27 @@ export function tickLiveChartSeriesEngineFrame(
|
|
|
332
371
|
const maxV = input.maxValue;
|
|
333
372
|
if (maxV !== undefined && tMax > maxV) tMax = maxV;
|
|
334
373
|
|
|
335
|
-
|
|
374
|
+
const disjoint = tMin >= state.displayMax || tMax <= state.displayMin;
|
|
375
|
+
if (snap || yScaleDragging) {
|
|
336
376
|
state.displayMin = tMin;
|
|
337
377
|
} else {
|
|
338
|
-
state.displayMin = lerp(
|
|
378
|
+
state.displayMin = lerp(
|
|
379
|
+
state.displayMin,
|
|
380
|
+
tMin,
|
|
381
|
+
rangeAnimationSpeed(speed, input.rangeAnimation, tMin < state.displayMin, disjoint),
|
|
382
|
+
input.dt,
|
|
383
|
+
);
|
|
339
384
|
}
|
|
340
385
|
|
|
341
|
-
if (snap || yScaleDragging
|
|
386
|
+
if (snap || yScaleDragging) {
|
|
342
387
|
state.displayMax = tMax;
|
|
343
388
|
} else {
|
|
344
|
-
state.displayMax = lerp(
|
|
389
|
+
state.displayMax = lerp(
|
|
390
|
+
state.displayMax,
|
|
391
|
+
tMax,
|
|
392
|
+
rangeAnimationSpeed(speed, input.rangeAnimation, tMax > state.displayMax, disjoint),
|
|
393
|
+
input.dt,
|
|
394
|
+
);
|
|
345
395
|
}
|
|
346
396
|
}
|
|
347
397
|
}
|
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
CandleGapKind,
|
|
10
10
|
CandleGapLabelStyle,
|
|
11
11
|
CandleGapsConfig,
|
|
12
|
+
ChartViewportControl,
|
|
12
13
|
DegenOptions,
|
|
13
14
|
FontConfig,
|
|
14
15
|
FontWeight,
|
|
@@ -42,9 +43,11 @@ import type {
|
|
|
42
43
|
TradeEvent,
|
|
43
44
|
TransitionConfig,
|
|
44
45
|
ValueLineConfig,
|
|
46
|
+
ViewportConfig,
|
|
45
47
|
VolumeConfig,
|
|
46
48
|
XAxisConfig,
|
|
47
49
|
YAxisConfig,
|
|
50
|
+
YAxisScaleGestureConfig,
|
|
48
51
|
ZoomConfig,
|
|
49
52
|
} from "../types";
|
|
50
53
|
import type { ComponentType, ReactElement } from "react";
|
|
@@ -76,6 +79,8 @@ export interface ResolvedBadgeConfig {
|
|
|
76
79
|
variant: BadgeVariant;
|
|
77
80
|
tail: boolean;
|
|
78
81
|
position: "right" | "left";
|
|
82
|
+
/** "yAxisColumn" → value in the right-anchored Y-axis label column. */
|
|
83
|
+
textAlign: "center" | "yAxisColumn";
|
|
79
84
|
background: string | undefined;
|
|
80
85
|
/** undefined → capsule (pillHeight / 2) at render time */
|
|
81
86
|
radius: number | undefined;
|
|
@@ -93,7 +98,10 @@ export interface ResolvedBadgeConfig {
|
|
|
93
98
|
followViewEdge: boolean;
|
|
94
99
|
}
|
|
95
100
|
|
|
101
|
+
export type ResolvedYAxisScaleGestureConfig = Required<YAxisScaleGestureConfig>;
|
|
102
|
+
|
|
96
103
|
export interface ResolvedYAxisConfig {
|
|
104
|
+
scaleGesture: ResolvedYAxisScaleGestureConfig | null;
|
|
97
105
|
side: "left" | "right";
|
|
98
106
|
minGap: number;
|
|
99
107
|
/** Multiplier used to choose and align representable dynamic nice intervals. */
|
|
@@ -188,9 +196,12 @@ export interface ResolvedAxisLabelConfig {
|
|
|
188
196
|
|
|
189
197
|
export interface ResolvedXAxisConfig {
|
|
190
198
|
minGap: number;
|
|
199
|
+
/** Vertical grid-line overrides over `gridStyle`; null → no vertical grid. */
|
|
200
|
+
gridLines: GridStyleConfig | null;
|
|
191
201
|
}
|
|
192
202
|
|
|
193
203
|
export interface ResolvedScrubConfig {
|
|
204
|
+
markers: { radius: number } | null;
|
|
194
205
|
tooltip: boolean;
|
|
195
206
|
/** Opt-in per-series pill tooltip for LiveChartSeries; null keeps guide-only behavior. */
|
|
196
207
|
seriesTooltip: ResolvedPerSeriesTooltipConfig | null;
|
|
@@ -508,6 +519,7 @@ const BADGE_DEFAULTS: ResolvedBadgeConfig = {
|
|
|
508
519
|
variant: "default",
|
|
509
520
|
tail: true,
|
|
510
521
|
position: "right",
|
|
522
|
+
textAlign: "center",
|
|
511
523
|
background: undefined,
|
|
512
524
|
radius: undefined,
|
|
513
525
|
borderColor: undefined,
|
|
@@ -531,7 +543,7 @@ export function resolveBadge(
|
|
|
531
543
|
return resolveToggle(prop, BADGE_DEFAULTS, false);
|
|
532
544
|
}
|
|
533
545
|
|
|
534
|
-
const Y_AXIS_DEFAULTS: ResolvedYAxisConfig = {
|
|
546
|
+
const Y_AXIS_DEFAULTS: Omit<ResolvedYAxisConfig, "scaleGesture"> = {
|
|
535
547
|
side: "right",
|
|
536
548
|
minGap: 36,
|
|
537
549
|
intervalScale: 1,
|
|
@@ -541,6 +553,23 @@ const Y_AXIS_DEFAULTS: ResolvedYAxisConfig = {
|
|
|
541
553
|
float: false,
|
|
542
554
|
};
|
|
543
555
|
|
|
556
|
+
/** Normalize the opt-in axis gesture; bounds only constrain gesture writes. */
|
|
557
|
+
export function resolveYAxisScaleGesture(
|
|
558
|
+
prop: boolean | YAxisScaleGestureConfig | undefined,
|
|
559
|
+
): ResolvedYAxisScaleGestureConfig | null {
|
|
560
|
+
if (!prop) return null;
|
|
561
|
+
const config = prop === true ? {} : prop;
|
|
562
|
+
const positive = (value: number | undefined, fallback: number) =>
|
|
563
|
+
value !== undefined && Number.isFinite(value) && value > 0 ? value : fallback;
|
|
564
|
+
const minScale = positive(config.minScale, 0.25);
|
|
565
|
+
return {
|
|
566
|
+
minScale,
|
|
567
|
+
maxScale: Math.max(minScale, positive(config.maxScale, 10)),
|
|
568
|
+
dragDistance: positive(config.dragDistance, 160),
|
|
569
|
+
doubleTapReset: config.doubleTapReset ?? true,
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
|
|
544
573
|
/**
|
|
545
574
|
* Resolves `yAxis` prop to a fully-typed config or null (disabled).
|
|
546
575
|
* `true` → defaults, object → merged with defaults, falsy → null.
|
|
@@ -554,6 +583,9 @@ export function resolveYAxis(
|
|
|
554
583
|
if (resolved === null) return null;
|
|
555
584
|
return {
|
|
556
585
|
...resolved,
|
|
586
|
+
scaleGesture: resolveYAxisScaleGesture(
|
|
587
|
+
typeof prop === "object" ? prop.scaleGesture : undefined,
|
|
588
|
+
),
|
|
557
589
|
count: Math.max(0, Math.floor(resolved.count)),
|
|
558
590
|
intervalScale:
|
|
559
591
|
Number.isFinite(resolved.intervalScale) && resolved.intervalScale > 0
|
|
@@ -726,6 +758,31 @@ export function resolveCandleGaps(
|
|
|
726
758
|
};
|
|
727
759
|
}
|
|
728
760
|
|
|
761
|
+
export interface ResolvedViewportConfig extends ChartViewportControl {
|
|
762
|
+
/** Fully resolved render-time option; shared values are kept by reference. */
|
|
763
|
+
windowSmoothing: boolean;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
const VIEWPORT_DEFAULTS: Pick<ResolvedViewportConfig, "windowSmoothing"> = {
|
|
767
|
+
windowSmoothing: true,
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* Resolves the external viewport prop at render time: false/omitted → private
|
|
772
|
+
* state; an object → required shared values plus defaulted behavior options.
|
|
773
|
+
* Never reads or clones the shared values; they remain UI-thread inputs.
|
|
774
|
+
*/
|
|
775
|
+
export function resolveViewport(
|
|
776
|
+
prop: false | ViewportConfig | undefined,
|
|
777
|
+
): ResolvedViewportConfig | null {
|
|
778
|
+
if (prop === undefined || prop === false) return null;
|
|
779
|
+
return {
|
|
780
|
+
end: prop.end,
|
|
781
|
+
window: prop.window,
|
|
782
|
+
windowSmoothing: prop.windowSmoothing ?? VIEWPORT_DEFAULTS.windowSmoothing,
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
|
|
729
786
|
export interface ResolvedZoomConfig {
|
|
730
787
|
/** Tightest window (max zoom-in), seconds. `undefined` → `timeWindow / 8`. */
|
|
731
788
|
minTimeWindow: number | undefined;
|
|
@@ -904,8 +961,12 @@ export function resolveAxisLabel(
|
|
|
904
961
|
|
|
905
962
|
const X_AXIS_DEFAULTS: ResolvedXAxisConfig = {
|
|
906
963
|
minGap: 60,
|
|
964
|
+
gridLines: null,
|
|
907
965
|
};
|
|
908
966
|
|
|
967
|
+
/** `gridLines: true` overrides nothing, so the lines take the `gridStyle` look. */
|
|
968
|
+
const NO_GRID_STYLE_OVERRIDES: GridStyleConfig = {};
|
|
969
|
+
|
|
909
970
|
/**
|
|
910
971
|
* Resolves `xAxis` prop to a fully-typed config or null (disabled).
|
|
911
972
|
* Defaults to enabled (`true`) so a bare `undefined` also returns the defaults.
|
|
@@ -913,10 +974,37 @@ const X_AXIS_DEFAULTS: ResolvedXAxisConfig = {
|
|
|
913
974
|
export function resolveXAxis(
|
|
914
975
|
prop: boolean | XAxisConfig | undefined,
|
|
915
976
|
): ResolvedXAxisConfig | null {
|
|
916
|
-
|
|
977
|
+
if (prop === false) return null;
|
|
978
|
+
if (prop == null || prop === true) return X_AXIS_DEFAULTS;
|
|
979
|
+
const { gridLines } = prop;
|
|
980
|
+
return {
|
|
981
|
+
minGap: prop.minGap ?? X_AXIS_DEFAULTS.minGap,
|
|
982
|
+
gridLines:
|
|
983
|
+
gridLines === true ? NO_GRID_STYLE_OVERRIDES : gridLines || null,
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
/**
|
|
988
|
+
* Resolves the vertical grid's style: `xAxis.gridLines` fields over the
|
|
989
|
+
* resolved `gridStyle`. Returns `base` itself when nothing is overridden, and
|
|
990
|
+
* null when the vertical grid is off.
|
|
991
|
+
*/
|
|
992
|
+
export function resolveXAxisGridStyle(
|
|
993
|
+
gridLines: GridStyleConfig | null,
|
|
994
|
+
base: ResolvedGridStyleConfig,
|
|
995
|
+
): ResolvedGridStyleConfig | null {
|
|
996
|
+
if (!gridLines) return null;
|
|
997
|
+
if (gridLines === NO_GRID_STYLE_OVERRIDES) return base;
|
|
998
|
+
return {
|
|
999
|
+
color: gridLines.color ?? base.color,
|
|
1000
|
+
strokeWidth: gridLines.strokeWidth ?? base.strokeWidth,
|
|
1001
|
+
intervals: gridLines.intervals ?? base.intervals,
|
|
1002
|
+
opacity: gridLines.opacity ?? base.opacity,
|
|
1003
|
+
};
|
|
917
1004
|
}
|
|
918
1005
|
|
|
919
1006
|
const SCRUB_DEFAULTS: ResolvedScrubConfig = {
|
|
1007
|
+
markers: null,
|
|
920
1008
|
tooltip: true,
|
|
921
1009
|
seriesTooltip: null,
|
|
922
1010
|
dimTarget: "future",
|
|
@@ -1005,6 +1093,11 @@ export function resolveScrub(
|
|
|
1005
1093
|
const seriesTooltip =
|
|
1006
1094
|
typeof prop === "object" ? prop.seriesTooltip : undefined;
|
|
1007
1095
|
resolved.seriesTooltip = resolvePerSeriesTooltip(seriesTooltip);
|
|
1096
|
+
const markers = typeof prop === "object" ? prop.markers : undefined;
|
|
1097
|
+
const radius = typeof markers === "object" ? markers.radius : undefined;
|
|
1098
|
+
resolved.markers = markers
|
|
1099
|
+
? { radius: radius !== undefined && Number.isFinite(radius) ? Math.max(0, radius) : 16 }
|
|
1100
|
+
: null;
|
|
1008
1101
|
// `resolveToggle` shallow-merges object props, so an explicitly undefined
|
|
1009
1102
|
// optional field replaces its default. Restore the public defaults before
|
|
1010
1103
|
// normalizing; otherwise the numeric clamps produce NaN and an undefined
|