mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 11:16:35 +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
8ee80586a8
commit
f7634c45c2
@ -9,6 +9,7 @@ import type {
|
|||||||
LegendComponentOption,
|
LegendComponentOption,
|
||||||
XAXisOption,
|
XAXisOption,
|
||||||
YAXisOption,
|
YAXisOption,
|
||||||
|
LineSeriesOption,
|
||||||
} from "echarts/types/dist/shared";
|
} from "echarts/types/dist/shared";
|
||||||
import type { PropertyValues } from "lit";
|
import type { PropertyValues } from "lit";
|
||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
@ -642,15 +643,16 @@ export class HaChartBase extends LitElement {
|
|||||||
const yAxis = (this.options?.yAxis?.[0] ?? this.options?.yAxis) as
|
const yAxis = (this.options?.yAxis?.[0] ?? this.options?.yAxis) as
|
||||||
| YAXisOption
|
| YAXisOption
|
||||||
| undefined;
|
| undefined;
|
||||||
const series = ensureArray(this.data)
|
const series = ensureArray(this.data).map((s) => {
|
||||||
.filter((d) => !this._hiddenDatasets.has(String(d.name ?? d.id)))
|
const data = this._hiddenDatasets.has(String(s.name ?? s.id))
|
||||||
.map((s) => {
|
? undefined
|
||||||
if (s.type === "line") {
|
: s.data;
|
||||||
|
if (data && s.type === "line") {
|
||||||
if (yAxis?.type === "log") {
|
if (yAxis?.type === "log") {
|
||||||
// set <=0 values to null so they render as gaps on a log graph
|
// set <=0 values to null so they render as gaps on a log graph
|
||||||
return {
|
return {
|
||||||
...s,
|
...s,
|
||||||
data: s.data?.map((v) =>
|
data: (data as LineSeriesOption["data"])!.map((v) =>
|
||||||
Array.isArray(v)
|
Array.isArray(v)
|
||||||
? [
|
? [
|
||||||
v[0],
|
v[0],
|
||||||
@ -663,23 +665,24 @@ export class HaChartBase extends LitElement {
|
|||||||
}
|
}
|
||||||
if (s.sampling === "minmax") {
|
if (s.sampling === "minmax") {
|
||||||
const minX =
|
const minX =
|
||||||
xAxis?.min && typeof xAxis.min === "number"
|
xAxis?.min && typeof xAxis.min === "number" ? xAxis.min : undefined;
|
||||||
? xAxis.min
|
|
||||||
: undefined;
|
|
||||||
const maxX =
|
const maxX =
|
||||||
xAxis?.max && typeof xAxis.max === "number"
|
xAxis?.max && typeof xAxis.max === "number" ? xAxis.max : undefined;
|
||||||
? xAxis.max
|
|
||||||
: undefined;
|
|
||||||
return {
|
return {
|
||||||
...s,
|
...s,
|
||||||
sampling: undefined,
|
sampling: undefined,
|
||||||
data: downSampleLineData(s.data, this.clientWidth, minX, maxX),
|
data: downSampleLineData(
|
||||||
|
data as LineSeriesOption["data"],
|
||||||
|
this.clientWidth,
|
||||||
|
minX,
|
||||||
|
maxX
|
||||||
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s;
|
return { ...s, data };
|
||||||
});
|
});
|
||||||
return series;
|
return series as ECOption["series"];
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getDefaultHeight() {
|
private _getDefaultHeight() {
|
||||||
|
@ -81,7 +81,6 @@ export class HuiEnergyDevicesDetailGraphCard
|
|||||||
key: this._config?.collection_key,
|
key: this._config?.collection_key,
|
||||||
}).subscribe((data) => {
|
}).subscribe((data) => {
|
||||||
this._data = data;
|
this._data = data;
|
||||||
this._processStatistics();
|
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -103,10 +102,7 @@ export class HuiEnergyDevicesDetailGraphCard
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected willUpdate(changedProps: PropertyValues) {
|
protected willUpdate(changedProps: PropertyValues) {
|
||||||
if (
|
if (changedProps.has("_config") || changedProps.has("_data")) {
|
||||||
(changedProps.has("_hiddenStats") || changedProps.has("_config")) &&
|
|
||||||
this._data
|
|
||||||
) {
|
|
||||||
this._processStatistics();
|
this._processStatistics();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,7 +202,10 @@ export class HuiEnergyDevicesDetailGraphCard
|
|||||||
);
|
);
|
||||||
|
|
||||||
private _processStatistics() {
|
private _processStatistics() {
|
||||||
const energyData = this._data!;
|
if (!this._data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const energyData = this._data;
|
||||||
|
|
||||||
this._start = energyData.start;
|
this._start = energyData.start;
|
||||||
this._end = energyData.end || endOfToday();
|
this._end = energyData.end || endOfToday();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user