@gearbox-protocol/ui-kit 4.5.0 → 4.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { createChart as
|
|
3
|
-
import * as
|
|
4
|
-
import { useRef as
|
|
5
|
-
import { resolveCSSColor as
|
|
6
|
-
import { useIsMobile as
|
|
1
|
+
import { jsxs as ee, jsx as _ } from "react/jsx-runtime";
|
|
2
|
+
import { createChart as ft, CrosshairMode as ht, LineStyle as le, LineSeries as dt, AreaSeries as mt } from "lightweight-charts";
|
|
3
|
+
import * as _e from "react";
|
|
4
|
+
import { useRef as H, useState as re, useEffect as W, useLayoutEffect as pt } from "react";
|
|
5
|
+
import { resolveCSSColor as ne, generateColorsFromBase as Pe } from "./colors.js";
|
|
6
|
+
import { useIsMobile as gt } from "../../hooks/use-media-query.js";
|
|
7
7
|
import { cn as J } from "../../utils/cn.js";
|
|
8
|
-
import { AXIS_TIME_EDGE_PADDING_PX as
|
|
9
|
-
import { formatExactValue as
|
|
10
|
-
import { GraphCurrentValue as
|
|
11
|
-
import { GraphTooltip as
|
|
12
|
-
import { VertLine as
|
|
13
|
-
import { resolvePriceScaleSides as
|
|
14
|
-
import { getSeriesColorPalette as
|
|
15
|
-
import { pickMinMove as
|
|
16
|
-
function
|
|
8
|
+
import { AXIS_TIME_EDGE_PADDING_PX as bt, getDefaultOptions as Ke, getDefaultSeries as St, AXIS_TICK_MARK_DENSITY as pe, getDefaultVerticalLine as vt, AXIS_FONT_SIZE as Ct, AXIS_EDGE_LABEL_PADDING_PX as Ze, AXIS_TOP_LABEL_PADDING_PX as qe } from "./default-config.js";
|
|
9
|
+
import { formatExactValue as Re, isRatioUnit as yt, getXFormatters as Je, createAdaptiveYAxisFormatter as xt } from "./formatters.js";
|
|
10
|
+
import { GraphCurrentValue as wt } from "./graph-current-value.js";
|
|
11
|
+
import { GraphTooltip as _t } from "./graph-tooltip.js";
|
|
12
|
+
import { VertLine as Pt } from "./plugins/vertical-line.js";
|
|
13
|
+
import { resolvePriceScaleSides as Rt } from "./series-config.js";
|
|
14
|
+
import { getSeriesColorPalette as Oe } from "./series-palette.js";
|
|
15
|
+
import { pickMinMove as Tt, niceAxisRange as Nt } from "./y-axis-scale.js";
|
|
16
|
+
function ie(e) {
|
|
17
17
|
return e.id ?? e.label;
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function Vt({
|
|
20
20
|
lastIndex: e,
|
|
21
|
-
width:
|
|
21
|
+
width: n,
|
|
22
22
|
padLeft: c,
|
|
23
23
|
padRight: f,
|
|
24
|
-
paddingPx: h =
|
|
24
|
+
paddingPx: h = bt
|
|
25
25
|
}) {
|
|
26
26
|
if (e < 0) return null;
|
|
27
|
-
const u = (c || f) &&
|
|
27
|
+
const u = (c || f) && n > 0 ? h * Math.max(e, 1) / n : 0;
|
|
28
28
|
return {
|
|
29
29
|
from: c && u !== 0 ? -u : 0,
|
|
30
30
|
to: f ? e + u : e
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function Qe(e, n, c) {
|
|
34
34
|
if (!c)
|
|
35
35
|
return e.values().next().value;
|
|
36
36
|
const f = e.get(c);
|
|
37
37
|
if (f) return f;
|
|
38
|
-
const h =
|
|
39
|
-
return h ? e.get(
|
|
38
|
+
const h = n.find((u) => u.id === c || u.label === c);
|
|
39
|
+
return h ? e.get(ie(h)) : void 0;
|
|
40
40
|
}
|
|
41
|
-
class
|
|
41
|
+
class kt {
|
|
42
42
|
_yTop;
|
|
43
43
|
_yBottom;
|
|
44
44
|
_color;
|
|
45
|
-
constructor(
|
|
46
|
-
this._yTop =
|
|
45
|
+
constructor(n, c, f) {
|
|
46
|
+
this._yTop = n, this._yBottom = c, this._color = f;
|
|
47
47
|
}
|
|
48
|
-
draw(
|
|
49
|
-
|
|
48
|
+
draw(n) {
|
|
49
|
+
n.useBitmapCoordinateSpace((c) => {
|
|
50
50
|
const f = c.context, h = c.verticalPixelRatio, u = this._yTop === null ? 0 : this._yTop * h, S = this._yBottom === null ? c.bitmapSize.height : this._yBottom * h, P = Math.min(u, S), D = Math.max(u, S);
|
|
51
51
|
f.fillStyle = this._color, f.fillRect(0, P, c.bitmapSize.width, D - P);
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
class
|
|
55
|
+
class Lt {
|
|
56
56
|
_source;
|
|
57
57
|
_yTop = null;
|
|
58
58
|
_yBottom = null;
|
|
59
|
-
constructor(
|
|
60
|
-
this._source =
|
|
59
|
+
constructor(n) {
|
|
60
|
+
this._source = n;
|
|
61
61
|
}
|
|
62
62
|
update() {
|
|
63
|
-
const
|
|
64
|
-
this._yTop = this._source.priceTop === void 0 ? null :
|
|
63
|
+
const n = this._source.series;
|
|
64
|
+
this._yTop = this._source.priceTop === void 0 ? null : n.priceToCoordinate(this._source.priceTop), this._yBottom = this._source.priceBottom === void 0 ? null : n.priceToCoordinate(this._source.priceBottom);
|
|
65
65
|
}
|
|
66
66
|
/** Draw beneath the series line/area so the data stays readable. */
|
|
67
67
|
zOrder() {
|
|
68
68
|
return "bottom";
|
|
69
69
|
}
|
|
70
70
|
renderer() {
|
|
71
|
-
return new
|
|
71
|
+
return new kt(this._yTop, this._yBottom, this._source.color);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
class
|
|
74
|
+
class Mt {
|
|
75
75
|
series;
|
|
76
76
|
priceTop;
|
|
77
77
|
priceBottom;
|
|
78
78
|
color;
|
|
79
79
|
_paneViews;
|
|
80
|
-
constructor(
|
|
81
|
-
this.series =
|
|
80
|
+
constructor(n, c, f, h) {
|
|
81
|
+
this.series = n, this.priceTop = c, this.priceBottom = f, this.color = h, this._paneViews = [new Lt(this)];
|
|
82
82
|
}
|
|
83
83
|
updateAllViews() {
|
|
84
|
-
for (const
|
|
84
|
+
for (const n of this._paneViews) n.update();
|
|
85
85
|
}
|
|
86
86
|
paneViews() {
|
|
87
87
|
return this._paneViews;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function Dt(e, n) {
|
|
91
91
|
switch (e) {
|
|
92
|
-
case
|
|
93
|
-
return [
|
|
94
|
-
case
|
|
95
|
-
return [2 *
|
|
96
|
-
case
|
|
97
|
-
return [6 *
|
|
98
|
-
case
|
|
99
|
-
return [
|
|
92
|
+
case le.Dotted:
|
|
93
|
+
return [n, n];
|
|
94
|
+
case le.Dashed:
|
|
95
|
+
return [2 * n, 2 * n];
|
|
96
|
+
case le.LargeDashed:
|
|
97
|
+
return [6 * n, 6 * n];
|
|
98
|
+
case le.SparseDotted:
|
|
99
|
+
return [n, 4 * n];
|
|
100
100
|
default:
|
|
101
101
|
return [];
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
class
|
|
104
|
+
class It {
|
|
105
105
|
_y;
|
|
106
106
|
_color;
|
|
107
107
|
_lineWidth;
|
|
108
108
|
_lineStyle;
|
|
109
|
-
constructor(
|
|
110
|
-
this._y =
|
|
109
|
+
constructor(n, c, f, h) {
|
|
110
|
+
this._y = n, this._color = c, this._lineWidth = f, this._lineStyle = h;
|
|
111
111
|
}
|
|
112
|
-
draw(
|
|
113
|
-
|
|
112
|
+
draw(n) {
|
|
113
|
+
n.useBitmapCoordinateSpace((c) => {
|
|
114
114
|
if (this._y === null) return;
|
|
115
115
|
const f = c.context, h = c.verticalPixelRatio, u = Math.max(1, Math.round(this._lineWidth * h)), S = Math.round(this._y * h);
|
|
116
|
-
f.save(), f.strokeStyle = this._color, f.lineWidth = u, f.setLineDash(
|
|
116
|
+
f.save(), f.strokeStyle = this._color, f.lineWidth = u, f.setLineDash(Dt(this._lineStyle, u)), f.beginPath(), f.moveTo(0, S), f.lineTo(c.bitmapSize.width, S), f.stroke(), f.restore();
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
class
|
|
120
|
+
class Bt {
|
|
121
121
|
_source;
|
|
122
122
|
_y = null;
|
|
123
|
-
constructor(
|
|
124
|
-
this._source =
|
|
123
|
+
constructor(n) {
|
|
124
|
+
this._source = n;
|
|
125
125
|
}
|
|
126
126
|
update() {
|
|
127
127
|
this._y = this._source.series.priceToCoordinate(this._source.price);
|
|
@@ -136,7 +136,7 @@ class It {
|
|
|
136
136
|
return "top";
|
|
137
137
|
}
|
|
138
138
|
renderer() {
|
|
139
|
-
return new
|
|
139
|
+
return new It(
|
|
140
140
|
this._y,
|
|
141
141
|
this._source.color,
|
|
142
142
|
this._source.lineWidth,
|
|
@@ -144,48 +144,48 @@ class It {
|
|
|
144
144
|
);
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
|
-
class
|
|
147
|
+
class Et {
|
|
148
148
|
series;
|
|
149
149
|
price;
|
|
150
150
|
color;
|
|
151
151
|
lineWidth;
|
|
152
152
|
lineStyle;
|
|
153
153
|
_paneViews;
|
|
154
|
-
constructor(
|
|
155
|
-
this.series =
|
|
154
|
+
constructor(n, c, f, h, u) {
|
|
155
|
+
this.series = n, this.price = c, this.color = f, this.lineWidth = h, this.lineStyle = u, this._paneViews = [new Bt(this)];
|
|
156
156
|
}
|
|
157
157
|
updateAllViews() {
|
|
158
|
-
for (const
|
|
158
|
+
for (const n of this._paneViews) n.update();
|
|
159
159
|
}
|
|
160
160
|
paneViews() {
|
|
161
161
|
return this._paneViews;
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
function
|
|
165
|
-
const f = e.labelText ?? "", h = e.value, u = h === void 0 ? "" : typeof h == "number" ?
|
|
164
|
+
function Ft(e, n, c) {
|
|
165
|
+
const f = e.labelText ?? "", h = e.value, u = h === void 0 ? "" : typeof h == "number" ? n === "$" ? `$${Re(h, void 0, c)}` : n === "%" ? `${Re(h, void 0, c)}%` : Re(
|
|
166
166
|
h,
|
|
167
|
-
|
|
167
|
+
n !== "none" && n !== "%" && n !== "$" && !yt(n) ? n : void 0,
|
|
168
168
|
c
|
|
169
169
|
) : String(h);
|
|
170
170
|
return { labelText: f, valueStr: u };
|
|
171
171
|
}
|
|
172
|
-
const
|
|
173
|
-
function
|
|
172
|
+
const Ye = 4;
|
|
173
|
+
function zt(e, n, c) {
|
|
174
174
|
const f = { left: e, transform: "translateX(-50%)" };
|
|
175
|
-
if (
|
|
175
|
+
if (n <= 0 || !c || c <= 0)
|
|
176
176
|
return f;
|
|
177
|
-
const h = c / 2, u =
|
|
178
|
-
return S < u ? { left:
|
|
177
|
+
const h = c / 2, u = Ye + h, S = n - Ye - h;
|
|
178
|
+
return S < u ? { left: n / 2, transform: "translateX(-50%)" } : { left: Math.min(Math.max(e, u), S), transform: "translateX(-50%)" };
|
|
179
179
|
}
|
|
180
|
-
function
|
|
180
|
+
function At(e, n) {
|
|
181
181
|
for (let c = e.length - 1; c >= 0; c--)
|
|
182
|
-
if (Number(e[c].time) <=
|
|
182
|
+
if (Number(e[c].time) <= n)
|
|
183
183
|
return e[c].value;
|
|
184
184
|
return 0;
|
|
185
185
|
}
|
|
186
|
-
function
|
|
186
|
+
function oo({
|
|
187
187
|
series: e,
|
|
188
|
-
className:
|
|
188
|
+
className: n,
|
|
189
189
|
showLegend: c = !1,
|
|
190
190
|
onUnselectSeries: f,
|
|
191
191
|
xMeasureUnit: h = "time",
|
|
@@ -195,84 +195,84 @@ function to({
|
|
|
195
195
|
priceLineOptions: D,
|
|
196
196
|
zoneOptions: F,
|
|
197
197
|
currentValueDecimals: se,
|
|
198
|
-
useSharedPriceScale:
|
|
198
|
+
useSharedPriceScale: K = !1,
|
|
199
199
|
dualYAxis: z = !1,
|
|
200
|
-
defaultVisiblePriceScaleId:
|
|
201
|
-
showCurrentValue:
|
|
202
|
-
graphTitle:
|
|
203
|
-
yScaleMin:
|
|
204
|
-
yScaleMinMultiple:
|
|
205
|
-
visibleTimeFrom:
|
|
206
|
-
disableZoom:
|
|
207
|
-
hideDefaultTooltip:
|
|
200
|
+
defaultVisiblePriceScaleId: Te = "right",
|
|
201
|
+
showCurrentValue: Ue = !0,
|
|
202
|
+
graphTitle: ge,
|
|
203
|
+
yScaleMin: Ne,
|
|
204
|
+
yScaleMinMultiple: Ve,
|
|
205
|
+
visibleTimeFrom: ae,
|
|
206
|
+
disableZoom: ke = !1,
|
|
207
|
+
hideDefaultTooltip: be = !1
|
|
208
208
|
}) {
|
|
209
|
-
const I =
|
|
209
|
+
const I = H(null), V = H(/* @__PURE__ */ new Map()), Se = H(!1), Le = H(!0), Me = H([]), ce = H(0), B = H(null), ve = H(null), De = H(null), R = gt(), ue = _e.useMemo(() => e.flatMap((t) => t.data), [e]), et = _e.useMemo(() => {
|
|
210
210
|
if (e.length > 0) {
|
|
211
211
|
const t = e[e.length - 1];
|
|
212
212
|
if (t.data.length > 0)
|
|
213
213
|
return t.data[t.data.length - 1];
|
|
214
214
|
}
|
|
215
|
-
}, [e]), [
|
|
216
|
-
if (!
|
|
215
|
+
}, [e]), [Ie, Ce] = re(() => {
|
|
216
|
+
if (!et) return;
|
|
217
217
|
const t = /* @__PURE__ */ new Map();
|
|
218
|
-
for (const
|
|
219
|
-
|
|
218
|
+
for (const s of e)
|
|
219
|
+
s.data.length > 0 && t.set(s.label, s.data[s.data.length - 1]);
|
|
220
220
|
return t;
|
|
221
|
-
}), [
|
|
221
|
+
}), [Be, Q] = re(null), [Ee, Fe] = re([]), [tt, ze] = re(0), Ae = H(/* @__PURE__ */ new Map()), [ot, rt] = re({}), [Y, nt] = re(0);
|
|
222
222
|
W(() => {
|
|
223
223
|
const t = () => {
|
|
224
224
|
try {
|
|
225
|
-
if (B.current &&
|
|
226
|
-
const
|
|
227
|
-
I.current.resize(
|
|
225
|
+
if (B.current && ze(B.current.clientWidth), I.current && B.current) {
|
|
226
|
+
const l = B.current.clientWidth, a = B.current.clientHeight;
|
|
227
|
+
I.current.resize(l, a);
|
|
228
228
|
try {
|
|
229
|
-
|
|
229
|
+
ce.current = I.current.paneSize().height;
|
|
230
230
|
} catch {
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
} catch {
|
|
234
234
|
}
|
|
235
|
-
},
|
|
236
|
-
return
|
|
237
|
-
|
|
235
|
+
}, s = B.current, r = s ? new ResizeObserver(t) : null;
|
|
236
|
+
return De.current = r, s && r?.observe(s), () => {
|
|
237
|
+
s && r?.unobserve(s), r?.disconnect(), De.current = null;
|
|
238
238
|
};
|
|
239
239
|
}, []), W(() => {
|
|
240
|
-
if (!
|
|
241
|
-
const t =
|
|
240
|
+
if (!ve.current || Se.current) return;
|
|
241
|
+
const t = Ke(), s = ne(
|
|
242
242
|
"hsl(var(--muted-foreground))",
|
|
243
243
|
"rgb(163, 163, 163)"
|
|
244
|
-
), r =
|
|
244
|
+
), r = ft(ve.current, {
|
|
245
245
|
...t,
|
|
246
246
|
leftPriceScale: {
|
|
247
247
|
...t.leftPriceScale || {},
|
|
248
248
|
visible: !1,
|
|
249
|
-
textColor:
|
|
249
|
+
textColor: s
|
|
250
250
|
},
|
|
251
251
|
rightPriceScale: {
|
|
252
252
|
...t.rightPriceScale || {},
|
|
253
253
|
visible: !R,
|
|
254
|
-
textColor:
|
|
254
|
+
textColor: s
|
|
255
255
|
},
|
|
256
256
|
...R && {
|
|
257
257
|
crosshair: {
|
|
258
258
|
...t.crosshair,
|
|
259
|
-
mode:
|
|
259
|
+
mode: ht.Magnet
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
});
|
|
263
|
-
I.current = r,
|
|
263
|
+
I.current = r, Se.current = !0;
|
|
264
264
|
try {
|
|
265
|
-
|
|
265
|
+
ce.current = r.paneSize().height;
|
|
266
266
|
} catch {
|
|
267
|
-
|
|
267
|
+
ce.current = 0;
|
|
268
268
|
}
|
|
269
|
-
return
|
|
270
|
-
r.remove(), I.current = null,
|
|
269
|
+
return nt((l) => l + 1), () => {
|
|
270
|
+
r.remove(), I.current = null, Se.current = !1, V.current.clear();
|
|
271
271
|
};
|
|
272
272
|
}, [R]), W(() => {
|
|
273
273
|
const t = I.current;
|
|
274
274
|
t && t.applyOptions(
|
|
275
|
-
|
|
275
|
+
ke ? {
|
|
276
276
|
handleScale: {
|
|
277
277
|
mouseWheel: !1,
|
|
278
278
|
pinch: !1,
|
|
@@ -300,218 +300,219 @@ function to({
|
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
);
|
|
303
|
-
}, [Y,
|
|
303
|
+
}, [Y, ke]), W(() => {
|
|
304
304
|
const t = I.current;
|
|
305
305
|
!t || !S || t.applyOptions(S);
|
|
306
306
|
}, [Y, S]), W(() => {
|
|
307
307
|
const t = I.current;
|
|
308
308
|
if (!t || e.length === 0) return;
|
|
309
|
-
const r = e.filter((
|
|
310
|
-
|
|
311
|
-
|
|
309
|
+
const r = e.filter((i) => i.data.length > 0).length <= 1 ? Ne : Ve, l = h === "time" ? Je(h, ue) : Je(h), a = new Map(
|
|
310
|
+
Rt(e).map(({ series: i, side: o }) => [
|
|
311
|
+
i.label,
|
|
312
312
|
o
|
|
313
313
|
])
|
|
314
|
-
),
|
|
315
|
-
const { formatter: L, tickmarksFormatter:
|
|
314
|
+
), m = (i, o, d) => {
|
|
315
|
+
const { formatter: L, tickmarksFormatter: N, updateVisibleRange: E } = xt(i, o, {
|
|
316
316
|
yScaleMin: r
|
|
317
317
|
});
|
|
318
|
-
return { formatter: L, tickmarksFormatter:
|
|
319
|
-
},
|
|
318
|
+
return { formatter: L, tickmarksFormatter: N, updateVisibleRange: E, labels: d };
|
|
319
|
+
}, p = [];
|
|
320
320
|
if (z)
|
|
321
|
-
for (const
|
|
321
|
+
for (const i of ["left", "right"]) {
|
|
322
322
|
const o = /* @__PURE__ */ new Set(), d = [];
|
|
323
323
|
let L = u;
|
|
324
|
-
for (const
|
|
325
|
-
if (
|
|
326
|
-
o.size === 0 &&
|
|
327
|
-
for (const E of
|
|
324
|
+
for (const N of e)
|
|
325
|
+
if (N.data.length !== 0 && a.get(N.label) === i) {
|
|
326
|
+
o.size === 0 && N.yMeasureUnit && (L = N.yMeasureUnit), o.add(N.label);
|
|
327
|
+
for (const E of N.data) d.push(E.value);
|
|
328
328
|
}
|
|
329
|
-
o.size > 0 &&
|
|
329
|
+
o.size > 0 && p.push(m(d, L, o));
|
|
330
330
|
}
|
|
331
331
|
else {
|
|
332
|
-
const
|
|
332
|
+
const i = ue.map((d) => d.value), o = new Set(
|
|
333
333
|
e.filter((d) => d.data.length > 0).map((d) => d.label)
|
|
334
334
|
);
|
|
335
|
-
|
|
335
|
+
p.push(m(i, u, o));
|
|
336
336
|
}
|
|
337
|
-
|
|
337
|
+
Me.current = p;
|
|
338
338
|
const y = /* @__PURE__ */ new Map();
|
|
339
|
-
for (const
|
|
340
|
-
for (const o of
|
|
341
|
-
y.set(o,
|
|
342
|
-
const x =
|
|
339
|
+
for (const i of p)
|
|
340
|
+
for (const o of i.labels)
|
|
341
|
+
y.set(o, i);
|
|
342
|
+
const x = Ke();
|
|
343
343
|
t.applyOptions({
|
|
344
344
|
localization: {
|
|
345
345
|
...x.localization || {},
|
|
346
346
|
// biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
|
|
347
|
-
timeFormatter: (
|
|
347
|
+
timeFormatter: (i) => (
|
|
348
348
|
// biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
|
|
349
|
-
|
|
349
|
+
l.timeFormatter(parseFloat(i), void 0)
|
|
350
350
|
)
|
|
351
351
|
},
|
|
352
352
|
timeScale: {
|
|
353
353
|
...x.timeScale || {},
|
|
354
354
|
...S?.timeScale,
|
|
355
355
|
// biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
|
|
356
|
-
tickMarkFormatter:
|
|
356
|
+
tickMarkFormatter: l.tickMarkFormatter,
|
|
357
357
|
minBarSpacing: 0
|
|
358
358
|
}
|
|
359
359
|
});
|
|
360
|
-
const v = !z && e.length > 1 && !
|
|
360
|
+
const v = !z && e.length > 1 && !K, X = z ? R : e.length > 1 && !K || R, k = ne(
|
|
361
361
|
"hsl(var(--muted-foreground))",
|
|
362
362
|
"rgb(163, 163, 163)"
|
|
363
363
|
);
|
|
364
364
|
t.applyOptions({
|
|
365
365
|
...z && {
|
|
366
|
-
defaultVisiblePriceScaleId:
|
|
366
|
+
defaultVisiblePriceScaleId: Te
|
|
367
367
|
},
|
|
368
368
|
leftPriceScale: {
|
|
369
369
|
...x.leftPriceScale || {},
|
|
370
370
|
...S?.leftPriceScale,
|
|
371
371
|
visible: z && !R,
|
|
372
|
-
textColor:
|
|
372
|
+
textColor: k
|
|
373
373
|
},
|
|
374
374
|
rightPriceScale: {
|
|
375
375
|
...x.rightPriceScale || {},
|
|
376
376
|
...S?.rightPriceScale,
|
|
377
377
|
visible: z ? !R : !X,
|
|
378
|
-
textColor:
|
|
378
|
+
textColor: k
|
|
379
379
|
}
|
|
380
380
|
});
|
|
381
|
-
const O = new Set(
|
|
382
|
-
for (const
|
|
383
|
-
if (!$.has(
|
|
384
|
-
const o =
|
|
385
|
-
o && (t.removeSeries(o),
|
|
381
|
+
const O = new Set(V.current.keys()), $ = new Set(e.map(ie));
|
|
382
|
+
for (const i of O)
|
|
383
|
+
if (!$.has(i)) {
|
|
384
|
+
const o = V.current.get(i);
|
|
385
|
+
o && (t.removeSeries(o), V.current.delete(i));
|
|
386
386
|
}
|
|
387
|
-
const g =
|
|
387
|
+
const g = St(), M = [];
|
|
388
388
|
let T = 0;
|
|
389
|
-
const G = e.find((
|
|
389
|
+
const G = e.find((i) => i.data.length > 0), C = /* @__PURE__ */ new Map();
|
|
390
390
|
if (D && D.length > 0)
|
|
391
|
-
for (const
|
|
392
|
-
if (!Number.isFinite(
|
|
393
|
-
const o =
|
|
391
|
+
for (const i of D) {
|
|
392
|
+
if (!Number.isFinite(i.price)) continue;
|
|
393
|
+
const o = i.seriesLabel ?? G?.label;
|
|
394
394
|
if (!o) continue;
|
|
395
395
|
const d = C.get(o) ?? [];
|
|
396
|
-
d.push(
|
|
396
|
+
d.push(i.price), C.set(o, d);
|
|
397
397
|
}
|
|
398
398
|
if (F && F.length > 0)
|
|
399
|
-
for (const
|
|
400
|
-
const o =
|
|
399
|
+
for (const i of F) {
|
|
400
|
+
const o = i.seriesLabel ?? G?.label;
|
|
401
401
|
if (!o) continue;
|
|
402
402
|
const d = C.get(o) ?? [];
|
|
403
|
-
Number.isFinite(
|
|
403
|
+
Number.isFinite(i.priceTop) && d.push(i.priceTop), Number.isFinite(i.priceBottom) && d.push(i.priceBottom), C.set(o, d);
|
|
404
404
|
}
|
|
405
|
-
for (let
|
|
406
|
-
const o = e[
|
|
405
|
+
for (let i = 0; i < e.length; i++) {
|
|
406
|
+
const o = e[i], d = ie(o), L = Oe(i), N = o.lineColor ?? o.color ?? L.line;
|
|
407
407
|
let E, q;
|
|
408
408
|
if (o.lineColor ?? o.color)
|
|
409
409
|
if (o.topColor && o.bottomColor)
|
|
410
410
|
E = o.topColor, q = o.bottomColor;
|
|
411
411
|
else if (o.topColor) {
|
|
412
|
-
const b =
|
|
412
|
+
const b = Pe(N);
|
|
413
413
|
E = o.topColor, q = b.bottomColor;
|
|
414
414
|
} else if (o.bottomColor)
|
|
415
|
-
E =
|
|
415
|
+
E = Pe(N).topColor, q = o.bottomColor;
|
|
416
416
|
else {
|
|
417
|
-
const b =
|
|
417
|
+
const b = Pe(N);
|
|
418
418
|
E = b.topColor, q = b.bottomColor;
|
|
419
419
|
}
|
|
420
420
|
else
|
|
421
421
|
E = o.topColor || L.top, q = o.bottomColor || L.bottom;
|
|
422
422
|
if (o.data.length === 0) {
|
|
423
|
-
const b =
|
|
424
|
-
b && (t.removeSeries(b),
|
|
423
|
+
const b = V.current.get(d);
|
|
424
|
+
b && (t.removeSeries(b), V.current.delete(d));
|
|
425
425
|
continue;
|
|
426
426
|
}
|
|
427
|
-
const
|
|
427
|
+
const fe = o.data.length > 0 ? Math.min(...o.data.map((b) => b.value)) : 0, de = o.data.length > 0 ? Math.max(...o.data.map((b) => b.value)) : 0, it = fe < 0, lt = o.data.some((b) => b.value === 0), st = !it && lt, Xe = Tt(de - fe), $e = z ? o.priceScaleId ?? (T === 0 ? "left" : "right") : K || !v || T === 0 ? "right" : `scale-${T}`;
|
|
428
428
|
v && M.push({
|
|
429
|
-
priceScaleId:
|
|
429
|
+
priceScaleId: $e || "right",
|
|
430
430
|
seriesIndex: T
|
|
431
431
|
});
|
|
432
|
-
const
|
|
432
|
+
const ye = (K || !v) && r !== void 0 && typeof r == "number", at = C.get(o.label) ?? [], ct = (b) => {
|
|
433
433
|
const w = b();
|
|
434
434
|
if (w?.priceRange) {
|
|
435
|
-
|
|
436
|
-
for (const
|
|
437
|
-
|
|
438
|
-
const
|
|
439
|
-
if (
|
|
440
|
-
const
|
|
435
|
+
ye && (w.priceRange.minValue = r);
|
|
436
|
+
for (const j of at)
|
|
437
|
+
j < w.priceRange.minValue && (w.priceRange.minValue = j), j > w.priceRange.maxValue && (w.priceRange.maxValue = j);
|
|
438
|
+
const oe = ye ? r : st && w.priceRange.minValue >= 0 ? 0 : void 0, me = ce.current > 0 ? ce.current : B.current?.clientHeight ?? 0;
|
|
439
|
+
if (me > 0) {
|
|
440
|
+
const j = Nt({
|
|
441
441
|
min: w.priceRange.minValue,
|
|
442
442
|
max: w.priceRange.maxValue,
|
|
443
|
-
floor:
|
|
444
|
-
scaleHeightPx:
|
|
445
|
-
fontSizePx:
|
|
443
|
+
floor: oe,
|
|
444
|
+
scaleHeightPx: me,
|
|
445
|
+
fontSizePx: Ct,
|
|
446
446
|
tickMarkDensity: pe,
|
|
447
|
-
minMove:
|
|
448
|
-
edgePaddingPx:
|
|
449
|
-
edgePaddingTopPx:
|
|
447
|
+
minMove: Xe,
|
|
448
|
+
edgePaddingPx: Ze,
|
|
449
|
+
edgePaddingTopPx: qe
|
|
450
450
|
});
|
|
451
|
-
w.priceRange.minValue =
|
|
451
|
+
w.priceRange.minValue = j.min, w.priceRange.maxValue = j.max;
|
|
452
452
|
}
|
|
453
453
|
w.margins = {
|
|
454
|
-
above:
|
|
455
|
-
below:
|
|
454
|
+
above: qe,
|
|
455
|
+
below: Ze
|
|
456
456
|
};
|
|
457
457
|
}
|
|
458
458
|
return w;
|
|
459
|
-
},
|
|
460
|
-
lineColor:
|
|
459
|
+
}, Ge = y.get(o.label) ?? p[0], je = Ge.formatter, ut = Ge.tickmarksFormatter, xe = {
|
|
460
|
+
lineColor: N,
|
|
461
461
|
topColor: E,
|
|
462
462
|
bottomColor: q,
|
|
463
|
-
priceScaleId:
|
|
463
|
+
priceScaleId: $e,
|
|
464
464
|
...o.seriesType === "line" && {
|
|
465
|
-
|
|
465
|
+
color: N,
|
|
466
|
+
lineStyle: o.lineStyle ?? le.Solid
|
|
466
467
|
},
|
|
467
468
|
priceFormat: {
|
|
468
469
|
type: "custom",
|
|
469
|
-
minMove:
|
|
470
|
-
formatter:
|
|
470
|
+
minMove: Xe,
|
|
471
|
+
formatter: ye && typeof r == "number" ? (b) => je(
|
|
471
472
|
b < r ? r : b
|
|
472
|
-
) :
|
|
473
|
-
tickmarksFormatter:
|
|
473
|
+
) : je,
|
|
474
|
+
tickmarksFormatter: ut
|
|
474
475
|
},
|
|
475
|
-
autoscaleInfoProvider:
|
|
476
|
-
},
|
|
477
|
-
let A =
|
|
478
|
-
const
|
|
476
|
+
autoscaleInfoProvider: ct
|
|
477
|
+
}, He = o.seriesType === "line";
|
|
478
|
+
let A = V.current.get(d);
|
|
479
|
+
const te = o.data.map((b) => ({
|
|
479
480
|
...b,
|
|
480
481
|
time: b.time
|
|
481
482
|
}));
|
|
482
|
-
if (
|
|
483
|
-
const b = Number(
|
|
484
|
-
for (let
|
|
485
|
-
|
|
486
|
-
|
|
483
|
+
if (ae !== void 0 && te.length > 0 && Number(te[0].time) > ae) {
|
|
484
|
+
const b = Number(te[0].time), w = b - ae, oe = 86400, me = w > 180 * oe ? 7 * oe : w > 30 * oe ? oe : 6 * 3600, j = [];
|
|
485
|
+
for (let we = ae; we < b; we += me)
|
|
486
|
+
j.push({ time: we });
|
|
487
|
+
te.unshift(...j);
|
|
487
488
|
}
|
|
488
|
-
A && A.seriesType() !== (
|
|
489
|
+
A && A.seriesType() !== (He ? "Line" : "Area") && (t.removeSeries(A), V.current.delete(d), A = void 0), A ? (A.applyOptions(xe), A.setData(te)) : (He ? A = t.addSeries(dt, {
|
|
489
490
|
...g,
|
|
490
|
-
...
|
|
491
|
-
}) : A = t.addSeries(
|
|
491
|
+
...xe
|
|
492
|
+
}) : A = t.addSeries(mt, {
|
|
492
493
|
...g,
|
|
493
|
-
...
|
|
494
|
-
}), A.setData(
|
|
494
|
+
...xe
|
|
495
|
+
}), A.setData(te), V.current.set(d, A)), T++;
|
|
495
496
|
}
|
|
496
497
|
if (z)
|
|
497
498
|
try {
|
|
498
|
-
const
|
|
499
|
+
const i = t.priceScale("left"), o = t.priceScale("right"), d = {
|
|
499
500
|
visible: !R,
|
|
500
501
|
autoScale: !0,
|
|
501
502
|
scaleMargins: { top: 0, bottom: 0 },
|
|
502
503
|
alignLabels: !0,
|
|
503
504
|
entireTextOnly: !1,
|
|
504
505
|
tickMarkDensity: pe,
|
|
505
|
-
textColor:
|
|
506
|
+
textColor: k,
|
|
506
507
|
...S?.rightPriceScale
|
|
507
508
|
};
|
|
508
|
-
|
|
509
|
+
i?.applyOptions(d), o?.applyOptions(d);
|
|
509
510
|
} catch {
|
|
510
511
|
}
|
|
511
512
|
else if (v && M.length > 0)
|
|
512
|
-
for (const
|
|
513
|
+
for (const i of M)
|
|
513
514
|
try {
|
|
514
|
-
const o = t.priceScale(
|
|
515
|
+
const o = t.priceScale(i.priceScaleId);
|
|
515
516
|
o && o.applyOptions({
|
|
516
517
|
visible: !1,
|
|
517
518
|
autoScale: !0,
|
|
@@ -522,18 +523,18 @@ function to({
|
|
|
522
523
|
alignLabels: !0,
|
|
523
524
|
entireTextOnly: !1,
|
|
524
525
|
tickMarkDensity: pe,
|
|
525
|
-
textColor:
|
|
526
|
+
textColor: k
|
|
526
527
|
});
|
|
527
528
|
} catch (o) {
|
|
528
529
|
console.warn(
|
|
529
|
-
`Failed to configure price scale ${
|
|
530
|
+
`Failed to configure price scale ${i.priceScaleId} for series ${i.seriesIndex}:`,
|
|
530
531
|
o
|
|
531
532
|
);
|
|
532
533
|
}
|
|
533
534
|
else if (!v)
|
|
534
535
|
try {
|
|
535
|
-
const
|
|
536
|
-
|
|
536
|
+
const i = t.priceScale("right");
|
|
537
|
+
i && i.applyOptions({
|
|
537
538
|
visible: !R,
|
|
538
539
|
autoScale: !0,
|
|
539
540
|
scaleMargins: {
|
|
@@ -543,17 +544,19 @@ function to({
|
|
|
543
544
|
alignLabels: !0,
|
|
544
545
|
entireTextOnly: !1,
|
|
545
546
|
tickMarkDensity: pe,
|
|
546
|
-
textColor:
|
|
547
|
+
textColor: k,
|
|
547
548
|
...S?.rightPriceScale
|
|
548
549
|
});
|
|
549
550
|
} catch {
|
|
550
551
|
}
|
|
551
|
-
|
|
552
|
+
r !== void 0 && !R && (K || !v) && t.applyOptions({
|
|
552
553
|
handleScroll: {
|
|
553
554
|
vertTouchDrag: !1
|
|
554
555
|
}
|
|
555
|
-
})
|
|
556
|
-
|
|
556
|
+
});
|
|
557
|
+
let Z = 0;
|
|
558
|
+
if (ue.length > 0) {
|
|
559
|
+
const i = ue.map((d) => Number(d.time)).filter((d) => Number.isFinite(d)), o = new Set(i).size - 1;
|
|
557
560
|
if (o >= 0) {
|
|
558
561
|
const d = () => {
|
|
559
562
|
const L = t.timeScale();
|
|
@@ -564,18 +567,23 @@ function to({
|
|
|
564
567
|
}), L.setVisibleLogicalRange({ from: 0, to: o });
|
|
565
568
|
return;
|
|
566
569
|
}
|
|
567
|
-
const
|
|
570
|
+
const N = z && !R, E = z ? !R : !X, q = !N, fe = !E;
|
|
568
571
|
L.applyOptions({
|
|
569
572
|
fixLeftEdge: !q,
|
|
570
|
-
fixRightEdge: !
|
|
571
|
-
})
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
573
|
+
fixRightEdge: !fe
|
|
574
|
+
}), Z = requestAnimationFrame(() => {
|
|
575
|
+
const de = Vt({
|
|
576
|
+
lastIndex: o,
|
|
577
|
+
width: L.width(),
|
|
578
|
+
padLeft: q,
|
|
579
|
+
padRight: fe
|
|
580
|
+
});
|
|
581
|
+
try {
|
|
582
|
+
de && L.setVisibleLogicalRange(de);
|
|
583
|
+
} catch {
|
|
584
|
+
L.fitContent();
|
|
585
|
+
}
|
|
577
586
|
});
|
|
578
|
-
he && L.setVisibleLogicalRange(he);
|
|
579
587
|
};
|
|
580
588
|
try {
|
|
581
589
|
d();
|
|
@@ -587,31 +595,31 @@ function to({
|
|
|
587
595
|
}
|
|
588
596
|
}
|
|
589
597
|
}
|
|
590
|
-
|
|
591
|
-
const
|
|
592
|
-
for (const
|
|
593
|
-
|
|
594
|
-
|
|
598
|
+
Le.current && (Le.current = !1), S && t.applyOptions(S);
|
|
599
|
+
const U = /* @__PURE__ */ new Map();
|
|
600
|
+
for (const i of e)
|
|
601
|
+
i.data.length > 0 && U.set(i.label, i.data[i.data.length - 1]);
|
|
602
|
+
return Ce(U.size > 0 ? U : void 0), () => cancelAnimationFrame(Z);
|
|
595
603
|
}, [
|
|
596
604
|
Y,
|
|
597
605
|
e,
|
|
598
|
-
|
|
606
|
+
ue,
|
|
599
607
|
h,
|
|
600
608
|
u,
|
|
601
609
|
R,
|
|
602
|
-
|
|
610
|
+
K,
|
|
603
611
|
z,
|
|
604
|
-
Re,
|
|
605
612
|
Te,
|
|
606
613
|
Ne,
|
|
607
|
-
|
|
614
|
+
Ve,
|
|
615
|
+
ae,
|
|
608
616
|
D,
|
|
609
617
|
F,
|
|
610
618
|
S
|
|
611
619
|
]), W(() => {
|
|
612
620
|
const t = I.current;
|
|
613
621
|
if (!t || e.length === 0) return;
|
|
614
|
-
const
|
|
622
|
+
const s = e.length === 1;
|
|
615
623
|
let r;
|
|
616
624
|
for (const a of e)
|
|
617
625
|
if (a.data.length > 0) {
|
|
@@ -619,13 +627,13 @@ function to({
|
|
|
619
627
|
break;
|
|
620
628
|
}
|
|
621
629
|
if (!r) return;
|
|
622
|
-
const
|
|
623
|
-
const { time:
|
|
624
|
-
if (!y || !
|
|
630
|
+
const l = (a) => {
|
|
631
|
+
const { time: m = r, seriesData: p, point: y } = a || {}, x = e[0], v = x ? V.current.get(ie(x)) : void 0;
|
|
632
|
+
if (!y || !m) {
|
|
625
633
|
const $ = /* @__PURE__ */ new Map();
|
|
626
634
|
for (const g of e)
|
|
627
635
|
g.data.length > 0 && $.set(g.label, g.data[g.data.length - 1]);
|
|
628
|
-
if (
|
|
636
|
+
if (Ce($.size > 0 ? $ : void 0), s || K || be)
|
|
629
637
|
Q(null);
|
|
630
638
|
else if (v && r) {
|
|
631
639
|
const g = e[0];
|
|
@@ -637,26 +645,26 @@ function to({
|
|
|
637
645
|
return;
|
|
638
646
|
}
|
|
639
647
|
const X = /* @__PURE__ */ new Map();
|
|
640
|
-
let
|
|
648
|
+
let k, O = v;
|
|
641
649
|
for (let $ = 0; $ < e.length; $++) {
|
|
642
|
-
const g = e[$], M =
|
|
650
|
+
const g = e[$], M = V.current.get(ie(g));
|
|
643
651
|
if (!M) continue;
|
|
644
|
-
const T =
|
|
652
|
+
const T = p?.get(M), G = T && "value" in T ? T.value : void 0;
|
|
645
653
|
let C;
|
|
646
654
|
if (G !== void 0)
|
|
647
655
|
C = G;
|
|
648
|
-
else if (
|
|
649
|
-
const
|
|
650
|
-
|
|
656
|
+
else if (s) {
|
|
657
|
+
const Z = Number(m), U = g.data.length > 0 ? Number(g.data[0].time) : Number.POSITIVE_INFINITY;
|
|
658
|
+
Z < U ? C = Number.NaN : C = g.data[g.data.length - 1]?.value ?? 0;
|
|
651
659
|
} else {
|
|
652
|
-
const
|
|
653
|
-
if (Number(
|
|
654
|
-
C =
|
|
660
|
+
const Z = g.data.length > 0 ? Number(g.data[0].time) : Number.POSITIVE_INFINITY;
|
|
661
|
+
if (Number(m) < Z) continue;
|
|
662
|
+
C = At(g.data, Number(m));
|
|
655
663
|
}
|
|
656
|
-
Number.isNaN(C) || (
|
|
664
|
+
Number.isNaN(C) || (k === void 0 && (k = C, O = M), X.set(g.label, { value: C, time: m }));
|
|
657
665
|
}
|
|
658
|
-
if (
|
|
659
|
-
const g = t.timeScale().timeToCoordinate(
|
|
666
|
+
if (Ce(X), k !== void 0 && O) {
|
|
667
|
+
const g = t.timeScale().timeToCoordinate(m), M = O.priceToCoordinate(k);
|
|
660
668
|
if (g !== null && M !== null) {
|
|
661
669
|
const T = B.current;
|
|
662
670
|
if (T) {
|
|
@@ -664,8 +672,8 @@ function to({
|
|
|
664
672
|
".LightweightChart"
|
|
665
673
|
);
|
|
666
674
|
if (G) {
|
|
667
|
-
const C = G.getBoundingClientRect(),
|
|
668
|
-
Q({ x:
|
|
675
|
+
const C = G.getBoundingClientRect(), Z = T.getBoundingClientRect(), U = g + (C.left - Z.left), i = M + (C.top - Z.top);
|
|
676
|
+
Q({ x: U, y: i });
|
|
669
677
|
} else
|
|
670
678
|
Q({ x: g, y: M });
|
|
671
679
|
} else
|
|
@@ -675,252 +683,252 @@ function to({
|
|
|
675
683
|
} else
|
|
676
684
|
Q(null);
|
|
677
685
|
};
|
|
678
|
-
return t.subscribeCrosshairMove(
|
|
679
|
-
const a = e[0],
|
|
680
|
-
if (
|
|
681
|
-
const y = t.timeScale().timeToCoordinate(r), x = a.data[a.data.length - 1].value, v =
|
|
686
|
+
return t.subscribeCrosshairMove(l), R && t.subscribeClick(l), !s && !K && !be && requestAnimationFrame(() => {
|
|
687
|
+
const a = e[0], m = a ? V.current.get(ie(a)) : void 0;
|
|
688
|
+
if (m && r && a.data.length > 0) {
|
|
689
|
+
const y = t.timeScale().timeToCoordinate(r), x = a.data[a.data.length - 1].value, v = m.priceToCoordinate(x);
|
|
682
690
|
y !== null && v !== null && Q({ x: y, y: v });
|
|
683
691
|
}
|
|
684
692
|
}), () => {
|
|
685
|
-
t.unsubscribeCrosshairMove(
|
|
693
|
+
t.unsubscribeCrosshairMove(l), R && t.unsubscribeClick(l);
|
|
686
694
|
};
|
|
687
|
-
}, [e,
|
|
695
|
+
}, [e, K, R, be]), W(() => {
|
|
688
696
|
const t = I.current;
|
|
689
697
|
if (!t || e.length === 0) return;
|
|
690
|
-
const
|
|
691
|
-
const
|
|
692
|
-
if (
|
|
693
|
-
const a =
|
|
698
|
+
const s = t.timeScale(), r = () => {
|
|
699
|
+
const l = Me.current;
|
|
700
|
+
if (l.length === 0) return;
|
|
701
|
+
const a = s.getVisibleRange();
|
|
694
702
|
if (!a) return;
|
|
695
|
-
const
|
|
696
|
-
for (const y of
|
|
703
|
+
const m = Number(a.from), p = Number(a.to);
|
|
704
|
+
for (const y of l) {
|
|
697
705
|
const x = [];
|
|
698
706
|
for (const v of e)
|
|
699
707
|
if (y.labels.has(v.label))
|
|
700
708
|
for (const X of v.data) {
|
|
701
|
-
const
|
|
702
|
-
|
|
709
|
+
const k = Number(X.time);
|
|
710
|
+
k >= m && k <= p && x.push(X.value);
|
|
703
711
|
}
|
|
704
712
|
x.length > 0 && y.updateVisibleRange(x);
|
|
705
713
|
}
|
|
706
714
|
};
|
|
707
|
-
return
|
|
708
|
-
|
|
715
|
+
return s.subscribeVisibleLogicalRangeChange(r), () => {
|
|
716
|
+
s.unsubscribeVisibleLogicalRangeChange(
|
|
709
717
|
r
|
|
710
718
|
);
|
|
711
719
|
};
|
|
712
720
|
}, [e]), W(() => {
|
|
713
|
-
const t = I.current,
|
|
714
|
-
if (t &&
|
|
715
|
-
const
|
|
716
|
-
for (const
|
|
717
|
-
const
|
|
718
|
-
...
|
|
719
|
-
...
|
|
721
|
+
const t = I.current, s = Array.from(V.current.values()), r = [];
|
|
722
|
+
if (t && s.length > 0 && P) {
|
|
723
|
+
const l = vt(), a = s[0];
|
|
724
|
+
for (const m of P) {
|
|
725
|
+
const p = {
|
|
726
|
+
...l,
|
|
727
|
+
...m.options || {}
|
|
720
728
|
};
|
|
721
|
-
|
|
722
|
-
const y = new
|
|
729
|
+
p.color && (p.color = ne(p.color, p.color));
|
|
730
|
+
const y = new Pt(
|
|
723
731
|
t,
|
|
724
732
|
a,
|
|
725
|
-
|
|
726
|
-
|
|
733
|
+
m.xCoordinate,
|
|
734
|
+
p
|
|
727
735
|
);
|
|
728
736
|
a.attachPrimitive(y), r.push(y);
|
|
729
737
|
}
|
|
730
738
|
}
|
|
731
739
|
return () => {
|
|
732
|
-
if (
|
|
733
|
-
const
|
|
740
|
+
if (s.length > 0) {
|
|
741
|
+
const l = s[0];
|
|
734
742
|
for (const a of r)
|
|
735
743
|
try {
|
|
736
|
-
|
|
744
|
+
l.detachPrimitive(a);
|
|
737
745
|
} catch {
|
|
738
746
|
}
|
|
739
747
|
}
|
|
740
748
|
};
|
|
741
749
|
}, [P, e, Y]), W(() => {
|
|
742
|
-
const t = [],
|
|
750
|
+
const t = [], s = [];
|
|
743
751
|
if (D && D.length > 0) {
|
|
744
|
-
const r =
|
|
752
|
+
const r = ne(
|
|
745
753
|
"hsl(var(--destructive))",
|
|
746
754
|
"rgb(239, 68, 68)"
|
|
747
755
|
);
|
|
748
|
-
for (const
|
|
749
|
-
if (!Number.isFinite(
|
|
750
|
-
const a =
|
|
751
|
-
|
|
756
|
+
for (const l of D) {
|
|
757
|
+
if (!Number.isFinite(l.price)) continue;
|
|
758
|
+
const a = Qe(
|
|
759
|
+
V.current,
|
|
752
760
|
e,
|
|
753
|
-
|
|
761
|
+
l.seriesLabel
|
|
754
762
|
);
|
|
755
763
|
if (!a) continue;
|
|
756
|
-
const
|
|
757
|
-
price:
|
|
758
|
-
color:
|
|
759
|
-
lineWidth:
|
|
764
|
+
const m = l.color ? ne(l.color, l.color) : r, p = l.lineWidth ?? 1, y = l.lineStyle ?? le.Dashed, x = a.createPriceLine({
|
|
765
|
+
price: l.price,
|
|
766
|
+
color: m,
|
|
767
|
+
lineWidth: p,
|
|
760
768
|
lineStyle: y,
|
|
761
|
-
axisLabelVisible:
|
|
762
|
-
title:
|
|
769
|
+
axisLabelVisible: l.axisLabelVisible ?? !0,
|
|
770
|
+
title: l.title ?? ""
|
|
763
771
|
});
|
|
764
772
|
t.push({ series: a, line: x });
|
|
765
|
-
const v = new
|
|
773
|
+
const v = new Et(
|
|
766
774
|
a,
|
|
767
|
-
|
|
768
|
-
p,
|
|
775
|
+
l.price,
|
|
769
776
|
m,
|
|
777
|
+
p,
|
|
770
778
|
y
|
|
771
779
|
);
|
|
772
|
-
a.attachPrimitive(v),
|
|
780
|
+
a.attachPrimitive(v), s.push({ series: a, primitive: v });
|
|
773
781
|
}
|
|
774
782
|
}
|
|
775
783
|
return () => {
|
|
776
|
-
for (const { series: r, primitive:
|
|
784
|
+
for (const { series: r, primitive: l } of s)
|
|
777
785
|
try {
|
|
778
|
-
r.detachPrimitive(
|
|
786
|
+
r.detachPrimitive(l);
|
|
779
787
|
} catch {
|
|
780
788
|
}
|
|
781
|
-
for (const { series: r, line:
|
|
789
|
+
for (const { series: r, line: l } of t)
|
|
782
790
|
try {
|
|
783
|
-
r.removePriceLine(
|
|
791
|
+
r.removePriceLine(l);
|
|
784
792
|
} catch {
|
|
785
793
|
}
|
|
786
794
|
};
|
|
787
795
|
}, [D, e, Y]), W(() => {
|
|
788
796
|
const t = [];
|
|
789
797
|
if (F && F.length > 0) {
|
|
790
|
-
const
|
|
798
|
+
const s = "rgba(239, 68, 68, 0.12)";
|
|
791
799
|
for (const r of F) {
|
|
792
|
-
const
|
|
793
|
-
|
|
800
|
+
const l = Qe(
|
|
801
|
+
V.current,
|
|
794
802
|
e,
|
|
795
803
|
r.seriesLabel
|
|
796
804
|
);
|
|
797
|
-
if (!
|
|
798
|
-
const a = r.color ?
|
|
799
|
-
|
|
805
|
+
if (!l) continue;
|
|
806
|
+
const a = r.color ? ne(r.color, s) : s, m = new Mt(
|
|
807
|
+
l,
|
|
800
808
|
r.priceTop,
|
|
801
809
|
r.priceBottom,
|
|
802
810
|
a
|
|
803
811
|
);
|
|
804
|
-
|
|
812
|
+
l.attachPrimitive(m), t.push({ series: l, zone: m });
|
|
805
813
|
}
|
|
806
814
|
}
|
|
807
815
|
return () => {
|
|
808
|
-
for (const { series:
|
|
816
|
+
for (const { series: s, zone: r } of t)
|
|
809
817
|
try {
|
|
810
|
-
|
|
818
|
+
s.detachPrimitive(r);
|
|
811
819
|
} catch {
|
|
812
820
|
}
|
|
813
821
|
};
|
|
814
822
|
}, [F, e, Y]), W(() => {
|
|
815
823
|
const t = I.current;
|
|
816
824
|
if (!t || !P?.length) {
|
|
817
|
-
|
|
825
|
+
Fe([]);
|
|
818
826
|
return;
|
|
819
827
|
}
|
|
820
|
-
const
|
|
821
|
-
const a = t.timeScale(),
|
|
822
|
-
|
|
828
|
+
const s = () => {
|
|
829
|
+
const a = t.timeScale(), m = P.map((p) => a.timeToCoordinate(p.xCoordinate) ?? null);
|
|
830
|
+
Fe(m), B.current && ze(B.current.clientWidth);
|
|
823
831
|
};
|
|
824
|
-
|
|
825
|
-
const r = t.timeScale(),
|
|
826
|
-
|
|
832
|
+
s();
|
|
833
|
+
const r = t.timeScale(), l = () => {
|
|
834
|
+
s();
|
|
827
835
|
};
|
|
828
|
-
return r.subscribeVisibleLogicalRangeChange(
|
|
829
|
-
r.unsubscribeVisibleLogicalRangeChange(
|
|
836
|
+
return r.subscribeVisibleLogicalRangeChange(l), () => {
|
|
837
|
+
r.unsubscribeVisibleLogicalRangeChange(l);
|
|
830
838
|
};
|
|
831
839
|
}, [P, e, Y]), pt(() => {
|
|
832
|
-
|
|
833
|
-
const
|
|
840
|
+
rt((t) => {
|
|
841
|
+
const s = {};
|
|
834
842
|
let r = !1;
|
|
835
|
-
for (const [
|
|
843
|
+
for (const [l, a] of Ae.current) {
|
|
836
844
|
if (!a) continue;
|
|
837
|
-
const
|
|
838
|
-
l
|
|
845
|
+
const m = a.offsetWidth;
|
|
846
|
+
s[l] = m, t[l] !== m && (r = !0);
|
|
839
847
|
}
|
|
840
|
-
return Object.keys(t).length !== Object.keys(
|
|
848
|
+
return Object.keys(t).length !== Object.keys(s).length && (r = !0), r ? s : t;
|
|
841
849
|
});
|
|
842
850
|
});
|
|
843
|
-
const
|
|
844
|
-
if (
|
|
851
|
+
const he = e.length === 1, We = _e.useMemo(() => {
|
|
852
|
+
if (he && e.length > 0) {
|
|
845
853
|
const t = e[0];
|
|
846
854
|
if (t.data.length > 0)
|
|
847
855
|
return t.data[t.data.length - 1];
|
|
848
856
|
}
|
|
849
|
-
}, [
|
|
850
|
-
return /* @__PURE__ */
|
|
857
|
+
}, [he, e]);
|
|
858
|
+
return /* @__PURE__ */ ee(
|
|
851
859
|
"div",
|
|
852
860
|
{
|
|
853
861
|
ref: B,
|
|
854
862
|
className: J(
|
|
855
863
|
"relative z-[1] w-full h-full overflow-hidden p-0",
|
|
856
|
-
|
|
864
|
+
n
|
|
857
865
|
),
|
|
858
866
|
children: [
|
|
859
|
-
|
|
860
|
-
|
|
867
|
+
ge != null && ge !== !1 && he ? /* @__PURE__ */ _("div", { className: "absolute top-2 left-2 right-2 z-[100] pointer-events-none", children: /* @__PURE__ */ _("div", { className: "text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis", children: ge }) }) : Ue && he && We && /* @__PURE__ */ _(
|
|
868
|
+
wt,
|
|
861
869
|
{
|
|
862
|
-
point:
|
|
870
|
+
point: We,
|
|
863
871
|
xMeasureUnit: h,
|
|
864
872
|
yMeasureUnit: u,
|
|
865
873
|
decimals: se
|
|
866
874
|
}
|
|
867
875
|
),
|
|
868
|
-
|
|
869
|
-
|
|
876
|
+
Ie && Be && /* @__PURE__ */ _(
|
|
877
|
+
_t,
|
|
870
878
|
{
|
|
871
|
-
points:
|
|
879
|
+
points: Ie,
|
|
872
880
|
xMeasureUnit: h,
|
|
873
881
|
yMeasureUnit: u,
|
|
874
882
|
series: e,
|
|
875
|
-
position:
|
|
883
|
+
position: Be,
|
|
876
884
|
containerRef: B,
|
|
877
885
|
decimals: se
|
|
878
886
|
}
|
|
879
887
|
),
|
|
880
|
-
c && /* @__PURE__ */ _(
|
|
881
|
-
P && P.length > 0 &&
|
|
888
|
+
c && /* @__PURE__ */ _(Wt, { series: e, onUnselect: f }),
|
|
889
|
+
P && P.length > 0 && Ee.length === P.length && /* @__PURE__ */ _(
|
|
882
890
|
"div",
|
|
883
891
|
{
|
|
884
892
|
className: "absolute inset-0 z-[5] pointer-events-none",
|
|
885
893
|
"aria-hidden": !0,
|
|
886
|
-
children: P.map((t,
|
|
887
|
-
const r =
|
|
894
|
+
children: P.map((t, s) => {
|
|
895
|
+
const r = Ee[s], l = t.options ?? {};
|
|
888
896
|
if (r === null) return null;
|
|
889
|
-
const { labelText: a, valueStr:
|
|
890
|
-
|
|
897
|
+
const { labelText: a, valueStr: m } = Ft(
|
|
898
|
+
l,
|
|
891
899
|
u,
|
|
892
900
|
se
|
|
893
|
-
),
|
|
894
|
-
if (!(a ||
|
|
895
|
-
const x =
|
|
901
|
+
), p = l.tooltipText ?? "";
|
|
902
|
+
if (!(a || m || p)) return null;
|
|
903
|
+
const x = l.labelBackgroundColor ?? l.color ?? "hsl(var(--background))", v = l.labelTextColor ?? "hsl(var(--foreground))", X = `${String(t.xCoordinate)}-${a}-${p}`, k = zt(
|
|
896
904
|
r,
|
|
897
|
-
|
|
898
|
-
|
|
905
|
+
tt,
|
|
906
|
+
ot[s]
|
|
899
907
|
);
|
|
900
|
-
return /* @__PURE__ */
|
|
908
|
+
return /* @__PURE__ */ ee(
|
|
901
909
|
"div",
|
|
902
910
|
{
|
|
903
911
|
ref: (O) => {
|
|
904
|
-
|
|
912
|
+
Ae.current.set(s, O);
|
|
905
913
|
},
|
|
906
914
|
className: J(
|
|
907
915
|
"group absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",
|
|
908
|
-
|
|
916
|
+
p && "pointer-events-auto cursor-default"
|
|
909
917
|
),
|
|
910
918
|
style: {
|
|
911
|
-
...
|
|
919
|
+
...k,
|
|
912
920
|
backgroundColor: x,
|
|
913
921
|
color: v
|
|
914
922
|
},
|
|
915
923
|
children: [
|
|
916
924
|
a && /* @__PURE__ */ _("span", { className: "block", children: a }),
|
|
917
|
-
|
|
918
|
-
|
|
925
|
+
m && /* @__PURE__ */ _("span", { className: J("block", a && "mt-0.5"), children: m }),
|
|
926
|
+
p && /* @__PURE__ */ _(
|
|
919
927
|
"span",
|
|
920
928
|
{
|
|
921
929
|
className: "pointer-events-none absolute right-0 top-full z-10 mt-1 hidden w-[280px] whitespace-normal rounded border border-border bg-popover px-2.5 py-1.5 text-left leading-snug text-popover-foreground shadow-md group-hover:block",
|
|
922
930
|
role: "tooltip",
|
|
923
|
-
children:
|
|
931
|
+
children: p
|
|
924
932
|
}
|
|
925
933
|
)
|
|
926
934
|
]
|
|
@@ -933,7 +941,7 @@ function to({
|
|
|
933
941
|
/* @__PURE__ */ _(
|
|
934
942
|
"div",
|
|
935
943
|
{
|
|
936
|
-
ref:
|
|
944
|
+
ref: ve,
|
|
937
945
|
className: "LightweightChart w-full h-full overflow-hidden"
|
|
938
946
|
}
|
|
939
947
|
)
|
|
@@ -941,14 +949,14 @@ function to({
|
|
|
941
949
|
}
|
|
942
950
|
);
|
|
943
951
|
}
|
|
944
|
-
function
|
|
952
|
+
function Wt({
|
|
945
953
|
series: e,
|
|
946
|
-
markers:
|
|
954
|
+
markers: n,
|
|
947
955
|
onUnselect: c,
|
|
948
956
|
inline: f = !1
|
|
949
957
|
}) {
|
|
950
958
|
const h = e.every((u) => u.data.length === 0);
|
|
951
|
-
return /* @__PURE__ */
|
|
959
|
+
return /* @__PURE__ */ ee(
|
|
952
960
|
"div",
|
|
953
961
|
{
|
|
954
962
|
className: J(
|
|
@@ -957,8 +965,8 @@ function At({
|
|
|
957
965
|
),
|
|
958
966
|
children: [
|
|
959
967
|
e.map((u, S) => {
|
|
960
|
-
const P =
|
|
961
|
-
return /* @__PURE__ */
|
|
968
|
+
const P = Oe(S), D = (u.lineColor ?? u.color) || P.line, F = !h && u.data.length === 0;
|
|
969
|
+
return /* @__PURE__ */ ee(
|
|
962
970
|
"div",
|
|
963
971
|
{
|
|
964
972
|
className: J(
|
|
@@ -977,7 +985,7 @@ function At({
|
|
|
977
985
|
style: { backgroundColor: D }
|
|
978
986
|
}
|
|
979
987
|
),
|
|
980
|
-
/* @__PURE__ */
|
|
988
|
+
/* @__PURE__ */ ee(
|
|
981
989
|
"span",
|
|
982
990
|
{
|
|
983
991
|
className: J(
|
|
@@ -999,7 +1007,7 @@ function At({
|
|
|
999
1007
|
},
|
|
1000
1008
|
className: "ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer",
|
|
1001
1009
|
"aria-label": `Remove ${u.label}`,
|
|
1002
|
-
children: /* @__PURE__ */
|
|
1010
|
+
children: /* @__PURE__ */ ee(
|
|
1003
1011
|
"svg",
|
|
1004
1012
|
{
|
|
1005
1013
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -1027,7 +1035,7 @@ function At({
|
|
|
1027
1035
|
u.id ?? u.label
|
|
1028
1036
|
);
|
|
1029
1037
|
}),
|
|
1030
|
-
|
|
1038
|
+
n?.map((u) => /* @__PURE__ */ ee(
|
|
1031
1039
|
"div",
|
|
1032
1040
|
{
|
|
1033
1041
|
className: J(
|
|
@@ -1061,12 +1069,12 @@ function At({
|
|
|
1061
1069
|
);
|
|
1062
1070
|
}
|
|
1063
1071
|
export {
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
+
oo as Graph,
|
|
1073
|
+
Wt as GraphLegend,
|
|
1074
|
+
Ye as VERTICAL_LINE_LABEL_EDGE_PADDING,
|
|
1075
|
+
At as getStepForwardValue,
|
|
1076
|
+
zt as getVerticalLineLabelStyle,
|
|
1077
|
+
Ft as getVerticalLineTooltipContent,
|
|
1078
|
+
ie as seriesIdentity,
|
|
1079
|
+
Vt as visibleLogicalRangeFor
|
|
1072
1080
|
};
|