Skip to content

Commit

Permalink
Fix touch control of chart zoom (#23302)
Browse files Browse the repository at this point in the history
* Fix touch control of chart zoom

* fix
  • Loading branch information
MindFreeze authored Dec 16, 2024
1 parent da7d3e1 commit 7370d1e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/components/chart/ha-chart-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export class HaChartBase extends LitElement {

@state() private _showZoomHint = false;

@state() private _isZoomed = false;

private _paddingUpdateCount = 0;

private _paddingUpdateLock = false;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/chart/state-history-chart-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class StateHistoryChartLine extends LitElement {
},
},
min: this.startTime,
suggestedMax: this.endTime,
max: this.endTime,
ticks: {
maxRotation: 0,
sampleSize: 5,
Expand Down

0 comments on commit 7370d1e

Please sign in to comment.