From 8a46ef61685042c90d7312682efb759b569453ff Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Wed, 18 Dec 2024 16:50:34 +0200 Subject: [PATCH] Improve chart zoom (#23326) --- src/components/chart/ha-chart-base.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/chart/ha-chart-base.ts b/src/components/chart/ha-chart-base.ts index 2ad97fa04c..8bf720f65b 100644 --- a/src/components/chart/ha-chart-base.ts +++ b/src/components/chart/ha-chart-base.ts @@ -372,6 +372,9 @@ export class HaChartBase extends LitElement { const modifierKey = isMac ? "meta" : "ctrl"; return { maintainAspectRatio: false, + animation: { + duration: 500, + }, ...this.options, plugins: { ...this.options?.plugins, @@ -396,14 +399,24 @@ export class HaChartBase extends LitElement { drag: { enabled: true, modifierKey, + threshold: 2, }, wheel: { enabled: true, modifierKey, + speed: 0.05, }, mode: "x", onZoomComplete: () => { - this._isZoomed = this.chart?.isZoomedOrPanned() ?? false; + const isZoomed = this.chart?.isZoomedOrPanned() ?? false; + if (this._isZoomed && !isZoomed) { + setTimeout(() => { + // make sure the scales are properly reset after full zoom out + // they get bugged when zooming in/out multiple times and panning + this.chart?.resetZoom(); + }); + } + this._isZoomed = isZoomed; }, }, limits: {