@acorex/charts 22.0.0-next.0 → 22.0.0-next.1

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.
@@ -235,7 +235,7 @@ class AXBarChartComponent extends AXChartComponent {
235
235
  const visibleSingleData = isClustered ? [] : this.visibleData();
236
236
  const groupedData = isClustered ? inputValue : [];
237
237
  // Clear existing chart SVG and messages (do not remove tooltip component)
238
- this.d3.select(containerElement).selectAll('svg, .ax-chart-message-container').remove();
238
+ this.clearChartArea(containerElement);
239
239
  // Early return if no data
240
240
  if (!Array.isArray(inputValue) || inputValue.length === 0) {
241
241
  this.showNoDataMessage(containerElement);
@@ -278,7 +278,7 @@ class AXBarChartComponent extends AXChartComponent {
278
278
  this._pendingTooltipCoords = null;
279
279
  const container = this.chartContainerEl()?.nativeElement;
280
280
  if (container) {
281
- this.d3?.select(container).selectAll('svg, .ax-chart-message-container').remove();
281
+ this.clearChartArea(container);
282
282
  }
283
283
  this.svg = undefined;
284
284
  this.chart = undefined;
@@ -934,24 +934,35 @@ class AXBarChartComponent extends AXChartComponent {
934
934
  percentage: `${percentage}%`,
935
935
  color: color,
936
936
  });
937
- this.updateTooltipPosition(event);
938
937
  this._tooltipVisible.set(true);
938
+ this.updateTooltipPosition(event);
939
939
  }
940
940
  }
941
941
  updateTooltipPosition(event) {
942
942
  this._pendingTooltipCoords = { x: event.clientX, y: event.clientY };
943
943
  if (this._tooltipRafId != null)
944
944
  return;
945
+ this.scheduleTooltipPosition(0);
946
+ }
947
+ scheduleTooltipPosition(attempt) {
945
948
  this._tooltipRafId = requestAnimationFrame(() => {
946
- this._tooltipRafId = null;
947
949
  const coords = this._pendingTooltipCoords;
948
- if (!coords)
950
+ if (!coords) {
951
+ this._tooltipRafId = null;
949
952
  return;
953
+ }
950
954
  const containerEl = this.chartContainerEl()?.nativeElement;
951
- if (!containerEl)
955
+ if (!containerEl) {
956
+ this._tooltipRafId = null;
952
957
  return;
953
- const containerRect = containerEl.getBoundingClientRect();
958
+ }
954
959
  const tooltipEl = containerEl.querySelector('.chart-tooltip');
960
+ if (!tooltipEl && this._tooltipVisible() && attempt < 3) {
961
+ this.scheduleTooltipPosition(attempt + 1);
962
+ return;
963
+ }
964
+ this._tooltipRafId = null;
965
+ const containerRect = containerEl.getBoundingClientRect();
955
966
  const tooltipRect = tooltipEl ? tooltipEl.getBoundingClientRect() : null;
956
967
  const pos = this.computeEnhancedTooltipPosition(containerRect, tooltipRect, coords.x, coords.y);
957
968
  this._tooltipPosition.set(pos);
@@ -961,51 +972,42 @@ class AXBarChartComponent extends AXChartComponent {
961
972
  * Enhanced tooltip positioning that considers chart boundaries and prevents overflow
962
973
  */
963
974
  computeEnhancedTooltipPosition(containerRect, tooltipRect, clientX, clientY) {
964
- const cursorX = clientX - containerRect.left;
965
- const cursorY = clientY - containerRect.top;
975
+ const containerLeft = containerRect.left;
976
+ const containerTop = containerRect.top;
977
+ const containerRight = containerRect.right;
978
+ const containerBottom = containerRect.bottom;
966
979
  if (!tooltipRect) {
967
- // Default positioning when tooltip dimensions are unknown
968
980
  return {
969
- x: Math.min(cursorX + this.TOOLTIP_GAP, containerRect.width - this.TOOLTIP_GAP),
970
- y: Math.max(this.TOOLTIP_GAP, Math.min(cursorY, containerRect.height - this.TOOLTIP_GAP)),
981
+ x: Math.min(clientX + this.TOOLTIP_GAP, containerRight - this.TOOLTIP_GAP),
982
+ y: Math.max(containerTop + this.TOOLTIP_GAP, Math.min(clientY + this.TOOLTIP_GAP, containerBottom - this.TOOLTIP_GAP)),
971
983
  };
972
984
  }
973
- // Calculate available space in each direction
974
- const spaceRight = containerRect.width - cursorX;
975
- const spaceLeft = cursorX;
976
- const spaceBelow = containerRect.height - cursorY;
977
- const spaceAbove = cursorY;
978
- // Determine best horizontal position
985
+ const spaceRight = containerRight - clientX;
986
+ const spaceLeft = clientX - containerLeft;
987
+ const spaceBelow = containerBottom - clientY;
988
+ const spaceAbove = clientY - containerTop;
979
989
  let x;
980
990
  if (spaceRight >= tooltipRect.width + this.TOOLTIP_GAP) {
981
- // Position to the right of cursor
982
- x = cursorX + this.TOOLTIP_GAP;
991
+ x = clientX + this.TOOLTIP_GAP;
983
992
  }
984
993
  else if (spaceLeft >= tooltipRect.width + this.TOOLTIP_GAP) {
985
- // Position to the left of cursor
986
- x = cursorX - tooltipRect.width - this.TOOLTIP_GAP;
994
+ x = clientX - tooltipRect.width - this.TOOLTIP_GAP;
987
995
  }
988
996
  else {
989
- // Center horizontally if neither side has enough space
990
- x = Math.max(this.TOOLTIP_GAP, Math.min((containerRect.width - tooltipRect.width) / 2, containerRect.width - tooltipRect.width - this.TOOLTIP_GAP));
997
+ x = Math.max(containerLeft + this.TOOLTIP_GAP, Math.min(containerLeft + (containerRect.width - tooltipRect.width) / 2, containerRight - tooltipRect.width - this.TOOLTIP_GAP));
991
998
  }
992
- // Calculate best vertical position
993
999
  let y;
994
1000
  if (spaceBelow >= tooltipRect.height + this.TOOLTIP_GAP) {
995
- // Position below cursor
996
- y = cursorY + this.TOOLTIP_GAP;
1001
+ y = clientY + this.TOOLTIP_GAP;
997
1002
  }
998
1003
  else if (spaceAbove >= tooltipRect.height + this.TOOLTIP_GAP) {
999
- // Position above cursor
1000
- y = cursorY - tooltipRect.height - this.TOOLTIP_GAP;
1004
+ y = clientY - tooltipRect.height - this.TOOLTIP_GAP;
1001
1005
  }
1002
1006
  else {
1003
- // Center vertically if neither direction has enough space
1004
- y = Math.max(this.TOOLTIP_GAP, Math.min((containerRect.height - tooltipRect.height) / 2, containerRect.height - tooltipRect.height - this.TOOLTIP_GAP));
1007
+ y = Math.max(containerTop + this.TOOLTIP_GAP, Math.min(containerTop + (containerRect.height - tooltipRect.height) / 2, containerBottom - tooltipRect.height - this.TOOLTIP_GAP));
1005
1008
  }
1006
- // Ensure tooltip stays within container bounds
1007
- x = Math.max(this.TOOLTIP_GAP, Math.min(x, containerRect.width - tooltipRect.width - this.TOOLTIP_GAP));
1008
- y = Math.max(this.TOOLTIP_GAP, Math.min(y, containerRect.height - tooltipRect.height - this.TOOLTIP_GAP));
1009
+ x = Math.max(containerLeft + this.TOOLTIP_GAP, Math.min(x, containerRight - tooltipRect.width - this.TOOLTIP_GAP));
1010
+ y = Math.max(containerTop + this.TOOLTIP_GAP, Math.min(y, containerBottom - tooltipRect.height - this.TOOLTIP_GAP));
1009
1011
  return { x, y };
1010
1012
  }
1011
1013
  /**
@@ -1190,10 +1192,7 @@ class AXBarChartComponent extends AXChartComponent {
1190
1192
  this.hiddenBars.delete(id);
1191
1193
  if (wasAllHidden) {
1192
1194
  if (this.chartContainerEl()?.nativeElement) {
1193
- this.d3
1194
- ?.select(this.chartContainerEl().nativeElement)
1195
- .selectAll('svg, .ax-chart-message-container')
1196
- .remove();
1195
+ this.clearChartArea(this.chartContainerEl().nativeElement);
1197
1196
  setTimeout(() => {
1198
1197
  this.createChart();
1199
1198
  }, 0);
@@ -1218,7 +1217,7 @@ class AXBarChartComponent extends AXChartComponent {
1218
1217
  this.hiddenSeries.delete(id);
1219
1218
  if (wasAllHidden) {
1220
1219
  if (this.chartContainerEl()?.nativeElement) {
1221
- this.d3?.select(this.chartContainerEl().nativeElement).selectAll('svg, .ax-chart-message-container').remove();
1220
+ this.clearChartArea(this.chartContainerEl().nativeElement);
1222
1221
  setTimeout(() => {
1223
1222
  this.createChart();
1224
1223
  }, 0);
@@ -1239,6 +1238,8 @@ class AXBarChartComponent extends AXChartComponent {
1239
1238
  return this.chartContainerEl()?.nativeElement ?? null;
1240
1239
  }
1241
1240
  clearChartArea(containerElement) {
1241
+ if (!this.d3)
1242
+ return;
1242
1243
  this.d3.select(containerElement).selectAll('svg, .ax-chart-empty, .ax-chart-message-container').remove();
1243
1244
  }
1244
1245
  /**