FIx console errors in charts (#24048)

* FIx console errors in charts

* handle undefined unit_of_measurement
This commit is contained in:
Petar Petrov 2025-02-03 19:13:35 +02:00 committed by Bram Kragten
parent b263b74916
commit fcf655b0ec
4 changed files with 7 additions and 15 deletions

View File

@ -143,15 +143,7 @@ export class HaChartBase extends LitElement {
this.chart.setOption(this._createOptions(), {
lazyUpdate: true,
// if we replace the whole object, it will reset the dataZoom
replaceMerge: [
"xAxis",
"yAxis",
"dataZoom",
"dataset",
"tooltip",
"grid",
"visualMap",
],
replaceMerge: ["grid"],
});
}
}
@ -503,6 +495,7 @@ export class HaChartBase extends LitElement {
private _handleZoomReset() {
this.chart?.dispatchAction({ type: "dataZoom", start: 0, end: 100 });
this._modifierPressed = false;
}
private _handleWheel(e: WheelEvent) {

View File

@ -132,6 +132,7 @@ export class StateHistoryChartLine extends LitElement {
marker: `<span style="display:inline-block;margin-right:4px;border-radius:10px;width:10px;height:10px;background-color:${dataset.color};"></span>`,
});
});
const unit = this.unit ? ` ${this.unit}` : "";
return (
title +
datapoints
@ -143,7 +144,7 @@ export class StateHistoryChartLine extends LitElement {
undefined,
this.hass.entities[this._entityIds[param.seriesIndex]]
)
)} ${this.unit}`;
)}${unit}`;
const dataIndex = this._datasetToDataIndex[param.seriesIndex];
const data = this.data[dataIndex];
if (data.statistics && data.statistics.length > 0) {

View File

@ -186,6 +186,7 @@ export class StatisticsChart extends LitElement {
private _renderTooltip = (params: any) => {
const rendered: Record<string, boolean> = {};
const unit = this.unit ? ` ${this.unit}` : "";
return params
.map((param, index: number) => {
if (rendered[param.seriesName]) return "";
@ -198,7 +199,7 @@ export class StatisticsChart extends LitElement {
undefined,
this.hass.entities[this._statisticIds[param.seriesIndex]]
)
)} ${this.unit}`;
)}${unit}`;
const time =
index === 0

View File

@ -33,10 +33,7 @@ export const loggingMixin = <T extends Constructor<HassBaseEl>>(
ev.message.includes("ResizeObserver loop limit exceeded")) ||
ev.message.includes(
"ResizeObserver loop completed with undelivered notifications"
) ||
(ev.error.stack.includes("DataZoomModel") &&
(ev.message.includes("undefined") ||
ev.message.includes("Cannot read properties of null")))
)
) {
ev.preventDefault();
ev.stopImmediatePropagation();