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