Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed mobile touch issue in pan zoom selection #4240

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/modules/ZoomPanSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Scales from './Scales'
export default class ZoomPanSelection extends Toolbar {
constructor(ctx) {
super(ctx)

this.ctx = ctx
this.w = ctx.w

Expand Down Expand Up @@ -157,9 +156,8 @@ export default class ZoomPanSelection extends Toolbar {
? e.changedTouches[0].clientY
: e.clientY

if (e.type === 'mousedown' && e.which === 1) {
if ((e.type === 'mousedown' || e.type === 'touchmove') && e.which === 1) {
let gridRectDim = me.gridRect.getBoundingClientRect()

me.startX = me.clientX - gridRectDim.left
me.startY = me.clientY - gridRectDim.top

Expand All @@ -172,14 +170,30 @@ export default class ZoomPanSelection extends Toolbar {

if (w.globals.panEnabled) {
w.globals.selection = null
if (me.w.globals.mousedown) {
if (me.w.globals.mousedown || e.type === 'touchmove') {
if (e.type === 'touchmove' && !me.w.globals.mousedown) {
console.warn('me.w.globals.mousedown ', me.w.globals.mousedown)
let gridRectDim = me.gridRect.getBoundingClientRect()
me.startX = me.clientX - gridRectDim.left
me.startY = me.clientY - gridRectDim.top
me.w.globals.mousedown = true
}

me.panDragging({
context: me,
zoomtype,
xyRatios,
})
}
} else {
if (e.type === 'touchmove') {
if (!me.w.globals.mousedown) {
let gridRectDim = me.gridRect.getBoundingClientRect()
me.startX = me.clientX - gridRectDim.left
me.startY = me.clientY - gridRectDim.top
}
me.w.globals.mousedown = true
}
if (
(me.w.globals.mousedown && w.globals.zoomEnabled) ||
(me.w.globals.mousedown && w.globals.selectionEnabled)
Expand Down Expand Up @@ -667,7 +681,6 @@ export default class ZoomPanSelection extends Toolbar {
panDragging({ context }) {
const w = this.w
let me = context

// check to make sure there is data to compare against
if (typeof w.globals.lastClientPosition.x !== 'undefined') {
// get the change from last position to this position
Expand All @@ -685,17 +698,14 @@ export default class ZoomPanSelection extends Toolbar {
this.moveDirection = 'down'
}
}

// set the new last position to the current for next time (to get the position of drag)
w.globals.lastClientPosition = {
x: me.clientX,
y: me.clientY,
}

let xLowestValue = w.globals.isRangeBar ? w.globals.minY : w.globals.minX

let xHighestValue = w.globals.isRangeBar ? w.globals.maxY : w.globals.maxX

// on a category, we don't pan continuosly as it causes bugs
if (!w.config.xaxis.convertedCatToNumeric) {
me.panScrolled(xLowestValue, xHighestValue)
Expand Down