From fcf655b0ec173e7f405e724f7eeb762fcd1a2e65 Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Mon, 3 Feb 2025 19:13:35 +0200 Subject: [PATCH] FIx console errors in charts (#24048) * FIx console errors in charts * handle undefined unit_of_measurement --- src/components/chart/ha-chart-base.ts | 11 ++--------- src/components/chart/state-history-chart-line.ts | 3 ++- src/components/chart/statistics-chart.ts | 3 ++- src/state/logging-mixin.ts | 5 +---- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/components/chart/ha-chart-base.ts b/src/components/chart/ha-chart-base.ts index 32e7f729eb..e83bb757a8 100644 --- a/src/components/chart/ha-chart-base.ts +++ b/src/components/chart/ha-chart-base.ts @@ -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) { diff --git a/src/components/chart/state-history-chart-line.ts b/src/components/chart/state-history-chart-line.ts index be9e71e845..2afbc7f3bd 100644 --- a/src/components/chart/state-history-chart-line.ts +++ b/src/components/chart/state-history-chart-line.ts @@ -132,6 +132,7 @@ export class StateHistoryChartLine extends LitElement { marker: ``, }); }); + 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) { diff --git a/src/components/chart/statistics-chart.ts b/src/components/chart/statistics-chart.ts index 62090d23ac..05eb8fe654 100644 --- a/src/components/chart/statistics-chart.ts +++ b/src/components/chart/statistics-chart.ts @@ -186,6 +186,7 @@ export class StatisticsChart extends LitElement { private _renderTooltip = (params: any) => { const rendered: Record = {}; + 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 diff --git a/src/state/logging-mixin.ts b/src/state/logging-mixin.ts index 4a14a441af..8ba4b630b3 100644 --- a/src/state/logging-mixin.ts +++ b/src/state/logging-mixin.ts @@ -33,10 +33,7 @@ export const loggingMixin = >( 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();