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

View File

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