Fix touch control of chart zoom (#23302)

* Fix touch control of chart zoom

* fix
This commit is contained in:
Petar Petrov 2024-12-16 17:03:32 +02:00 committed by GitHub
parent da7d3e118c
commit 7370d1e0dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View File

@ -67,6 +67,8 @@ export class HaChartBase extends LitElement {
@state() private _showZoomHint = false; @state() private _showZoomHint = false;
@state() private _isZoomed = false;
private _paddingUpdateCount = 0; private _paddingUpdateCount = 0;
private _paddingUpdateLock = false; private _paddingUpdateLock = false;
@ -266,7 +268,11 @@ export class HaChartBase extends LitElement {
})} })}
@wheel=${this._handleChartScroll} @wheel=${this._handleChartScroll}
> >
<canvas></canvas> <canvas
class=${classMap({
"not-zoomed": !this._isZoomed,
})}
></canvas>
<div <div
class="zoom-hint ${classMap({ class="zoom-hint ${classMap({
visible: this._showZoomHint, visible: this._showZoomHint,
@ -396,11 +402,14 @@ export class HaChartBase extends LitElement {
modifierKey, modifierKey,
}, },
mode: "x", mode: "x",
onZoomComplete: () => {
this._isZoomed = this.chart?.isZoomedOrPanned() ?? false;
},
}, },
limits: { limits: {
x: { x: {
min: "original", min: "original",
max: "original", max: (this.options?.scales?.x as any)?.max ?? "original",
}, },
y: { y: {
min: "original", min: "original",
@ -516,6 +525,10 @@ export class HaChartBase extends LitElement {
canvas { canvas {
max-height: var(--chart-max-height, 400px); max-height: var(--chart-max-height, 400px);
} }
canvas.not-zoomed {
/* allow scrolling if the chart is not zoomed */
touch-action: pan-y !important;
}
.chartLegend { .chartLegend {
text-align: center; text-align: center;
} }

View File

@ -113,7 +113,7 @@ export class StateHistoryChartLine extends LitElement {
}, },
}, },
min: this.startTime, min: this.startTime,
suggestedMax: this.endTime, max: this.endTime,
ticks: { ticks: {
maxRotation: 0, maxRotation: 0,
sampleSize: 5, sampleSize: 5,