Skip to content

Commit b0862fd

Browse files
authored
Fix resizing in pie chart (#27608)
1 parent 77735f5 commit b0862fd

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/components/chart/ha-chart-base.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,19 @@ export class HaChartBase extends LitElement {
8888

8989
private _lastTapTime?: number;
9090

91+
private _shouldResizeChart = false;
92+
9193
// @ts-ignore
9294
private _resizeController = new ResizeController(this, {
93-
callback: () => this.chart?.resize(),
95+
callback: () => {
96+
if (this.chart) {
97+
if (!this.chart.getZr().animation.isFinished()) {
98+
this._shouldResizeChart = true;
99+
} else {
100+
this.chart.resize();
101+
}
102+
}
103+
},
94104
});
95105

96106
private _loading = false;
@@ -366,6 +376,7 @@ export class HaChartBase extends LitElement {
366376
if (!this.options?.dataZoom) {
367377
this.chart.getZr().on("dblclick", this._handleClickZoom);
368378
}
379+
this.chart.on("finished", this._handleChartRenderFinished);
369380
if (this._isTouchDevice) {
370381
this.chart.getZr().on("click", (e: ECElementEvent) => {
371382
if (!e.zrByTouch) {
@@ -945,6 +956,13 @@ export class HaChartBase extends LitElement {
945956
});
946957
}
947958

959+
private _handleChartRenderFinished = () => {
960+
if (this._shouldResizeChart) {
961+
this.chart?.resize();
962+
this._shouldResizeChart = false;
963+
}
964+
};
965+
948966
static styles = css`
949967
:host {
950968
display: block;

0 commit comments

Comments
 (0)