@tradecanvas/chart 0.4.0 → 0.6.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 +120 -9
- package/dist/Chart-CrrTKx3r.js +1027 -0
- package/dist/Chart-CrrTKx3r.js.map +1 -0
- package/dist/Chart-DoR8L8Uk.cjs +2 -0
- package/dist/Chart-DoR8L8Uk.cjs.map +1 -0
- package/dist/Chart.d.ts +22 -8
- package/dist/Chart.d.ts.map +1 -1
- package/dist/charts/ChartTypeStrategy.d.ts +18 -0
- package/dist/charts/ChartTypeStrategy.d.ts.map +1 -0
- package/dist/charts/IndicatorPriceRange.d.ts +16 -0
- package/dist/charts/IndicatorPriceRange.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -1010
- package/dist/index.js.map +1 -1
- package/dist/state/AutoSaveScheduler.d.ts +26 -0
- package/dist/state/AutoSaveScheduler.d.ts.map +1 -0
- package/dist/widget/ChartWidget.d.ts +43 -0
- package/dist/widget/ChartWidget.d.ts.map +1 -0
- package/dist/widget/WidgetDrawingSidebar.d.ts +19 -0
- package/dist/widget/WidgetDrawingSidebar.d.ts.map +1 -0
- package/dist/widget/WidgetDropdown.d.ts +18 -0
- package/dist/widget/WidgetDropdown.d.ts.map +1 -0
- package/dist/widget/WidgetSettings.d.ts +25 -0
- package/dist/widget/WidgetSettings.d.ts.map +1 -0
- package/dist/widget/WidgetStatusBar.d.ts +15 -0
- package/dist/widget/WidgetStatusBar.d.ts.map +1 -0
- package/dist/widget/WidgetStyles.d.ts +9 -0
- package/dist/widget/WidgetStyles.d.ts.map +1 -0
- package/dist/widget/WidgetToolbar.d.ts +22 -0
- package/dist/widget/WidgetToolbar.d.ts.map +1 -0
- package/dist/widget/icons.d.ts +2 -0
- package/dist/widget/icons.d.ts.map +1 -0
- package/dist/widget/index.cjs +740 -0
- package/dist/widget/index.cjs.map +1 -0
- package/dist/widget/index.d.ts +3 -0
- package/dist/widget/index.d.ts.map +1 -0
- package/dist/widget/index.js +1058 -0
- package/dist/widget/index.js.map +1 -0
- package/dist/widget/types.d.ts +105 -0
- package/dist/widget/types.d.ts.map +1 -0
- package/dist/widget/widgetConfig.d.ts +16 -0
- package/dist/widget/widgetConfig.d.ts.map +1 -0
- package/package.json +14 -4
|
@@ -0,0 +1,1027 @@
|
|
|
1
|
+
import { DARK_THEME as e, DEFAULT_PANEL_HEIGHT as t, LIGHT_THEME as n, LayerType as r, MIN_PANEL_HEIGHT as i, PRICE_AXIS_WIDTH as a, TIME_AXIS_HEIGHT as o, computePriceLimits as s, mergeBar as c, setLocale as l, timeframeToMs as u } from "@tradecanvas/commons";
|
|
2
|
+
import { AlertManager as d, Animator as f, AreaRenderer as p, BarCountdown as m, BarRenderer as ee, BaselineRenderer as h, CandlestickRenderer as g, ChartLegend as te, ChartStateManager as _, CompareRenderer as v, CrosshairHandler as y, CrosshairTooltip as ne, CurrentPriceLine as re, DataExporter as b, DrawingManager as ie, DrawingRenderer as ae, EventBus as oe, GridRenderer as se, HollowCandleRenderer as ce, IndicatorEngine as x, InteractionManager as le, KagiRenderer as ue, KeyboardHandler as de, LineRenderer as S, PanHandler as C, PointAndFigureRenderer as w, PriceAxis as T, RenderEngine as E, RenkoRenderer as D, ReplayManager as O, Screenshot as k, SessionBreaks as A, StreamManager as j, TimeAxis as M, TradingManager as N, TradingRenderer as P, UndoRedoManager as F, Viewport as I, VolumeRenderer as L, Watermark as R, ZoomHandler as z, registerBuiltInDrawingTools as B, registerBuiltInIndicators as V, toHeikinAshi as H, toKagi as fe, toLineBreak as pe, toPointAndFigure as me, toRangeBars as he, toRenko as ge } from "@tradecanvas/core";
|
|
3
|
+
//#region src/charts/ChartTypeStrategy.ts
|
|
4
|
+
function _e(e) {
|
|
5
|
+
switch (e) {
|
|
6
|
+
case "candlestick":
|
|
7
|
+
case "heikinAshi":
|
|
8
|
+
case "lineBreak":
|
|
9
|
+
case "rangeBars": return new g();
|
|
10
|
+
case "line": return new S();
|
|
11
|
+
case "area": return new p();
|
|
12
|
+
case "bar": return new ee();
|
|
13
|
+
case "hollowCandle": return new ce();
|
|
14
|
+
case "baseline": return new h();
|
|
15
|
+
case "renko": return new D();
|
|
16
|
+
case "kagi": return new ue();
|
|
17
|
+
case "pointAndFigure": return new w();
|
|
18
|
+
default: return new g();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function ve(e, t) {
|
|
22
|
+
if (t.length === 0) return t;
|
|
23
|
+
switch (e) {
|
|
24
|
+
case "heikinAshi": return H(t);
|
|
25
|
+
case "renko": return ge(t, {
|
|
26
|
+
brickSize: 0,
|
|
27
|
+
useATR: !0,
|
|
28
|
+
atrPeriod: 14
|
|
29
|
+
});
|
|
30
|
+
case "lineBreak": return pe(t, 3);
|
|
31
|
+
case "kagi": return fe(t, 4);
|
|
32
|
+
case "pointAndFigure": return me(t, U(t) * .01, 3);
|
|
33
|
+
case "rangeBars": return he(t, { rangeSize: U(t) * .005 });
|
|
34
|
+
default: return t;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function U(e) {
|
|
38
|
+
let t = 0;
|
|
39
|
+
for (let n of e) t += n.close;
|
|
40
|
+
return t / e.length;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/charts/IndicatorPriceRange.ts
|
|
44
|
+
var W = {
|
|
45
|
+
min: 0,
|
|
46
|
+
max: 100
|
|
47
|
+
}, G = .1;
|
|
48
|
+
function ye(e, t, n) {
|
|
49
|
+
if (!e) return { ...W };
|
|
50
|
+
let r = Infinity, i = -Infinity, a = 0;
|
|
51
|
+
for (let [, o] of e.values) {
|
|
52
|
+
if (a >= t && a <= n) for (let e in o) {
|
|
53
|
+
let t = o[e];
|
|
54
|
+
t !== void 0 && Number.isFinite(t) && (t < r && (r = t), t > i && (i = t));
|
|
55
|
+
}
|
|
56
|
+
a++;
|
|
57
|
+
}
|
|
58
|
+
if (r === Infinity) return { ...W };
|
|
59
|
+
let o = i - r || 1;
|
|
60
|
+
return {
|
|
61
|
+
min: r - o * G,
|
|
62
|
+
max: i + o * G
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/state/AutoSaveScheduler.ts
|
|
67
|
+
var be = class {
|
|
68
|
+
timer = null;
|
|
69
|
+
delayMs = 0;
|
|
70
|
+
key = null;
|
|
71
|
+
constructor(e) {
|
|
72
|
+
this.save = e;
|
|
73
|
+
}
|
|
74
|
+
enable(e, t) {
|
|
75
|
+
this.key = e, this.delayMs = t;
|
|
76
|
+
}
|
|
77
|
+
disable() {
|
|
78
|
+
this.key = null, this.delayMs = 0, this.cancel();
|
|
79
|
+
}
|
|
80
|
+
schedule() {
|
|
81
|
+
this.delayMs <= 0 || !this.key || (this.timer && clearTimeout(this.timer), this.timer = setTimeout(() => {
|
|
82
|
+
this.timer = null, this.key && this.save(this.key);
|
|
83
|
+
}, this.delayMs));
|
|
84
|
+
}
|
|
85
|
+
cancel() {
|
|
86
|
+
this.timer &&= (clearTimeout(this.timer), null);
|
|
87
|
+
}
|
|
88
|
+
isEnabled() {
|
|
89
|
+
return this.delayMs > 0 && this.key !== null;
|
|
90
|
+
}
|
|
91
|
+
hasPending() {
|
|
92
|
+
return this.timer !== null;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/DataManager.ts
|
|
97
|
+
function K(e) {
|
|
98
|
+
if (!e || typeof e.time != "number") return !1;
|
|
99
|
+
let { open: t, high: n, low: r, close: i } = e;
|
|
100
|
+
return !(!isFinite(t) || !isFinite(n) || !isFinite(r) || !isFinite(i) || t < 0 || n < 0 || r < 0 || i < 0 || n < r || e.volume !== void 0 && (!isFinite(e.volume) || e.volume < 0));
|
|
101
|
+
}
|
|
102
|
+
function q(e) {
|
|
103
|
+
return {
|
|
104
|
+
...e,
|
|
105
|
+
high: Math.max(e.open, e.high, e.low, e.close),
|
|
106
|
+
low: Math.min(e.open, e.high, e.low, e.close),
|
|
107
|
+
volume: e.volume === void 0 ? 0 : Math.max(0, e.volume)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
var J = class {
|
|
111
|
+
data = [];
|
|
112
|
+
getData() {
|
|
113
|
+
return this.data;
|
|
114
|
+
}
|
|
115
|
+
setData(e) {
|
|
116
|
+
this.data = e.filter(K).map(q);
|
|
117
|
+
}
|
|
118
|
+
appendBar(e) {
|
|
119
|
+
K(e) && this.data.push(q(e));
|
|
120
|
+
}
|
|
121
|
+
updateLastBar(e) {
|
|
122
|
+
if (!K(e)) return;
|
|
123
|
+
let t = q(e);
|
|
124
|
+
if (this.data.length === 0) {
|
|
125
|
+
this.data.push(t);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.data[this.data.length - 1] = t;
|
|
129
|
+
}
|
|
130
|
+
updateLastBarFromTick(e) {
|
|
131
|
+
this.data.length !== 0 && (!isFinite(e.price) || e.price < 0 || e.volume !== void 0 && (!isFinite(e.volume) || e.volume < 0) || (this.data[this.data.length - 1] = c(this.data[this.data.length - 1], e)));
|
|
132
|
+
}
|
|
133
|
+
getLength() {
|
|
134
|
+
return this.data.length;
|
|
135
|
+
}
|
|
136
|
+
clear() {
|
|
137
|
+
this.data = [];
|
|
138
|
+
}
|
|
139
|
+
}, Y = class {
|
|
140
|
+
theme;
|
|
141
|
+
constructor(t) {
|
|
142
|
+
!t || t === "dark" ? this.theme = { ...e } : t === "light" ? this.theme = { ...n } : this.theme = { ...t };
|
|
143
|
+
}
|
|
144
|
+
getTheme() {
|
|
145
|
+
return this.theme;
|
|
146
|
+
}
|
|
147
|
+
setTheme(t) {
|
|
148
|
+
t === "dark" ? this.theme = { ...e } : t === "light" ? this.theme = { ...n } : this.theme = { ...t };
|
|
149
|
+
}
|
|
150
|
+
}, X = 200, Z = 80, Q = class {
|
|
151
|
+
panels = [];
|
|
152
|
+
containerWidth = 0;
|
|
153
|
+
containerHeight = 0;
|
|
154
|
+
resize(e, t) {
|
|
155
|
+
this.containerWidth = e, this.containerHeight = t;
|
|
156
|
+
}
|
|
157
|
+
addPanel(e, n = "bottom", r) {
|
|
158
|
+
let a = n === "left" || n === "right";
|
|
159
|
+
this.panels.push({
|
|
160
|
+
id: e,
|
|
161
|
+
position: n,
|
|
162
|
+
size: r ?? (a ? X : t),
|
|
163
|
+
minSize: a ? Z : i,
|
|
164
|
+
content: {
|
|
165
|
+
type: "indicator",
|
|
166
|
+
indicatorInstanceId: e
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
removePanel(e) {
|
|
171
|
+
this.panels = this.panels.filter((t) => t.id !== e);
|
|
172
|
+
}
|
|
173
|
+
setPanelPosition(e, n) {
|
|
174
|
+
let r = this.panels.find((t) => t.id === e);
|
|
175
|
+
if (r) {
|
|
176
|
+
let e = r.position === "left" || r.position === "right", a = n === "left" || n === "right";
|
|
177
|
+
r.position = n, e !== a && (r.size = a ? X : t, r.minSize = a ? Z : i);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
setPanelSize(e, t) {
|
|
181
|
+
let n = this.panels.find((t) => t.id === e);
|
|
182
|
+
n && (n.size = Math.max(n.minSize, t));
|
|
183
|
+
}
|
|
184
|
+
getPanels() {
|
|
185
|
+
return this.panels;
|
|
186
|
+
}
|
|
187
|
+
resolve() {
|
|
188
|
+
let e = this.panels.filter((e) => e.position === "left"), t = this.panels.filter((e) => e.position === "right"), n = this.panels.filter((e) => e.position === "top"), r = this.panels.filter((e) => e.position === "bottom"), i = e.reduce((e, t) => e + t.size, 0), s = t.reduce((e, t) => e + t.size, 0), c = n.reduce((e, t) => e + t.size, 0), l = r.reduce((e, t) => e + t.size, 0), u = {
|
|
189
|
+
x: i,
|
|
190
|
+
y: c,
|
|
191
|
+
width: Math.max(0, this.containerWidth - i - s - a),
|
|
192
|
+
height: Math.max(0, this.containerHeight - c - l - o)
|
|
193
|
+
}, d = [], f = [], p = 0;
|
|
194
|
+
for (let t of e) d.push({
|
|
195
|
+
config: t,
|
|
196
|
+
rect: {
|
|
197
|
+
x: p,
|
|
198
|
+
y: 0,
|
|
199
|
+
width: t.size,
|
|
200
|
+
height: this.containerHeight - o
|
|
201
|
+
}
|
|
202
|
+
}), f.push({
|
|
203
|
+
panelId: t.id,
|
|
204
|
+
rect: {
|
|
205
|
+
x: p + t.size - 2,
|
|
206
|
+
y: 0,
|
|
207
|
+
width: 4,
|
|
208
|
+
height: this.containerHeight
|
|
209
|
+
},
|
|
210
|
+
orientation: "vertical"
|
|
211
|
+
}), p += t.size;
|
|
212
|
+
let m = 0;
|
|
213
|
+
for (let e of n) d.push({
|
|
214
|
+
config: e,
|
|
215
|
+
rect: {
|
|
216
|
+
x: i,
|
|
217
|
+
y: m,
|
|
218
|
+
width: u.width,
|
|
219
|
+
height: e.size
|
|
220
|
+
}
|
|
221
|
+
}), f.push({
|
|
222
|
+
panelId: e.id,
|
|
223
|
+
rect: {
|
|
224
|
+
x: i,
|
|
225
|
+
y: m + e.size - 2,
|
|
226
|
+
width: u.width,
|
|
227
|
+
height: 4
|
|
228
|
+
},
|
|
229
|
+
orientation: "horizontal"
|
|
230
|
+
}), m += e.size;
|
|
231
|
+
m = u.y + u.height;
|
|
232
|
+
for (let e of r) d.push({
|
|
233
|
+
config: e,
|
|
234
|
+
rect: {
|
|
235
|
+
x: i,
|
|
236
|
+
y: m,
|
|
237
|
+
width: u.width,
|
|
238
|
+
height: e.size
|
|
239
|
+
}
|
|
240
|
+
}), f.push({
|
|
241
|
+
panelId: e.id,
|
|
242
|
+
rect: {
|
|
243
|
+
x: i,
|
|
244
|
+
y: m - 2,
|
|
245
|
+
width: u.width,
|
|
246
|
+
height: 4
|
|
247
|
+
},
|
|
248
|
+
orientation: "horizontal"
|
|
249
|
+
}), m += e.size;
|
|
250
|
+
p = i + u.width + a;
|
|
251
|
+
for (let e of t) d.push({
|
|
252
|
+
config: e,
|
|
253
|
+
rect: {
|
|
254
|
+
x: p,
|
|
255
|
+
y: 0,
|
|
256
|
+
width: e.size,
|
|
257
|
+
height: this.containerHeight - o
|
|
258
|
+
}
|
|
259
|
+
}), f.push({
|
|
260
|
+
panelId: e.id,
|
|
261
|
+
rect: {
|
|
262
|
+
x: p - 2,
|
|
263
|
+
y: 0,
|
|
264
|
+
width: 4,
|
|
265
|
+
height: this.containerHeight
|
|
266
|
+
},
|
|
267
|
+
orientation: "vertical"
|
|
268
|
+
}), p += e.size;
|
|
269
|
+
return {
|
|
270
|
+
mainChartRect: u,
|
|
271
|
+
panels: d,
|
|
272
|
+
dividers: f
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
getMainChartRect() {
|
|
276
|
+
return this.resolve().mainChartRect;
|
|
277
|
+
}
|
|
278
|
+
}, $ = class {
|
|
279
|
+
constructor(e) {
|
|
280
|
+
this.indicatorEngine = e;
|
|
281
|
+
}
|
|
282
|
+
registerIndicator(e) {
|
|
283
|
+
this.indicatorEngine.register(e);
|
|
284
|
+
}
|
|
285
|
+
}, xe = class {
|
|
286
|
+
static version = "0.3.0";
|
|
287
|
+
engine;
|
|
288
|
+
viewport;
|
|
289
|
+
dataManager;
|
|
290
|
+
themeManager;
|
|
291
|
+
layoutManager;
|
|
292
|
+
pluginManager;
|
|
293
|
+
indicatorEngine;
|
|
294
|
+
drawingManager;
|
|
295
|
+
drawingRenderer;
|
|
296
|
+
tradingManager;
|
|
297
|
+
tradingRenderer;
|
|
298
|
+
eventBus;
|
|
299
|
+
streamManager = null;
|
|
300
|
+
autoScrollOnNewBar = !0;
|
|
301
|
+
displayDataCache = null;
|
|
302
|
+
resolvedLayoutCache = null;
|
|
303
|
+
panelInfoCache = null;
|
|
304
|
+
renderScheduled = !1;
|
|
305
|
+
containerSizeCache = null;
|
|
306
|
+
containerSizeCacheTime = 0;
|
|
307
|
+
chartLegend;
|
|
308
|
+
watermark;
|
|
309
|
+
barCountdown;
|
|
310
|
+
sessionBreaks;
|
|
311
|
+
compareRenderer;
|
|
312
|
+
countdownInterval = null;
|
|
313
|
+
volumeRenderer;
|
|
314
|
+
alertManager;
|
|
315
|
+
replayManager;
|
|
316
|
+
undoRedoManager;
|
|
317
|
+
autoSaveScheduler = new be((e) => this.saveState(e));
|
|
318
|
+
animator;
|
|
319
|
+
crosshairTooltip;
|
|
320
|
+
interactionManager;
|
|
321
|
+
crosshairHandler;
|
|
322
|
+
chartRenderer;
|
|
323
|
+
gridRenderer;
|
|
324
|
+
priceAxis;
|
|
325
|
+
timeAxis;
|
|
326
|
+
options;
|
|
327
|
+
features;
|
|
328
|
+
marketConfig = null;
|
|
329
|
+
container;
|
|
330
|
+
currentPriceLine;
|
|
331
|
+
numberLocale;
|
|
332
|
+
keyboardHandler = null;
|
|
333
|
+
onWindowKeyDown = null;
|
|
334
|
+
currentSymbol = "";
|
|
335
|
+
constructor(e, t) {
|
|
336
|
+
this.container = e, this.options = t, this.numberLocale = t.numberLocale ?? "en-US";
|
|
337
|
+
let n = t.features ?? {};
|
|
338
|
+
this.features = {
|
|
339
|
+
drawings: n.drawings ?? !0,
|
|
340
|
+
drawingTools: n.drawingTools ?? [],
|
|
341
|
+
drawingMagnet: n.drawingMagnet ?? !0,
|
|
342
|
+
drawingUndoRedo: n.drawingUndoRedo ?? !0,
|
|
343
|
+
trading: n.trading ?? !0,
|
|
344
|
+
tradingContextMenu: n.tradingContextMenu ?? !0,
|
|
345
|
+
indicators: n.indicators ?? !0,
|
|
346
|
+
indicatorIds: n.indicatorIds ?? [],
|
|
347
|
+
panning: n.panning ?? !0,
|
|
348
|
+
zooming: n.zooming ?? !0,
|
|
349
|
+
crosshair: n.crosshair ?? !0,
|
|
350
|
+
keyboard: n.keyboard ?? !0,
|
|
351
|
+
priceAxis: n.priceAxis ?? !0,
|
|
352
|
+
timeAxis: n.timeAxis ?? !0,
|
|
353
|
+
grid: n.grid ?? t.grid?.visible ?? !0,
|
|
354
|
+
legend: n.legend ?? !0,
|
|
355
|
+
volume: n.volume ?? !0,
|
|
356
|
+
watermark: n.watermark ?? !0,
|
|
357
|
+
saveLoad: n.saveLoad ?? !0,
|
|
358
|
+
screenshot: n.screenshot ?? !0,
|
|
359
|
+
alerts: n.alerts ?? !0,
|
|
360
|
+
replay: n.replay ?? !0,
|
|
361
|
+
sessionBreaks: n.sessionBreaks ?? !0,
|
|
362
|
+
barCountdown: n.barCountdown ?? !0,
|
|
363
|
+
compareSymbols: n.compareSymbols ?? !0,
|
|
364
|
+
dataExport: n.dataExport ?? !0,
|
|
365
|
+
logScale: n.logScale ?? !0,
|
|
366
|
+
timeframes: n.timeframes ?? [],
|
|
367
|
+
defaultTimeframeFavorites: n.defaultTimeframeFavorites ?? []
|
|
368
|
+
}, e.style.position = "relative", e.style.overflow = "hidden", e.tabIndex = 0, e.style.outline = "none", this.dataManager = new J(), this.themeManager = new Y(t.theme), this.layoutManager = new Q(), this.indicatorEngine = new x(), this.pluginManager = new $(this.indicatorEngine), this.eventBus = new oe(), V(this.indicatorEngine), this.drawingManager = new ie(), B(this.drawingManager), this.drawingRenderer = new ae(this.drawingManager), this.drawingManager.setRequestRender(() => {
|
|
369
|
+
this.syncRenderContext(), this.engine.requestRender(r.Overlay), this.scheduleAutoSave();
|
|
370
|
+
}), this.drawingManager.setEventCallback((e, t) => {
|
|
371
|
+
this.eventBus.emit(e, t);
|
|
372
|
+
}), this.undoRedoManager = new F(), this.drawingManager.setUndoRedoManager(this.undoRedoManager), this.drawingManager.setDataGetter(() => this.dataManager.getData()), this.drawingManager.setDisplayDataGetter(() => this.getDisplayData()), t.crosshair?.mode === "magnet" && this.drawingManager.setMagnetMode("magnet"), this.tradingManager = new N(), this.tradingRenderer = new P(this.tradingManager), this.tradingManager.setContainer(e), this.tradingManager.setRequestRender(() => this.engine.requestRender(r.Overlay)), this.tradingManager.setEventCallback((e, t) => {
|
|
373
|
+
this.eventBus.emit(e, t);
|
|
374
|
+
}), this.engine = new E(e);
|
|
375
|
+
let i = this.engine.dprManager.getContainerSize();
|
|
376
|
+
this.viewport = new I(i.width, i.height, t.minBarSpacing ?? 2, t.maxBarSpacing ?? 30, t.rightMargin ?? 5), this.layoutManager.resize(i.width, i.height), this.engine.onContainerResize = (e) => {
|
|
377
|
+
if (e.width <= 0 || e.height <= 0) return;
|
|
378
|
+
let t = this.viewport.isAtEnd();
|
|
379
|
+
this.viewport.resize(e.width, e.height), this.layoutManager.resize(e.width, e.height), this.updateViewportAndRender(t);
|
|
380
|
+
}, this.chartRenderer = this.createChartRenderer(t.chartType), this.gridRenderer = new se(), t.grid?.visible === !1 && this.gridRenderer.setVisible(!1), this.priceAxis = new T(), this.priceAxis.setLocale(this.numberLocale), this.timeAxis = new M(), this.crosshairHandler = new y(), this.crosshairHandler.setLocale(this.numberLocale), t.crosshair?.mode && this.crosshairHandler.setMode(t.crosshair.mode), this.crosshairHandler.setCallback((e, t) => {
|
|
381
|
+
if (e !== null && t) {
|
|
382
|
+
let n = this.dataManager.getData(), r = e < n.length ? n[e] : void 0;
|
|
383
|
+
this.chartLegend.setHoverBar(r ?? null), r && this.crosshairTooltip.show(t, r, this.themeManager.getTheme(), this.cachedContainerSize()), this.eventBus.emit("crosshairMove", {
|
|
384
|
+
point: t,
|
|
385
|
+
bar: r,
|
|
386
|
+
barIndex: e
|
|
387
|
+
});
|
|
388
|
+
} else this.crosshairTooltip.hide(), this.chartLegend.setHoverBar(null);
|
|
389
|
+
}), this.chartLegend = new te(), this.chartLegend.setChartType(t.chartType), this.watermark = new R(), t.watermark && this.watermark.setConfig(t.watermark), this.volumeRenderer = new L(), this.barCountdown = new m(), this.sessionBreaks = new A(), this.compareRenderer = new v(), t.sessionBreaks ? this.sessionBreaks.setConfig({
|
|
390
|
+
visible: t.sessionBreaks.visible ?? !0,
|
|
391
|
+
color: t.sessionBreaks.color,
|
|
392
|
+
lineStyle: t.sessionBreaks.lineStyle,
|
|
393
|
+
lineWidth: t.sessionBreaks.lineWidth
|
|
394
|
+
}) : t.features?.sessionBreaks !== !1 && this.sessionBreaks.setVisible(!0), t.logScale && this.viewport.setLogScale(!0), this.animator = new f(), this.crosshairTooltip = new ne(), this.crosshairTooltip.create(e), this.keyboardHandler = new de({
|
|
395
|
+
scrollBars: (e) => {
|
|
396
|
+
let t = this.viewport.getState().barWidth + this.viewport.getState().barSpacing;
|
|
397
|
+
this.viewport.scrollBy(e * t), this.updateViewportAndRender();
|
|
398
|
+
},
|
|
399
|
+
zoom: (e) => {
|
|
400
|
+
let t = this.viewport.getState().chartRect.width;
|
|
401
|
+
this.viewport.zoom(e, t / 2), this.updateViewportAndRender();
|
|
402
|
+
},
|
|
403
|
+
goToStart: () => {
|
|
404
|
+
this.viewport.scrollBy(-Infinity), this.updateViewportAndRender();
|
|
405
|
+
},
|
|
406
|
+
goToEnd: () => {
|
|
407
|
+
this.viewport.scrollToEnd(), this.updateViewportAndRender();
|
|
408
|
+
},
|
|
409
|
+
fitContent: () => this.fitContent()
|
|
410
|
+
}), this.keyboardHandler.setEnabled(this.features.keyboard), this.onWindowKeyDown = (e) => {
|
|
411
|
+
if (!this.keyboardHandler) return;
|
|
412
|
+
let t = document.activeElement;
|
|
413
|
+
t && t !== this.container && !this.container.contains(t) || t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.isContentEditable) || this.keyboardHandler.handleKey(e) && e.preventDefault();
|
|
414
|
+
}, window.addEventListener("keydown", this.onWindowKeyDown), this.currentPriceLine = new re(), this.alertManager = new d(), this.alertManager.setRequestRender(() => this.engine.requestRender(r.Overlay)), this.alertManager.on("triggered", (e) => {
|
|
415
|
+
this.eventBus.emit("dataUpdate", {
|
|
416
|
+
alert: "triggered",
|
|
417
|
+
alertId: e.id,
|
|
418
|
+
price: e.price,
|
|
419
|
+
message: e.message
|
|
420
|
+
});
|
|
421
|
+
}), this.replayManager = new O(), this.interactionManager = new le(e), this.features.panning && this.interactionManager.setPanHandler(new C((e) => {
|
|
422
|
+
this.viewport.scrollBy(e), this.updateViewportAndRender();
|
|
423
|
+
})), this.features.zooming && this.interactionManager.setZoomHandler(new z((e, t) => {
|
|
424
|
+
this.viewport.zoom(e, t), this.updateViewportAndRender();
|
|
425
|
+
})), this.features.crosshair && this.interactionManager.setCrosshairHandler(this.crosshairHandler), this.features.drawings && this.interactionManager.setDrawingManager(this.drawingManager, () => this.viewport.getState()), this.features.trading && this.interactionManager.setTradingManager(this.tradingManager, () => this.viewport.getState()), this.interactionManager.setOverlayDirtyCallback(() => {
|
|
426
|
+
this.engine.requestRender(r.Overlay), this.layoutManager.getPanels().length > 0 && this.engine.requestRender(r.UI);
|
|
427
|
+
}), this.interactionManager.attach(), this.syncRenderContext(), this.engine.start();
|
|
428
|
+
}
|
|
429
|
+
setData(e) {
|
|
430
|
+
this.dataManager.setData(e), this.crosshairHandler.setData(this.dataManager.getData()), this.displayDataCache = null, this.sessionBreaks.invalidateCache(), this.indicatorEngine.recalculateAll(this.dataManager.getData()), e.length > 0 && this.currentPriceLine.setPrice(e[e.length - 1].close), this.updateViewportAndRender(!0), this.eventBus.emit("dataUpdate", { length: e.length });
|
|
431
|
+
}
|
|
432
|
+
appendBar(e) {
|
|
433
|
+
this.dataManager.appendBar(e), this.crosshairHandler.setData(this.dataManager.getData()), this.displayDataCache = null, this.autoScrollOnNewBar && this.viewport.scrollToEnd(), this.indicatorEngine.recalculateAll(this.dataManager.getData()), this.updateViewportAndRender();
|
|
434
|
+
}
|
|
435
|
+
appendBars(e) {
|
|
436
|
+
if (e.length !== 0) {
|
|
437
|
+
for (let t of e) this.dataManager.appendBar(t);
|
|
438
|
+
this.displayDataCache = null, this.indicatorEngine.recalculateAll(this.dataManager.getData()), this.crosshairHandler.setData(this.dataManager.getData()), this.updateViewportAndRender(this.viewport.isAtEnd());
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
updateLastBar(e) {
|
|
442
|
+
this.dataManager.updateLastBar(e), this.currentPriceLine.setPrice(e.close), this.options.chartType !== "candlestick" && this.options.chartType !== "line" && this.options.chartType !== "area" && this.options.chartType !== "bar" && this.options.chartType !== "hollowCandle" && (this.displayDataCache = null), this.indicatorEngine.recalculateAll(this.dataManager.getData()), this.scheduleRender();
|
|
443
|
+
}
|
|
444
|
+
updateLastBarFromTick(e) {
|
|
445
|
+
this.dataManager.updateLastBarFromTick(e), this.currentPriceLine.setPrice(e.price), this.options.chartType !== "candlestick" && this.options.chartType !== "line" && this.options.chartType !== "area" && this.options.chartType !== "bar" && this.options.chartType !== "hollowCandle" && (this.displayDataCache = null), this.indicatorEngine.recalculateAll(this.dataManager.getData()), this.scheduleRender();
|
|
446
|
+
}
|
|
447
|
+
setChartType(e) {
|
|
448
|
+
this.options.chartType = e, this.chartRenderer = this.createChartRenderer(e), this.chartLegend.setChartType(e), this.displayDataCache = null, this.updateViewportAndRender(!0);
|
|
449
|
+
}
|
|
450
|
+
addIndicator(e, t = {}, n = "bottom") {
|
|
451
|
+
if (!this.features.indicators || this.features.indicatorIds.length > 0 && !this.features.indicatorIds.includes(e)) return null;
|
|
452
|
+
let r = this.indicatorEngine.addIndicator(e, t, this.dataManager.getData());
|
|
453
|
+
return this.indicatorEngine.getAvailableIndicators().find((t) => t.id === e)?.placement === "panel" ? (this.layoutManager.addPanel(r, n), this.updateViewportAndRender()) : this.engine.requestRender(), this.eventBus.emit("indicatorAdd", {
|
|
454
|
+
instanceId: r,
|
|
455
|
+
id: e
|
|
456
|
+
}), r;
|
|
457
|
+
}
|
|
458
|
+
updateIndicator(e, t) {
|
|
459
|
+
this.indicatorEngine.updateIndicator(e, t, this.dataManager.getData()), this.engine.requestRender();
|
|
460
|
+
}
|
|
461
|
+
removeIndicator(e) {
|
|
462
|
+
let t = this.layoutManager.getPanels().some((t) => t.id === e);
|
|
463
|
+
this.indicatorEngine.removeIndicator(e), this.layoutManager.removePanel(e), this.eventBus.emit("indicatorRemove", { instanceId: e }), t ? this.updateViewportAndRender() : this.engine.requestRender();
|
|
464
|
+
}
|
|
465
|
+
getIndicatorOutput(e) {
|
|
466
|
+
return this.indicatorEngine.getOutput(e);
|
|
467
|
+
}
|
|
468
|
+
registerIndicator(e) {
|
|
469
|
+
this.pluginManager.registerIndicator(e);
|
|
470
|
+
}
|
|
471
|
+
static indicators() {
|
|
472
|
+
let e = new x();
|
|
473
|
+
return V(e), e.getAvailableIndicators();
|
|
474
|
+
}
|
|
475
|
+
setPanelPosition(e, t) {
|
|
476
|
+
this.layoutManager.setPanelPosition(e, t), this.engine.requestRender();
|
|
477
|
+
}
|
|
478
|
+
setPanelSize(e, t) {
|
|
479
|
+
this.layoutManager.setPanelSize(e, t), this.engine.requestRender();
|
|
480
|
+
}
|
|
481
|
+
setDrawingTool(e) {
|
|
482
|
+
this.features.drawings && (e && this.features.drawingTools.length > 0 && !this.features.drawingTools.includes(e) || this.drawingManager.setActiveTool(e));
|
|
483
|
+
}
|
|
484
|
+
getDrawingTool() {
|
|
485
|
+
return this.drawingManager.getActiveTool();
|
|
486
|
+
}
|
|
487
|
+
setDrawingStyle(e) {
|
|
488
|
+
this.drawingManager.setStyle(e);
|
|
489
|
+
}
|
|
490
|
+
getDrawings() {
|
|
491
|
+
return this.drawingManager.getDrawings();
|
|
492
|
+
}
|
|
493
|
+
setDrawings(e) {
|
|
494
|
+
this.drawingManager.setDrawings(e);
|
|
495
|
+
}
|
|
496
|
+
removeDrawing(e) {
|
|
497
|
+
this.drawingManager.removeDrawing(e);
|
|
498
|
+
}
|
|
499
|
+
clearDrawings() {
|
|
500
|
+
this.drawingManager.clearDrawings();
|
|
501
|
+
}
|
|
502
|
+
registerDrawingTool(e) {
|
|
503
|
+
this.drawingManager.register(e);
|
|
504
|
+
}
|
|
505
|
+
undo() {
|
|
506
|
+
return this.features.drawingUndoRedo ? this.drawingManager.undo() : !1;
|
|
507
|
+
}
|
|
508
|
+
redo() {
|
|
509
|
+
return this.features.drawingUndoRedo ? this.drawingManager.redo() : !1;
|
|
510
|
+
}
|
|
511
|
+
getUndoRedoState() {
|
|
512
|
+
return this.undoRedoManager.getState();
|
|
513
|
+
}
|
|
514
|
+
setDrawingMagnet(e) {
|
|
515
|
+
this.drawingManager.setMagnetMode(e ? "magnet" : "none");
|
|
516
|
+
}
|
|
517
|
+
getDrawingMagnet() {
|
|
518
|
+
return this.drawingManager.getMagnetMode() === "magnet";
|
|
519
|
+
}
|
|
520
|
+
lockAllDrawings() {
|
|
521
|
+
this.drawingManager.lockAllDrawings();
|
|
522
|
+
}
|
|
523
|
+
unlockAllDrawings() {
|
|
524
|
+
this.drawingManager.unlockAllDrawings();
|
|
525
|
+
}
|
|
526
|
+
hideAllDrawings() {
|
|
527
|
+
this.drawingManager.hideAllDrawings();
|
|
528
|
+
}
|
|
529
|
+
showAllDrawings() {
|
|
530
|
+
this.drawingManager.showAllDrawings();
|
|
531
|
+
}
|
|
532
|
+
duplicateDrawing(e) {
|
|
533
|
+
let t = e ?? this.drawingManager.getSelectedDrawingId();
|
|
534
|
+
return t ? this.drawingManager.duplicateDrawing(t) : null;
|
|
535
|
+
}
|
|
536
|
+
exportVisibleData(e = "csv", t) {
|
|
537
|
+
let n = this.viewport.getState(), r = this.dataManager.getData(), i = Math.max(0, n.visibleRange.from), a = Math.min(r.length - 1, n.visibleRange.to), o = r.slice(i, a + 1);
|
|
538
|
+
if (e === "json") {
|
|
539
|
+
let e = b.toJSON(o);
|
|
540
|
+
b.download(e, t ?? "chart-data.json", "application/json");
|
|
541
|
+
} else {
|
|
542
|
+
let e = b.toCSV(o);
|
|
543
|
+
b.download(e, t ?? "chart-data.csv", "text/csv");
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
exportAllData(e = "csv", t) {
|
|
547
|
+
let n = this.dataManager.getData();
|
|
548
|
+
if (e === "json") {
|
|
549
|
+
let e = b.toJSON(n);
|
|
550
|
+
b.download(e, t ?? "chart-data.json", "application/json");
|
|
551
|
+
} else {
|
|
552
|
+
let e = b.toCSV(n);
|
|
553
|
+
b.download(e, t ?? "chart-data.csv", "text/csv");
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
setAutoSave(e, t = 5e3) {
|
|
557
|
+
this.autoSaveScheduler.enable(e, t);
|
|
558
|
+
}
|
|
559
|
+
disableAutoSave() {
|
|
560
|
+
this.autoSaveScheduler.disable();
|
|
561
|
+
}
|
|
562
|
+
scheduleAutoSave() {
|
|
563
|
+
this.autoSaveScheduler.schedule();
|
|
564
|
+
}
|
|
565
|
+
getAvailableIndicators() {
|
|
566
|
+
return this.indicatorEngine.getAvailableIndicators();
|
|
567
|
+
}
|
|
568
|
+
getIndicatorInputs(e) {
|
|
569
|
+
let t = this.indicatorEngine.getAvailableIndicators().find((t) => t.id === e);
|
|
570
|
+
return t ? {
|
|
571
|
+
id: t.id,
|
|
572
|
+
params: t.defaultConfig
|
|
573
|
+
} : null;
|
|
574
|
+
}
|
|
575
|
+
getActiveIndicators() {
|
|
576
|
+
return this.indicatorEngine.getActiveIndicators();
|
|
577
|
+
}
|
|
578
|
+
getIndicatorConfig(e) {
|
|
579
|
+
let t = this.indicatorEngine.getIndicatorConfig(e);
|
|
580
|
+
return t ? {
|
|
581
|
+
id: t.id,
|
|
582
|
+
params: { ...t.params }
|
|
583
|
+
} : null;
|
|
584
|
+
}
|
|
585
|
+
updateIndicatorStyle(e, t) {
|
|
586
|
+
this.indicatorEngine.updateIndicatorStyle(e, t), this.engine.requestRender();
|
|
587
|
+
}
|
|
588
|
+
setOrders(e) {
|
|
589
|
+
this.features.trading && this.tradingManager.setOrders(e);
|
|
590
|
+
}
|
|
591
|
+
setPositions(e) {
|
|
592
|
+
this.features.trading && this.tradingManager.setPositions(e);
|
|
593
|
+
}
|
|
594
|
+
setDepthData(e) {
|
|
595
|
+
this.features.trading && this.tradingManager.setDepthData(e);
|
|
596
|
+
}
|
|
597
|
+
setCurrentPrice(e, t) {
|
|
598
|
+
this.tradingManager.setCurrentPrice(e), this.currentPriceLine.setPrice(e), this.scheduleRender(), this.features.alerts && this.alertManager.checkPrice(e);
|
|
599
|
+
}
|
|
600
|
+
setTradingConfig(e) {
|
|
601
|
+
this.features.trading && this.tradingManager.setConfig(e);
|
|
602
|
+
}
|
|
603
|
+
async connect(e) {
|
|
604
|
+
this.disconnectStream(), this.streamManager = new j(), this.streamManager.on("snapshot", (e) => {
|
|
605
|
+
this.setData(e);
|
|
606
|
+
}), this.streamManager.on("barClose", (e) => {
|
|
607
|
+
this.dataManager.appendBar(e), this.crosshairHandler.setData(this.dataManager.getData()), this.autoScrollOnNewBar && this.viewport.scrollToEnd(), this.indicatorEngine.recalculateAll(this.dataManager.getData()), this.updateViewportAndRender();
|
|
608
|
+
}), this.streamManager.on("barUpdate", (e) => {
|
|
609
|
+
this.dataManager.updateLastBar(e), this.currentPriceLine.setPrice(e.close), this.indicatorEngine.recalculateAll(this.dataManager.getData()), this.scheduleRender();
|
|
610
|
+
}), this.streamManager.on("priceChange", ({ price: e }) => {
|
|
611
|
+
this.tradingManager.setCurrentPrice(e), this.currentPriceLine.setPrice(e), this.engine.requestRender(r.Overlay), this.engine.requestRender(r.UI);
|
|
612
|
+
}), this.streamManager.on("connectionChange", (e) => {
|
|
613
|
+
this.eventBus.emit("dataUpdate", { connection: e });
|
|
614
|
+
}), this.streamManager.on("error", (e) => {
|
|
615
|
+
this.eventBus.emit("dataUpdate", { error: e.message });
|
|
616
|
+
}), this.autoScrollOnNewBar = e.autoScroll !== !1, this.currentSymbol = e.symbol, await this.streamManager.connect(e);
|
|
617
|
+
let t = u(e.timeframe);
|
|
618
|
+
this.barCountdown.setTimeframeMs(t), this.countdownInterval && clearInterval(this.countdownInterval), this.countdownInterval = setInterval(() => {
|
|
619
|
+
this.barCountdown.isVisible() && this.engine.requestRender(r.UI);
|
|
620
|
+
}, 1e3);
|
|
621
|
+
}
|
|
622
|
+
async switchStream(e, t) {
|
|
623
|
+
this.streamManager && (this.currentSymbol = e, await this.streamManager.switchTo(e, t));
|
|
624
|
+
}
|
|
625
|
+
async setTimeframe(e) {
|
|
626
|
+
if (!this.streamManager) throw Error("No active stream. Call connect() first.");
|
|
627
|
+
await this.switchStream(this.currentSymbol, e);
|
|
628
|
+
}
|
|
629
|
+
disconnectStream() {
|
|
630
|
+
this.streamManager &&= (this.streamManager.dispose(), null);
|
|
631
|
+
}
|
|
632
|
+
setBarCountdownVisible(e) {
|
|
633
|
+
this.barCountdown.setVisible(e), this.engine.requestRender(r.UI);
|
|
634
|
+
}
|
|
635
|
+
setSessionBreaksVisible(e) {
|
|
636
|
+
this.sessionBreaks.setVisible(e), this.engine.requestRender(r.Background);
|
|
637
|
+
}
|
|
638
|
+
addCompareSymbol(e, t, n, i) {
|
|
639
|
+
this.compareRenderer.addSymbol({
|
|
640
|
+
id: e,
|
|
641
|
+
label: t,
|
|
642
|
+
data: n,
|
|
643
|
+
color: i,
|
|
644
|
+
visible: !0
|
|
645
|
+
}), this.engine.requestRender(r.Main);
|
|
646
|
+
}
|
|
647
|
+
removeCompareSymbol(e) {
|
|
648
|
+
this.compareRenderer.removeSymbol(e), this.engine.requestRender(r.Main);
|
|
649
|
+
}
|
|
650
|
+
updateCompareData(e, t) {
|
|
651
|
+
this.compareRenderer.setSymbolData(e, t), this.engine.requestRender(r.Main);
|
|
652
|
+
}
|
|
653
|
+
setCompareMode(e) {
|
|
654
|
+
this.compareRenderer.setMode(e), this.engine.requestRender(r.Main);
|
|
655
|
+
}
|
|
656
|
+
clearCompareSymbols() {
|
|
657
|
+
this.compareRenderer.clear(), this.engine.requestRender(r.Main);
|
|
658
|
+
}
|
|
659
|
+
setLogScale(e) {
|
|
660
|
+
this.viewport.setLogScale(e), this.updateViewportAndRender();
|
|
661
|
+
}
|
|
662
|
+
isLogScale() {
|
|
663
|
+
return this.viewport.isLogScale();
|
|
664
|
+
}
|
|
665
|
+
setSessionBreaksConfig(e) {
|
|
666
|
+
this.sessionBreaks.setConfig(e), this.engine.requestRender(r.Background);
|
|
667
|
+
}
|
|
668
|
+
getConnectionState() {
|
|
669
|
+
return this.streamManager?.getConnectionState() ?? "disconnected";
|
|
670
|
+
}
|
|
671
|
+
getConnectionInfo() {
|
|
672
|
+
return this.streamManager?.getConnectionInfo() ?? { state: "disconnected" };
|
|
673
|
+
}
|
|
674
|
+
setAutoScroll(e) {
|
|
675
|
+
this.autoScrollOnNewBar = e;
|
|
676
|
+
}
|
|
677
|
+
scrollTo(e) {
|
|
678
|
+
let t = this.dataManager.getData();
|
|
679
|
+
for (let n = 0; n < t.length; n++) if (t[n].time >= e) {
|
|
680
|
+
let e = this.viewport.getState().barWidth + this.viewport.getState().barSpacing;
|
|
681
|
+
this.viewport.scrollBy(n * e - this.viewport.getState().offset), this.updateViewportAndRender();
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
scrollToEnd() {
|
|
686
|
+
this.viewport.scrollToEnd(), this.updateViewportAndRender();
|
|
687
|
+
}
|
|
688
|
+
setVisibleRange(e, t) {
|
|
689
|
+
let n = this.dataManager.getData(), r = 0, i = n.length - 1;
|
|
690
|
+
for (let t = 0; t < n.length; t++) if (n[t].time >= e) {
|
|
691
|
+
r = t;
|
|
692
|
+
break;
|
|
693
|
+
}
|
|
694
|
+
for (let e = n.length - 1; e >= 0; e--) if (n[e].time <= t) {
|
|
695
|
+
i = e;
|
|
696
|
+
break;
|
|
697
|
+
}
|
|
698
|
+
let a = i - r + 1;
|
|
699
|
+
if (a > 0) {
|
|
700
|
+
let e = this.viewport.getState().chartRect.width, t = e / a, n = Math.max(2, t - this.viewport.getState().barSpacing);
|
|
701
|
+
this.viewport.zoom((n - this.viewport.getState().barWidth) / this.viewport.getState().barWidth, e / 2);
|
|
702
|
+
}
|
|
703
|
+
this.updateViewportAndRender();
|
|
704
|
+
}
|
|
705
|
+
zoomIn() {
|
|
706
|
+
let e = this.viewport.getState().chartRect.width;
|
|
707
|
+
this.viewport.zoom(.2, e / 2), this.updateViewportAndRender();
|
|
708
|
+
}
|
|
709
|
+
zoomOut() {
|
|
710
|
+
let e = this.viewport.getState().chartRect.width;
|
|
711
|
+
this.viewport.zoom(-.2, e / 2), this.updateViewportAndRender();
|
|
712
|
+
}
|
|
713
|
+
fitContent() {
|
|
714
|
+
let e = this.dataManager.getData();
|
|
715
|
+
e.length !== 0 && this.setVisibleRange(e[0].time, e[e.length - 1].time);
|
|
716
|
+
}
|
|
717
|
+
on(e, t) {
|
|
718
|
+
this.eventBus.on(e, t);
|
|
719
|
+
}
|
|
720
|
+
off(e, t) {
|
|
721
|
+
this.eventBus.off(e, t);
|
|
722
|
+
}
|
|
723
|
+
enableTauriBridge(e) {
|
|
724
|
+
this.eventBus.enableTauriBridge({
|
|
725
|
+
enabled: !0,
|
|
726
|
+
...e
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
disableTauriBridge() {
|
|
730
|
+
this.eventBus.disableTauriBridge();
|
|
731
|
+
}
|
|
732
|
+
setTheme(e) {
|
|
733
|
+
this.themeManager.setTheme(e), this.syncRenderContext(), this.container.style.backgroundColor = this.themeManager.getTheme().background, this.engine.requestRender(), this.eventBus.emit("themeChange", { theme: e });
|
|
734
|
+
}
|
|
735
|
+
getTheme() {
|
|
736
|
+
return this.themeManager.getTheme();
|
|
737
|
+
}
|
|
738
|
+
setWatermark(e, t) {
|
|
739
|
+
this.watermark.setConfig({
|
|
740
|
+
text: e,
|
|
741
|
+
...t
|
|
742
|
+
}), this.engine.requestRender(r.Background);
|
|
743
|
+
}
|
|
744
|
+
setAutoScale(e) {
|
|
745
|
+
this.options.autoScale = e, this.updateViewportAndRender();
|
|
746
|
+
}
|
|
747
|
+
isAutoScale() {
|
|
748
|
+
return this.options.autoScale !== !1;
|
|
749
|
+
}
|
|
750
|
+
setCrosshairMode(e) {
|
|
751
|
+
this.crosshairHandler.setMode(e), this.engine.requestRender(r.Overlay);
|
|
752
|
+
}
|
|
753
|
+
getCrosshairMode() {
|
|
754
|
+
return this.crosshairHandler.getMode();
|
|
755
|
+
}
|
|
756
|
+
setGridVisible(e) {
|
|
757
|
+
this.gridRenderer.setVisible(e), this.engine.requestRender(r.Background);
|
|
758
|
+
}
|
|
759
|
+
isGridVisible() {
|
|
760
|
+
return this.gridRenderer.isVisible();
|
|
761
|
+
}
|
|
762
|
+
setVolumeVisible(e) {
|
|
763
|
+
this.volumeRenderer.setVisible(e), this.engine.requestRender(r.Main);
|
|
764
|
+
}
|
|
765
|
+
setTooltipVisible(e) {
|
|
766
|
+
e || this.crosshairTooltip.hide();
|
|
767
|
+
}
|
|
768
|
+
setLegend(e) {
|
|
769
|
+
this.chartLegend.setConfig(e), this.engine.requestRender(r.UI);
|
|
770
|
+
}
|
|
771
|
+
setSymbolName(e) {
|
|
772
|
+
this.chartLegend.setSymbol(e), this.engine.requestRender(r.UI);
|
|
773
|
+
}
|
|
774
|
+
setStatusText(e) {
|
|
775
|
+
this.chartLegend.setStatusText(e), this.engine.requestRender(r.UI);
|
|
776
|
+
}
|
|
777
|
+
screenshot(e) {
|
|
778
|
+
this.features.screenshot && k.download(this.container, e, this.themeManager.getTheme().background);
|
|
779
|
+
}
|
|
780
|
+
screenshotDataURL() {
|
|
781
|
+
return this.features.screenshot ? k.toDataURL(this.container, this.themeManager.getTheme().background) : null;
|
|
782
|
+
}
|
|
783
|
+
async screenshotBlob() {
|
|
784
|
+
return this.features.screenshot ? k.toBlob(this.container, this.themeManager.getTheme().background) : null;
|
|
785
|
+
}
|
|
786
|
+
addAlert(e, t = "crossing", n) {
|
|
787
|
+
if (!this.features.alerts) return null;
|
|
788
|
+
let r = this.alertManager.addAlert(e, t, n);
|
|
789
|
+
return this.scheduleAutoSave(), r;
|
|
790
|
+
}
|
|
791
|
+
removeAlert(e) {
|
|
792
|
+
this.alertManager.removeAlert(e), this.scheduleAutoSave();
|
|
793
|
+
}
|
|
794
|
+
getAlerts() {
|
|
795
|
+
return this.alertManager.getAlerts();
|
|
796
|
+
}
|
|
797
|
+
clearAlerts() {
|
|
798
|
+
this.alertManager.clearAlerts(), this.scheduleAutoSave();
|
|
799
|
+
}
|
|
800
|
+
saveAlerts(e) {
|
|
801
|
+
this.alertManager.saveToStorage(e);
|
|
802
|
+
}
|
|
803
|
+
loadAlerts(e) {
|
|
804
|
+
this.alertManager.loadFromStorage(e), this.engine.requestRender(r.Overlay);
|
|
805
|
+
}
|
|
806
|
+
replay(e) {
|
|
807
|
+
if (!this.features.replay) return;
|
|
808
|
+
let t = this.dataManager.getData();
|
|
809
|
+
this.replayManager.load(t), this.replayManager.on("bar", ({ bar: e, index: n }) => {
|
|
810
|
+
let r = t.slice(0, n + 1);
|
|
811
|
+
this.dataManager.setData(r), this.crosshairHandler.setData(r), this.indicatorEngine.recalculateAll(r), this.updateViewportAndRender();
|
|
812
|
+
}), this.replayManager.play(e);
|
|
813
|
+
}
|
|
814
|
+
replayPause() {
|
|
815
|
+
this.replayManager.pause();
|
|
816
|
+
}
|
|
817
|
+
replayResume() {
|
|
818
|
+
this.replayManager.resume();
|
|
819
|
+
}
|
|
820
|
+
replayStop() {
|
|
821
|
+
this.replayManager.stop();
|
|
822
|
+
}
|
|
823
|
+
replaySeek(e) {
|
|
824
|
+
this.replayManager.seekTo(e);
|
|
825
|
+
}
|
|
826
|
+
setReplaySpeed(e) {
|
|
827
|
+
this.replayManager.setSpeed(e);
|
|
828
|
+
}
|
|
829
|
+
getReplayState() {
|
|
830
|
+
return this.replayManager.getState();
|
|
831
|
+
}
|
|
832
|
+
getReplayProgress() {
|
|
833
|
+
return this.replayManager.getProgress();
|
|
834
|
+
}
|
|
835
|
+
saveState(e) {
|
|
836
|
+
if (!this.features.saveLoad) return null;
|
|
837
|
+
let t = _.capture({
|
|
838
|
+
getDrawings: () => this.getDrawings(),
|
|
839
|
+
getTheme: () => this.getTheme(),
|
|
840
|
+
getAlerts: () => this.getAlerts()
|
|
841
|
+
}, { chartType: this.options.chartType }), n = _.serialize(t);
|
|
842
|
+
return e && _.saveToStorage(e, t), n;
|
|
843
|
+
}
|
|
844
|
+
loadState(e) {
|
|
845
|
+
if (!this.features.saveLoad) return;
|
|
846
|
+
let t = _.deserialize(e);
|
|
847
|
+
if (t.chartType && this.setChartType(t.chartType), t.drawings && this.setDrawings(t.drawings), t.theme && this.setTheme(t.theme), t.alerts) {
|
|
848
|
+
this.clearAlerts();
|
|
849
|
+
for (let e of t.alerts) this.addAlert(e.price, e.condition, e.message);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
loadStateFromStorage(e) {
|
|
853
|
+
if (!this.features.saveLoad) return !1;
|
|
854
|
+
let t = _.loadFromStorage(e);
|
|
855
|
+
return t ? (this.loadState(_.serialize(t)), !0) : !1;
|
|
856
|
+
}
|
|
857
|
+
downloadState(e) {
|
|
858
|
+
if (!this.features.saveLoad) return;
|
|
859
|
+
let t = _.capture({
|
|
860
|
+
getDrawings: () => this.getDrawings(),
|
|
861
|
+
getTheme: () => this.getTheme(),
|
|
862
|
+
getAlerts: () => this.getAlerts()
|
|
863
|
+
}, { chartType: this.options.chartType });
|
|
864
|
+
_.downloadFile(t, e);
|
|
865
|
+
}
|
|
866
|
+
async loadStateFromFile() {
|
|
867
|
+
if (!this.features.saveLoad) return;
|
|
868
|
+
let e = await _.loadFromFile();
|
|
869
|
+
this.loadState(_.serialize(e));
|
|
870
|
+
}
|
|
871
|
+
setLocale(e) {
|
|
872
|
+
l(e), this.engine.requestRender();
|
|
873
|
+
}
|
|
874
|
+
setNumberLocale(e) {
|
|
875
|
+
this.numberLocale = e, this.priceAxis.setLocale(e), this.crosshairHandler.setLocale(e), this.syncRenderContext(), this.engine.requestRender();
|
|
876
|
+
}
|
|
877
|
+
getNumberLocale() {
|
|
878
|
+
return this.numberLocale;
|
|
879
|
+
}
|
|
880
|
+
setMarket(e) {
|
|
881
|
+
if (this.marketConfig = e, e.colorScheme) {
|
|
882
|
+
let t = {
|
|
883
|
+
...this.themeManager.getTheme(),
|
|
884
|
+
candleUp: e.colorScheme.up,
|
|
885
|
+
candleDown: e.colorScheme.down,
|
|
886
|
+
candleUpWick: e.colorScheme.up,
|
|
887
|
+
candleDownWick: e.colorScheme.down,
|
|
888
|
+
volumeUp: e.colorScheme.up.replace(")", ", 0.3)").replace("rgb(", "rgba(") || `${e.colorScheme.up}4D`,
|
|
889
|
+
volumeDown: e.colorScheme.down.replace(")", ", 0.3)").replace("rgb(", "rgba(") || `${e.colorScheme.down}4D`
|
|
890
|
+
};
|
|
891
|
+
this.themeManager.setTheme(t);
|
|
892
|
+
}
|
|
893
|
+
e.pricePrecision !== void 0 && (this.tradingManager.setConfig({ pricePrecision: e.pricePrecision }), this.alertManager.setPricePrecision(e.pricePrecision), this.streamManager?.priceLine.setPricePrecision(e.pricePrecision), this.crosshairHandler.setPricePrecision(e.pricePrecision)), this.syncRenderContext(), this.engine.requestRender();
|
|
894
|
+
}
|
|
895
|
+
getMarket() {
|
|
896
|
+
return this.marketConfig;
|
|
897
|
+
}
|
|
898
|
+
setPriceLimits(e) {
|
|
899
|
+
this.marketConfig && (s(e, this.marketConfig) && (this.marketConfig.priceLimits = {
|
|
900
|
+
...this.marketConfig.priceLimits,
|
|
901
|
+
referencePrice: e
|
|
902
|
+
}), this.engine.requestRender());
|
|
903
|
+
}
|
|
904
|
+
getFeatures() {
|
|
905
|
+
return this.features;
|
|
906
|
+
}
|
|
907
|
+
setFeatures(e) {
|
|
908
|
+
Object.assign(this.features, e), e.crosshair === !1 && this.crosshairTooltip.hide(), e.grid !== void 0 && this.engine.requestRender(r.Background), e.volume !== void 0 && (this.volumeRenderer.setVisible(e.volume), this.engine.requestRender(r.Main)), e.drawings === !1 && this.drawingManager.setActiveTool(null), e.trading === !1 && (this.tradingManager.setOrders([]), this.tradingManager.setPositions([])), e.keyboard !== void 0 && this.keyboardHandler?.setEnabled(e.keyboard), this.engine.requestRender();
|
|
909
|
+
}
|
|
910
|
+
resize() {
|
|
911
|
+
let e = this.engine.dprManager.readContainerSize();
|
|
912
|
+
if (e.width <= 0 || e.height <= 0) return;
|
|
913
|
+
this.containerSizeCache = e, this.containerSizeCacheTime = Date.now();
|
|
914
|
+
let t = this.engine.dprManager.getDpr();
|
|
915
|
+
this.engine.layerManager.resize(e, t);
|
|
916
|
+
let n = this.viewport.isAtEnd();
|
|
917
|
+
this.viewport.resize(e.width, e.height), this.layoutManager.resize(e.width, e.height), this.updateViewportAndRender(n), this.eventBus.emit("resize", e);
|
|
918
|
+
}
|
|
919
|
+
destroy() {
|
|
920
|
+
this.countdownInterval && clearInterval(this.countdownInterval), this.disableAutoSave(), this.disconnectStream(), this.onWindowKeyDown &&= (window.removeEventListener("keydown", this.onWindowKeyDown), null), this.keyboardHandler = null, this.interactionManager.detach(), this.tradingManager.destroy(), this.animator.dispose(), this.crosshairTooltip.destroy(), this.replayManager.dispose(), this.undoRedoManager.clear(), this.engine.destroy(), this.eventBus.destroy(), this.container.innerHTML = "";
|
|
921
|
+
}
|
|
922
|
+
createChartRenderer(e) {
|
|
923
|
+
return _e(e);
|
|
924
|
+
}
|
|
925
|
+
getDisplayData() {
|
|
926
|
+
if (this.displayDataCache) return this.displayDataCache;
|
|
927
|
+
let e = this.dataManager.getData();
|
|
928
|
+
if (e.length === 0) return e;
|
|
929
|
+
let t = ve(this.options.chartType, e);
|
|
930
|
+
return this.displayDataCache = t, t;
|
|
931
|
+
}
|
|
932
|
+
scheduleRender() {
|
|
933
|
+
this.renderScheduled || (this.renderScheduled = !0, requestAnimationFrame(() => {
|
|
934
|
+
this.renderScheduled = !1;
|
|
935
|
+
let e = this.getDisplayData();
|
|
936
|
+
this.viewport.updateData(e, this.options.autoScale !== !1), this.syncRenderContext(), this.engine.requestRender();
|
|
937
|
+
}));
|
|
938
|
+
}
|
|
939
|
+
updateViewportAndRender(e = !1) {
|
|
940
|
+
this.resolvedLayoutCache = null, this.panelInfoCache = null;
|
|
941
|
+
let t = this.getResolvedLayout();
|
|
942
|
+
this.viewport.setChartRect(t.mainChartRect);
|
|
943
|
+
let n = this.getDisplayData();
|
|
944
|
+
if (this.viewport.updateData(n, this.options.autoScale !== !1), this.options.autoScale !== !1) {
|
|
945
|
+
let e = this.viewport.getState(), t = this.indicatorEngine.getOverlayPriceRange(e.visibleRange.from, Math.min(e.visibleRange.to, n.length - 1));
|
|
946
|
+
if (t) {
|
|
947
|
+
let n = e.priceRange, r = Math.min(n.min, t.min), i = Math.max(n.max, t.max);
|
|
948
|
+
if (r < n.min || i > n.max) {
|
|
949
|
+
let e = i - r || 1;
|
|
950
|
+
this.viewport.setPriceRange(r - e * .02, i + e * .02);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
e && this.viewport.scrollToEnd(), this.syncRenderContext(), this.engine.requestRender();
|
|
955
|
+
}
|
|
956
|
+
getResolvedLayout() {
|
|
957
|
+
return this.resolvedLayoutCache ||= this.layoutManager.resolve(), this.resolvedLayoutCache;
|
|
958
|
+
}
|
|
959
|
+
cachedContainerSize() {
|
|
960
|
+
let e = Date.now();
|
|
961
|
+
return (!this.containerSizeCache || e - this.containerSizeCacheTime > 500) && (this.containerSizeCache = this.engine.dprManager.getContainerSize(), this.containerSizeCacheTime = e), this.containerSizeCache;
|
|
962
|
+
}
|
|
963
|
+
buildPanelRenderInfos() {
|
|
964
|
+
if (this.panelInfoCache) return this.panelInfoCache;
|
|
965
|
+
let e = this.getResolvedLayout(), t = this.viewport.getState(), { from: n, to: r } = t.visibleRange, i = e.panels.map((e) => {
|
|
966
|
+
let i = ye(this.indicatorEngine.getOutput(e.config.id), n, r), a = {
|
|
967
|
+
x: e.rect.x,
|
|
968
|
+
y: e.rect.y + 20,
|
|
969
|
+
width: e.rect.width,
|
|
970
|
+
height: Math.max(0, e.rect.height - 20)
|
|
971
|
+
};
|
|
972
|
+
return {
|
|
973
|
+
instanceId: e.config.id,
|
|
974
|
+
rect: e.rect,
|
|
975
|
+
viewport: {
|
|
976
|
+
...t,
|
|
977
|
+
chartRect: a,
|
|
978
|
+
priceRange: i
|
|
979
|
+
}
|
|
980
|
+
};
|
|
981
|
+
});
|
|
982
|
+
return this.panelInfoCache = i, i;
|
|
983
|
+
}
|
|
984
|
+
syncRenderContext() {
|
|
985
|
+
let e = this.getResolvedLayout(), t = this.features.indicators ? this.buildPanelRenderInfos() : [], n = e.panels.filter((e) => e.config.position === "bottom").reduce((e, t) => e + t.rect.height, 0), r = e.mainChartRect.y + e.mainChartRect.height + n;
|
|
986
|
+
this.engine.setRenderContext({
|
|
987
|
+
chartRenderer: this.chartRenderer,
|
|
988
|
+
gridRenderer: this.features.grid ? this.gridRenderer : null,
|
|
989
|
+
priceAxis: this.features.priceAxis ? this.priceAxis : null,
|
|
990
|
+
timeAxis: this.features.timeAxis ? this.timeAxis : null,
|
|
991
|
+
crosshairHandler: this.features.crosshair ? this.crosshairHandler : null,
|
|
992
|
+
indicatorEngine: this.features.indicators ? this.indicatorEngine : null,
|
|
993
|
+
drawingRenderer: this.features.drawings ? this.drawingRenderer : null,
|
|
994
|
+
tradingRenderer: this.features.trading ? this.tradingRenderer : null,
|
|
995
|
+
currentPriceLine: this.streamManager?.priceLine ?? this.currentPriceLine,
|
|
996
|
+
chartLegend: this.features.legend ? this.chartLegend : null,
|
|
997
|
+
volumeRenderer: this.features.volume ? this.volumeRenderer : null,
|
|
998
|
+
watermark: this.features.watermark ? this.watermark : null,
|
|
999
|
+
barCountdown: this.barCountdown,
|
|
1000
|
+
sessionBreaks: this.sessionBreaks,
|
|
1001
|
+
compareRenderer: this.compareRenderer,
|
|
1002
|
+
panels: t,
|
|
1003
|
+
priceLimits: this.buildPriceLimits(),
|
|
1004
|
+
timeAxisY: r,
|
|
1005
|
+
viewport: this.viewport.getState(),
|
|
1006
|
+
theme: this.themeManager.getTheme(),
|
|
1007
|
+
data: this.getDisplayData(),
|
|
1008
|
+
numberLocale: this.numberLocale
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
buildPriceLimits() {
|
|
1012
|
+
if (!this.marketConfig?.priceLimits?.enabled || !this.marketConfig.priceLimits.referencePrice) return null;
|
|
1013
|
+
let e = s(this.marketConfig.priceLimits.referencePrice, this.marketConfig);
|
|
1014
|
+
return e ? {
|
|
1015
|
+
...e,
|
|
1016
|
+
colors: this.marketConfig.colorScheme ? {
|
|
1017
|
+
ceiling: this.marketConfig.colorScheme.ceiling,
|
|
1018
|
+
floor: this.marketConfig.colorScheme.floor,
|
|
1019
|
+
reference: this.marketConfig.colorScheme.reference
|
|
1020
|
+
} : void 0
|
|
1021
|
+
} : null;
|
|
1022
|
+
}
|
|
1023
|
+
};
|
|
1024
|
+
//#endregion
|
|
1025
|
+
export { J as a, Y as i, $ as n, Q as r, xe as t };
|
|
1026
|
+
|
|
1027
|
+
//# sourceMappingURL=Chart-CrrTKx3r.js.map
|