mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 17:56:46 +00:00
Fix bar chart data order when using the legend (#25832)
* Fix bar chart data order when using the legend * type fix
This commit is contained in:
parent
51246f119c
commit
7f7e693547
@ -9,6 +9,7 @@ import type {
|
||||
LegendComponentOption,
|
||||
XAXisOption,
|
||||
YAXisOption,
|
||||
LineSeriesOption,
|
||||
} from "echarts/types/dist/shared";
|
||||
import type { PropertyValues } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
@ -642,44 +643,46 @@ export class HaChartBase extends LitElement {
|
||||
const yAxis = (this.options?.yAxis?.[0] ?? this.options?.yAxis) as
|
||||
| YAXisOption
|
||||
| undefined;
|
||||
const series = ensureArray(this.data)
|
||||
.filter((d) => !this._hiddenDatasets.has(String(d.name ?? d.id)))
|
||||
.map((s) => {
|
||||
if (s.type === "line") {
|
||||
if (yAxis?.type === "log") {
|
||||
// set <=0 values to null so they render as gaps on a log graph
|
||||
return {
|
||||
...s,
|
||||
data: s.data?.map((v) =>
|
||||
Array.isArray(v)
|
||||
? [
|
||||
v[0],
|
||||
typeof v[1] !== "number" || v[1] > 0 ? v[1] : null,
|
||||
...v.slice(2),
|
||||
]
|
||||
: v
|
||||
),
|
||||
};
|
||||
}
|
||||
if (s.sampling === "minmax") {
|
||||
const minX =
|
||||
xAxis?.min && typeof xAxis.min === "number"
|
||||
? xAxis.min
|
||||
: undefined;
|
||||
const maxX =
|
||||
xAxis?.max && typeof xAxis.max === "number"
|
||||
? xAxis.max
|
||||
: undefined;
|
||||
return {
|
||||
...s,
|
||||
sampling: undefined,
|
||||
data: downSampleLineData(s.data, this.clientWidth, minX, maxX),
|
||||
};
|
||||
}
|
||||
const series = ensureArray(this.data).map((s) => {
|
||||
const data = this._hiddenDatasets.has(String(s.name ?? s.id))
|
||||
? undefined
|
||||
: s.data;
|
||||
if (data && s.type === "line") {
|
||||
if (yAxis?.type === "log") {
|
||||
// set <=0 values to null so they render as gaps on a log graph
|
||||
return {
|
||||
...s,
|
||||
data: (data as LineSeriesOption["data"])!.map((v) =>
|
||||
Array.isArray(v)
|
||||
? [
|
||||
v[0],
|
||||
typeof v[1] !== "number" || v[1] > 0 ? v[1] : null,
|
||||
...v.slice(2),
|
||||
]
|
||||
: v
|
||||
),
|
||||
};
|
||||
}
|
||||
return s;
|
||||
});
|
||||
return series;
|
||||
if (s.sampling === "minmax") {
|
||||
const minX =
|
||||
xAxis?.min && typeof xAxis.min === "number" ? xAxis.min : undefined;
|
||||
const maxX =
|
||||
xAxis?.max && typeof xAxis.max === "number" ? xAxis.max : undefined;
|
||||
return {
|
||||
...s,
|
||||
sampling: undefined,
|
||||
data: downSampleLineData(
|
||||
data as LineSeriesOption["data"],
|
||||
this.clientWidth,
|
||||
minX,
|
||||
maxX
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
return { ...s, data };
|
||||
});
|
||||
return series as ECOption["series"];
|
||||
}
|
||||
|
||||
private _getDefaultHeight() {
|
||||
|
@ -81,7 +81,6 @@ export class HuiEnergyDevicesDetailGraphCard
|
||||
key: this._config?.collection_key,
|
||||
}).subscribe((data) => {
|
||||
this._data = data;
|
||||
this._processStatistics();
|
||||
}),
|
||||
];
|
||||
}
|
||||
@ -103,10 +102,7 @@ export class HuiEnergyDevicesDetailGraphCard
|
||||
}
|
||||
|
||||
protected willUpdate(changedProps: PropertyValues) {
|
||||
if (
|
||||
(changedProps.has("_hiddenStats") || changedProps.has("_config")) &&
|
||||
this._data
|
||||
) {
|
||||
if (changedProps.has("_config") || changedProps.has("_data")) {
|
||||
this._processStatistics();
|
||||
}
|
||||
}
|
||||
@ -206,7 +202,10 @@ export class HuiEnergyDevicesDetailGraphCard
|
||||
);
|
||||
|
||||
private _processStatistics() {
|
||||
const energyData = this._data!;
|
||||
if (!this._data) {
|
||||
return;
|
||||
}
|
||||
const energyData = this._data;
|
||||
|
||||
this._start = energyData.start;
|
||||
this._end = energyData.end || endOfToday();
|
||||
|
Loading…
x
Reference in New Issue
Block a user