mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +00:00
Show more details in statistics legend when only 1 entity (#26241)
This commit is contained in:
parent
657275fd17
commit
879e0ed3d5
@ -97,7 +97,7 @@ export class StatisticsChart extends LitElement {
|
|||||||
|
|
||||||
@state() private _chartData: (LineSeriesOption | BarSeriesOption)[] = [];
|
@state() private _chartData: (LineSeriesOption | BarSeriesOption)[] = [];
|
||||||
|
|
||||||
@state() private _legendData: NonNullable<CustomLegendOption["data"]> = [];
|
@state() private _legendData: CustomLegendOption["data"];
|
||||||
|
|
||||||
@state() private _statisticIds: string[] = [];
|
@state() private _statisticIds: string[] = [];
|
||||||
|
|
||||||
@ -184,11 +184,17 @@ export class StatisticsChart extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _datasetHidden(ev: CustomEvent) {
|
private _datasetHidden(ev: CustomEvent) {
|
||||||
|
if (!this._legendData) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this._hiddenStats.add(ev.detail.id);
|
this._hiddenStats.add(ev.detail.id);
|
||||||
this.requestUpdate("_hiddenStats");
|
this.requestUpdate("_hiddenStats");
|
||||||
}
|
}
|
||||||
|
|
||||||
private _datasetUnhidden(ev: CustomEvent) {
|
private _datasetUnhidden(ev: CustomEvent) {
|
||||||
|
if (!this._legendData) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this._hiddenStats.delete(ev.detail.id);
|
this._hiddenStats.delete(ev.detail.id);
|
||||||
this.requestUpdate("_hiddenStats");
|
this.requestUpdate("_hiddenStats");
|
||||||
}
|
}
|
||||||
@ -617,9 +623,13 @@ export class StatisticsChart extends LitElement {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this._chartData = totalDataSets;
|
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
|
// 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;
|
this._statisticIds = statisticIds;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user