Show more details in statistics legend when only 1 entity (#26241)

This commit is contained in:
Petar Petrov 2025-07-21 11:57:13 +03:00 committed by GitHub
parent 657275fd17
commit 879e0ed3d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -97,7 +97,7 @@ export class StatisticsChart extends LitElement {
@state() private _chartData: (LineSeriesOption | BarSeriesOption)[] = [];
@state() private _legendData: NonNullable<CustomLegendOption["data"]> = [];
@state() private _legendData: CustomLegendOption["data"];
@state() private _statisticIds: string[] = [];
@ -184,11 +184,17 @@ export class StatisticsChart extends LitElement {
}
private _datasetHidden(ev: CustomEvent) {
if (!this._legendData) {
return;
}
this._hiddenStats.add(ev.detail.id);
this.requestUpdate("_hiddenStats");
}
private _datasetUnhidden(ev: CustomEvent) {
if (!this._legendData) {
return;
}
this._hiddenStats.delete(ev.detail.id);
this.requestUpdate("_hiddenStats");
}
@ -617,9 +623,13 @@ export class StatisticsChart extends LitElement {
});
this._chartData = totalDataSets;
if (legendData.length !== this._legendData.length) {
if (legendData.length !== this._legendData?.length) {
// only update the legend if it has changed or it will trigger options update
this._legendData = legendData.map(({ id, name }) => ({ id, name }));
this._legendData =
legendData.length > 1
? legendData.map(({ id, name }) => ({ id, name }))
: // if there is only one entity, let the base chart handle the legend
undefined;
}
this._statisticIds = statisticIds;
}