mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Fix legend in charts (#24025)
* Fix legend in line charts * fix statistics graph legend
This commit is contained in:
parent
ff1159402e
commit
0d50d2664f
@ -72,6 +72,8 @@ export class StateHistoryChartLine extends LitElement {
|
|||||||
|
|
||||||
@state() private _chartOptions?: ECOption;
|
@state() private _chartOptions?: ECOption;
|
||||||
|
|
||||||
|
private _hiddenStats = new Set<string>();
|
||||||
|
|
||||||
@state() private _yWidth = 25;
|
@state() private _yWidth = 25;
|
||||||
|
|
||||||
private _chartTime: Date = new Date();
|
private _chartTime: Date = new Date();
|
||||||
@ -84,6 +86,9 @@ export class StateHistoryChartLine extends LitElement {
|
|||||||
.options=${this._chartOptions}
|
.options=${this._chartOptions}
|
||||||
.height=${this.height}
|
.height=${this.height}
|
||||||
style=${styleMap({ height: this.height })}
|
style=${styleMap({ height: this.height })}
|
||||||
|
external-hidden
|
||||||
|
@dataset-hidden=${this._datasetHidden}
|
||||||
|
@dataset-unhidden=${this._datasetUnhidden}
|
||||||
></ha-chart-base>
|
></ha-chart-base>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -98,7 +103,11 @@ export class StateHistoryChartLine extends LitElement {
|
|||||||
) + "<br>";
|
) + "<br>";
|
||||||
const datapoints: Record<string, any>[] = [];
|
const datapoints: Record<string, any>[] = [];
|
||||||
this._chartData.forEach((dataset, index) => {
|
this._chartData.forEach((dataset, index) => {
|
||||||
if (dataset.tooltip?.show === false) return;
|
if (
|
||||||
|
dataset.tooltip?.show === false ||
|
||||||
|
this._hiddenStats.has(dataset.name as string)
|
||||||
|
)
|
||||||
|
return;
|
||||||
const param = params.find(
|
const param = params.find(
|
||||||
(p: Record<string, any>) => p.seriesIndex === index
|
(p: Record<string, any>) => p.seriesIndex === index
|
||||||
);
|
);
|
||||||
@ -162,6 +171,14 @@ export class StateHistoryChartLine extends LitElement {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _datasetHidden(ev: CustomEvent) {
|
||||||
|
this._hiddenStats.add(ev.detail.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _datasetUnhidden(ev: CustomEvent) {
|
||||||
|
this._hiddenStats.delete(ev.detail.name);
|
||||||
|
}
|
||||||
|
|
||||||
public willUpdate(changedProps: PropertyValues) {
|
public willUpdate(changedProps: PropertyValues) {
|
||||||
if (
|
if (
|
||||||
changedProps.has("data") ||
|
changedProps.has("data") ||
|
||||||
@ -264,6 +281,8 @@ export class StateHistoryChartLine extends LitElement {
|
|||||||
} as YAXisOption,
|
} as YAXisOption,
|
||||||
legend: {
|
legend: {
|
||||||
show: this.showNames,
|
show: this.showNames,
|
||||||
|
type: "scroll",
|
||||||
|
animationDurationUpdate: 400,
|
||||||
icon: "circle",
|
icon: "circle",
|
||||||
padding: [20, 0],
|
padding: [20, 0],
|
||||||
},
|
},
|
||||||
@ -632,7 +651,7 @@ export class StateHistoryChartLine extends LitElement {
|
|||||||
pushData(new Date(entityState.last_changed), series);
|
pushData(new Date(entityState.last_changed), series);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
addDataSet(this.showNames ? name : "");
|
addDataSet(name);
|
||||||
|
|
||||||
let lastValue: number;
|
let lastValue: number;
|
||||||
let lastDate: Date;
|
let lastDate: Date;
|
||||||
|
@ -279,6 +279,8 @@ export class StatisticsChart extends LitElement {
|
|||||||
},
|
},
|
||||||
legend: {
|
legend: {
|
||||||
show: !this.hideLegend,
|
show: !this.hideLegend,
|
||||||
|
type: "scroll",
|
||||||
|
animationDurationUpdate: 400,
|
||||||
icon: "circle",
|
icon: "circle",
|
||||||
padding: [20, 0],
|
padding: [20, 0],
|
||||||
data: this._legendData,
|
data: this._legendData,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user