acttrader-charts 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -3371,6 +3371,7 @@ function formatTimestamp(ts, visibleBars, timeframe, spansMultipleDays, timezone
3371
3371
  return d.toLocaleDateString("en-US", { month: "short", year: "2-digit", timeZone: timezone });
3372
3372
  }
3373
3373
  function renderTimeAxis(ctx, bars, viewport, scale, theme, chartWidth, axisY, maxLabels = 8, cfg = DEFAULT_TIME_AXIS_CONFIG, timeframe, countdownBarIndex, timezone = "UTC") {
3374
+ if (bars.length === 0) return;
3374
3375
  const visibleBars = viewport.endIndex - viewport.startIndex;
3375
3376
  const firstBar = bars[0];
3376
3377
  const lastBar = bars[bars.length - 1];
@@ -3379,7 +3380,8 @@ function renderTimeAxis(ctx, bars, viewport, scale, theme, chartWidth, axisY, ma
3379
3380
  ctx.font = `${cfg.fontSize} ${cfg.fontFamily}`;
3380
3381
  ctx.textAlign = "center";
3381
3382
  const MIN_GAP = 12;
3382
- const sampleLabel = formatTimestamp(bars[Math.floor(bars.length / 2)]?.time ?? bars[0].time, visibleBars, timeframe, spansMultipleDays, timezone);
3383
+ const sampleBar = bars[Math.floor(bars.length / 2)] ?? bars[0];
3384
+ const sampleLabel = formatTimestamp(sampleBar.time, visibleBars, timeframe, spansMultipleDays, timezone);
3383
3385
  const labelW = ctx.measureText(sampleLabel).width;
3384
3386
  const minStep = Math.max(1, Math.floor(bars.length / maxLabels));
3385
3387
  let step = minStep;
@@ -18661,6 +18663,9 @@ var _ChartEngine = class _ChartEngine {
18661
18663
  this.tickActivityTimer = null;
18662
18664
  this.tickActivityMs = 3e4;
18663
18665
  this.streamStatus = "disconnected";
18666
+ // Set by destroy() so late-firing callbacks (ResizeObserver entries queued
18667
+ // before disconnect, in-flight promises, sockets) bail before touching state.
18668
+ this._isDestroyed = false;
18664
18669
  this.indicatorSettingsDialog = null;
18665
18670
  this.chartSettingsDialog = null;
18666
18671
  this.tradeButton = null;
@@ -19814,6 +19819,7 @@ var _ChartEngine = class _ChartEngine {
19814
19819
  }
19815
19820
  };
19816
19821
  this.onTick = (tick) => {
19822
+ if (this._isDestroyed) return;
19817
19823
  const all = this.dataStore.all;
19818
19824
  if (all.length === 0) return;
19819
19825
  if (this._suppressTicks) return;
@@ -22223,6 +22229,7 @@ var _ChartEngine = class _ChartEngine {
22223
22229
  return this;
22224
22230
  }
22225
22231
  destroy() {
22232
+ this._isDestroyed = true;
22226
22233
  this.panHandler.destroy();
22227
22234
  this.zoomHandler.destroy();
22228
22235
  this.resizeObserver.disconnect();
@@ -22355,6 +22362,7 @@ var _ChartEngine = class _ChartEngine {
22355
22362
  }
22356
22363
  // ── Rendering ─────────────────────────────────────────────────────────────
22357
22364
  scheduleRender() {
22365
+ if (this._isDestroyed) return;
22358
22366
  if (this.rafId !== null) return;
22359
22367
  this.rafId = requestAnimationFrame(() => {
22360
22368
  this.rafId = null;
@@ -22544,6 +22552,7 @@ var _ChartEngine = class _ChartEngine {
22544
22552
  this.positionRenderStyle = activeCount > this.tradesThresholdForHorizontalLine ? "dot" : "line";
22545
22553
  }
22546
22554
  renderTradeLayer() {
22555
+ if (this._isDestroyed) return;
22547
22556
  const dpr = window.devicePixelRatio || 1;
22548
22557
  const { tradeCtx: ctx, tradeCanvas: canvas, theme, viewport } = this;
22549
22558
  ctx.clearRect(0, 0, canvas.width, canvas.height);
@@ -23089,6 +23098,7 @@ var _ChartEngine = class _ChartEngine {
23089
23098
  });
23090
23099
  }
23091
23100
  render() {
23101
+ if (this._isDestroyed) return;
23092
23102
  const { ctx, canvas, theme, viewport } = this;
23093
23103
  const dpr = window.devicePixelRatio || 1;
23094
23104
  const totalW = canvas.width;
@@ -23536,19 +23546,21 @@ var _ChartEngine = class _ChartEngine {
23536
23546
  );
23537
23547
  if (showCountdown) {
23538
23548
  const lastBar2 = this.dataStore.all[this.dataStore.length - 1];
23539
- const intervalMs = this.timeframeToMs(this.timeframe);
23540
- renderCandleCountdown(
23541
- ctx,
23542
- lastBar2.time,
23543
- intervalMs,
23544
- this.dataStore.length - 1,
23545
- viewport,
23546
- this.scaleManager,
23547
- theme,
23548
- chartW,
23549
- subPaneY,
23550
- this.uiConfig.timeAxis
23551
- );
23549
+ if (lastBar2) {
23550
+ const intervalMs = this.timeframeToMs(this.timeframe);
23551
+ renderCandleCountdown(
23552
+ ctx,
23553
+ lastBar2.time,
23554
+ intervalMs,
23555
+ this.dataStore.length - 1,
23556
+ viewport,
23557
+ this.scaleManager,
23558
+ theme,
23559
+ chartW,
23560
+ subPaneY,
23561
+ this.uiConfig.timeAxis
23562
+ );
23563
+ }
23552
23564
  }
23553
23565
  }
23554
23566
  if (this.crosshair) {
@@ -23637,8 +23649,10 @@ var _ChartEngine = class _ChartEngine {
23637
23649
  }
23638
23650
  }
23639
23651
  onResize() {
23652
+ if (this._isDestroyed) return;
23640
23653
  const dpr = window.devicePixelRatio || 1;
23641
23654
  const rect = this.canvasWrap.getBoundingClientRect();
23655
+ if (rect.width === 0 || rect.height === 0) return;
23642
23656
  this._cachedWrapRect = rect;
23643
23657
  this._cachedDrawRect = this.drawCanvas.getBoundingClientRect();
23644
23658
  for (const c of [this.canvas, this.tradeCanvas, this.drawCanvas]) {