@tradecanvas/chart 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -237,8 +237,11 @@ var q = class {
237
237
  marketConfig = null;
238
238
  container;
239
239
  currentPriceLine;
240
+ numberLocale;
241
+ keyboardHandler = null;
242
+ onWindowKeyDown = null;
240
243
  constructor(e, t) {
241
- this.container = e, this.options = t;
244
+ this.container = e, this.options = t, this.numberLocale = t.numberLocale ?? "en-US";
242
245
  let n = t.features ?? {};
243
246
  this.features = {
244
247
  drawings: n.drawings ?? !0,
@@ -282,7 +285,7 @@ var q = class {
282
285
  if (e.width <= 0 || e.height <= 0) return;
283
286
  let t = this.viewport.isAtEnd();
284
287
  this.viewport.resize(e.width, e.height), this.layoutManager.resize(e.width, e.height), this.updateViewportAndRender(t);
285
- }, this.chartRenderer = this.createChartRenderer(t.chartType), this.gridRenderer = new Ee(), t.grid?.visible === !1 && this.gridRenderer.setVisible(!1), this.priceAxis = new Le(), this.timeAxis = new Je(), this.crosshairHandler = new z(), t.crosshair?.mode && this.crosshairHandler.setMode(t.crosshair.mode), this.crosshairHandler.setCallback((e, 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) => {
286
289
  if (e !== null && t) {
287
290
  let n = this.dataManager.getData(), r = e < n.length ? n[e] : void 0;
288
291
  this.chartLegend.setHoverBar(r ?? null), r && this.crosshairTooltip.show(t, r, this.themeManager.getTheme(), this.cachedContainerSize()), this.eventBus.emit("crosshairMove", {
@@ -296,7 +299,7 @@ var q = class {
296
299
  color: t.sessionBreaks.color,
297
300
  lineStyle: t.sessionBreaks.lineStyle,
298
301
  lineWidth: t.sessionBreaks.lineWidth
299
- }) : 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), new Me({
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({
300
303
  scrollBars: (e) => {
301
304
  let t = this.viewport.getState().barWidth + this.viewport.getState().barSpacing;
302
305
  this.viewport.scrollBy(e * t), this.updateViewportAndRender();
@@ -312,7 +315,11 @@ var q = class {
312
315
  this.viewport.scrollToEnd(), this.updateViewportAndRender();
313
316
  },
314
317
  fitContent: () => this.fitContent()
315
- }), this.currentPriceLine = new ve(), this.alertManager = new S(), this.alertManager.setRequestRender(() => this.engine.requestRender(u.Overlay)), this.alertManager.on("triggered", (e) => {
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) => {
316
323
  this.eventBus.emit("dataUpdate", {
317
324
  alert: "triggered",
318
325
  alertId: e.id,
@@ -334,10 +341,10 @@ var q = class {
334
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();
335
342
  }
336
343
  updateLastBar(e) {
337
- 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.scheduleRender();
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();
338
345
  }
339
346
  updateLastBarFromTick(e) {
340
- 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.scheduleRender();
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();
341
348
  }
342
349
  setChartType(e) {
343
350
  this.options.chartType = e, this.chartRenderer = this.createChartRenderer(e), this.chartLegend.setChartType(e), this.displayDataCache = null, this.updateViewportAndRender(!0);
@@ -503,7 +510,7 @@ var q = class {
503
510
  }), this.streamManager.on("barClose", (e) => {
504
511
  this.dataManager.appendBar(e), this.crosshairHandler.setData(this.dataManager.getData()), this.autoScrollOnNewBar && this.viewport.scrollToEnd(), this.indicatorEngine.recalculateAll(this.dataManager.getData()), this.updateViewportAndRender();
505
512
  }), this.streamManager.on("barUpdate", (e) => {
506
- this.dataManager.updateLastBar(e), this.currentPriceLine.setPrice(e.close), this.scheduleRender();
513
+ this.dataManager.updateLastBar(e), this.currentPriceLine.setPrice(e.close), this.indicatorEngine.recalculateAll(this.dataManager.getData()), this.scheduleRender();
507
514
  }), this.streamManager.on("priceChange", ({ price: e }) => {
508
515
  this.tradingManager.setCurrentPrice(e), this.currentPriceLine.setPrice(e), this.engine.requestRender(u.Overlay), this.engine.requestRender(u.UI);
509
516
  }), this.streamManager.on("connectionChange", (e) => {
@@ -761,6 +768,12 @@ var q = class {
761
768
  setLocale(e) {
762
769
  me(e), this.engine.requestRender();
763
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
+ }
764
777
  setMarket(e) {
765
778
  if (this.marketConfig = e, e.colorScheme) {
766
779
  let t = {
@@ -789,7 +802,7 @@ var q = class {
789
802
  return this.features;
790
803
  }
791
804
  setFeatures(e) {
792
- 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([])), this.engine.requestRender();
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();
793
806
  }
794
807
  resize() {
795
808
  let e = this.engine.dprManager.readContainerSize();
@@ -801,7 +814,7 @@ var q = class {
801
814
  this.viewport.resize(e.width, e.height), this.layoutManager.resize(e.width, e.height), this.updateViewportAndRender(n), this.eventBus.emit("resize", e);
802
815
  }
803
816
  destroy() {
804
- this.countdownInterval && clearInterval(this.countdownInterval), this.disableAutoSave(), this.disconnectStream(), 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 = "";
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 = "";
805
818
  }
806
819
  createChartRenderer(e) {
807
820
  switch (e) {
@@ -941,7 +954,8 @@ var q = class {
941
954
  timeAxisY: r,
942
955
  viewport: this.viewport.getState(),
943
956
  theme: this.themeManager.getTheme(),
944
- data: this.getDisplayData()
957
+ data: this.getDisplayData(),
958
+ numberLocale: this.numberLocale
945
959
  });
946
960
  }
947
961
  timeframeToMs(e) {