From ad487470fdee410be0707a48e0cab49c6c86e26c Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Wed, 19 Feb 2025 16:05:32 +0200 Subject: [PATCH] Enable downsampling in echarts (#24311) * Enable downsampling in echarts * remove unneeded symbol set --- src/components/chart/ha-chart-base.ts | 10 +++++----- src/components/chart/state-history-chart-line.ts | 5 +++-- src/components/chart/statistics-chart.ts | 5 ++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/chart/ha-chart-base.ts b/src/components/chart/ha-chart-base.ts index deb89d24d2..a87b7aa3a2 100644 --- a/src/components/chart/ha-chart-base.ts +++ b/src/components/chart/ha-chart-base.ts @@ -521,14 +521,14 @@ export class HaChartBase extends LitElement { 0 ); if (dataSize > 10000) { - // for large datasets zr.flush takes 30-40% of the render time - // so we delay it a bit to avoid blocking the main thread + // delay the last bit of the render to avoid blocking the main thread + // this is not that impactful with sampling enabled but it doesn't hurt to have it const zr = this.chart.getZr(); - this._originalZrFlush = zr.flush.bind(zr); + this._originalZrFlush = zr.flush; zr.flush = () => { setTimeout(() => { - this._originalZrFlush?.(); - }, 10); + this._originalZrFlush?.call(zr); + }, 5); }; } } diff --git a/src/components/chart/state-history-chart-line.ts b/src/components/chart/state-history-chart-line.ts index f7e60f7804..27de961e41 100644 --- a/src/components/chart/state-history-chart-line.ts +++ b/src/components/chart/state-history-chart-line.ts @@ -354,9 +354,10 @@ export class StateHistoryChartLine extends LitElement { name: nameY, color, symbol: "circle", - step: "end", - animationDurationUpdate: 0, symbolSize: 1, + step: "end", + sampling: "minmax", + animationDurationUpdate: 0, lineStyle: { width: fill ? 0 : 1.5, }, diff --git a/src/components/chart/statistics-chart.ts b/src/components/chart/statistics-chart.ts index 7954d76010..5c2372826c 100644 --- a/src/components/chart/statistics-chart.ts +++ b/src/components/chart/statistics-chart.ts @@ -492,8 +492,8 @@ export class StatisticsChart extends LitElement { : this.hass.localize( `ui.components.statistics_charts.statistic_types.${type}` ), - symbol: "circle", - symbolSize: 0, + symbol: "none", + sampling: "minmax", animationDurationUpdate: 0, lineStyle: { width: 1.5, @@ -511,7 +511,6 @@ export class StatisticsChart extends LitElement { if (band && this.chartType === "line") { series.stack = `band-${statistic_id}`; series.stackStrategy = "all"; - (series as LineSeriesOption).symbol = "none"; if (drawBands && type === "max") { (series as LineSeriesOption).areaStyle = { color: color + "3F",