@area8975/ui 0.2.2-dev.37 → 0.2.2-dev.38

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.
@@ -670,7 +670,6 @@ function baseChartOptions(ink) {
670
670
  fontFamily: "inherit",
671
671
  foreColor: ink.muted,
672
672
  parentHeightOffset: 0,
673
- redrawOnParentResize: true,
674
673
  toolbar: { show: false },
675
674
  zoom: { enabled: false },
676
675
  animations: {
@@ -1060,18 +1059,27 @@ var UiChartComponent = class UiChartComponent {
1060
1059
  chart = signal(null, ...ngDevMode ? [{ debugName: "chart" }] : /* istanbul ignore next */ []);
1061
1060
  destroyed = false;
1062
1061
  drawnNames = [];
1062
+ host = inject(ElementRef);
1063
+ drawnSize = {
1064
+ width: 0,
1065
+ height: 0
1066
+ };
1067
+ resizeObserver = null;
1063
1068
  constructor() {
1064
1069
  afterNextRender(async () => {
1065
1070
  const { default: Apex } = await import("apexcharts");
1066
1071
  if (this.destroyed) return;
1067
- const chart = new Apex(this.canvas().nativeElement, untracked(this.options));
1072
+ const chart = new Apex(this.canvas().nativeElement, this.withOwnParentResizing(untracked(this.options)));
1068
1073
  chart.addEventListener("updated", () => {
1074
+ this.drawnSize = this.hostSize();
1069
1075
  this.applyHidden(chart);
1070
1076
  this.applyEmphasis();
1071
1077
  });
1072
1078
  this.drawnNames = this.seriesNames();
1073
1079
  await chart.render();
1080
+ this.drawnSize = this.hostSize();
1074
1081
  this.chart.set(chart);
1082
+ this.redrawWhenResized(chart);
1075
1083
  this.applyHidden(chart);
1076
1084
  this.applyEmphasis();
1077
1085
  });
@@ -1082,7 +1090,7 @@ var UiChartComponent = class UiChartComponent {
1082
1090
  const names = this.seriesNames();
1083
1091
  const reordered = names.length === this.drawnNames.length && names.some((name, index) => name !== this.drawnNames[index]) && names.every((name) => this.drawnNames.includes(name));
1084
1092
  this.drawnNames = names;
1085
- chart.updateOptions(options, false, !reordered);
1093
+ chart.updateOptions(this.withOwnParentResizing(options), false, !reordered);
1086
1094
  });
1087
1095
  effect(() => {
1088
1096
  this.emphasis();
@@ -1097,9 +1105,33 @@ var UiChartComponent = class UiChartComponent {
1097
1105
  });
1098
1106
  inject(DestroyRef).onDestroy(() => {
1099
1107
  this.destroyed = true;
1108
+ this.resizeObserver?.disconnect();
1100
1109
  this.chart()?.destroy();
1101
1110
  });
1102
1111
  }
1112
+ withOwnParentResizing(options) {
1113
+ return {
1114
+ ...options,
1115
+ chart: {
1116
+ ...options.chart,
1117
+ redrawOnParentResize: false
1118
+ }
1119
+ };
1120
+ }
1121
+ redrawWhenResized(chart) {
1122
+ this.resizeObserver = new ResizeObserver(() => {
1123
+ const size = this.hostSize();
1124
+ if (size.width !== this.drawnSize.width || size.height !== this.drawnSize.height) chart.updateSeries(untracked(this.options).series ?? [], false);
1125
+ });
1126
+ this.resizeObserver.observe(this.host.nativeElement);
1127
+ }
1128
+ hostSize() {
1129
+ const { offsetWidth, offsetHeight } = this.host.nativeElement;
1130
+ return {
1131
+ width: offsetWidth,
1132
+ height: offsetHeight
1133
+ };
1134
+ }
1103
1135
  applyHidden(chart) {
1104
1136
  const hidden = this.hiddenSeries();
1105
1137
  if (!this.canvas().nativeElement.querySelector(".apexcharts-inner .apexcharts-series")) return;