Skip to content

Commit 2fa43df

Browse files
committed
fix: Charts would sometimes not display if used inside a vertical or horizontal stack card
Fixes #945
1 parent 7bcbd5f commit 2fa43df

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/apexcharts-card.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,6 @@ class ChartsCard extends LitElement {
782782
}
783783

784784
private async _initialLoad() {
785-
await this.updateComplete;
786-
787785
if (isUsingServerTimezone(this._hass)) {
788786
this._serverTimeOffset = computeTimezoneDiffWithLocal(this._hass?.config.time_zone);
789787
}
@@ -797,16 +795,18 @@ class ChartsCard extends LitElement {
797795
(layout as any).chart.id = Math.random().toString(36).substring(7);
798796
}
799797
this._apexChart = new ApexCharts(graph, layout);
800-
this._apexChart.render();
798+
const promises: Promise<void>[] = [];
799+
promises.push(this._apexChart.render());
801800
if (this._config.series_in_brush.length) {
802801
const brush = this.shadowRoot.querySelector('#brush');
803802
this._apexBrush = new ApexCharts(
804803
brush,
805804
// eslint-disable-next-line @typescript-eslint/no-explicit-any
806805
getBrushLayoutConfig(this._config, this._hass, (layout as any).chart.id),
807806
);
808-
this._apexBrush.render();
807+
promises.push(this._apexBrush.render());
809808
}
809+
await Promise.all(promises);
810810
this._firstDataLoad();
811811
}
812812
}
@@ -985,10 +985,13 @@ class ChartsCard extends LitElement {
985985
// eslint-disable-next-line @typescript-eslint/no-explicit-any
986986
const currentMax = (this._apexChart as any).axes?.w?.globals?.maxX;
987987
this._headerState = [...this._headerState];
988-
this._apexChart?.updateOptions(
989-
graphData,
990-
false,
991-
TIMESERIES_TYPES.includes(this._config.chart_type) ? false : true,
988+
const chartUpdates: Promise<void>[] = [];
989+
chartUpdates.push(
990+
this._apexChart?.updateOptions(
991+
graphData,
992+
false,
993+
TIMESERIES_TYPES.includes(this._config.chart_type) ? false : true,
994+
),
992995
);
993996
if (this._apexBrush) {
994997
const newMin = start.getTime() - this._serverTimeOffset;
@@ -1022,8 +1025,9 @@ class ChartsCard extends LitElement {
10221025
brushData.chart.selection.stroke = { color: selectionColor };
10231026
brushData.chart.selection.fill = { color: selectionColor, opacity: 0.1 };
10241027
this._brushInit = true;
1025-
this._apexBrush?.updateOptions(brushData, false, false);
1028+
chartUpdates.push(this._apexBrush?.updateOptions(brushData, false, false));
10261029
}
1030+
await Promise.all(chartUpdates);
10271031
} catch (err) {
10281032
log(err);
10291033
}

0 commit comments

Comments
 (0)