Improve chart zoom (#23326)

This commit is contained in:
Petar Petrov 2024-12-18 16:50:34 +02:00 committed by GitHub
parent ba3d37b550
commit 8a46ef6168
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -372,6 +372,9 @@ export class HaChartBase extends LitElement {
const modifierKey = isMac ? "meta" : "ctrl"; const modifierKey = isMac ? "meta" : "ctrl";
return { return {
maintainAspectRatio: false, maintainAspectRatio: false,
animation: {
duration: 500,
},
...this.options, ...this.options,
plugins: { plugins: {
...this.options?.plugins, ...this.options?.plugins,
@ -396,14 +399,24 @@ export class HaChartBase extends LitElement {
drag: { drag: {
enabled: true, enabled: true,
modifierKey, modifierKey,
threshold: 2,
}, },
wheel: { wheel: {
enabled: true, enabled: true,
modifierKey, modifierKey,
speed: 0.05,
}, },
mode: "x", mode: "x",
onZoomComplete: () => { 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: { limits: {