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