Skip to content

Commit

Permalink
fix: 修复panstart时图表的跳动问题 (#1213)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue committed Sep 28, 2021
1 parent 2aec518 commit fd31f03
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/interaction/mixin/move.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { each, isNil, uniq, directionEnabled } from '../../util/common';
import { each, isNil, uniq, directionEnabled, isNumber } from '../../util/common';
import { getLimitRange, getFieldRange } from '../helper';
import { getTickMethod } from '../../scale';

Expand All @@ -12,6 +12,15 @@ const TOUCH_EVENTS = [
];
const DAY_TIMESTAMPS = 86400000;

function convertPoints(point) {
const { x, y, clientX, clientY } = point;
// 小程序环境会有x,y
if (isNumber(x) || isNumber(y)) {
return { x, y };
}
return { x: clientX, y: clientY };
}

function _handleMove(e) {
if (e.type === 'swipe' && e.deltaTime > 350) { // 区分 pan 操作和 swipe 操作
return null;
Expand All @@ -21,8 +30,10 @@ function _handleMove(e) {
let deltaY;
if (TOUCH_EVENTS.indexOf(e.type) !== -1) { // support touch and miniprogram
const currentPoint = e.touches[0];
deltaX = currentPoint.x - lastPoint.x;
deltaY = currentPoint.y - lastPoint.y;
const deltaLastPoint = convertPoints(lastPoint);
const deltaCurrentPoint = convertPoints(currentPoint);
deltaX = deltaCurrentPoint.x - deltaLastPoint.x;
deltaY = deltaCurrentPoint.y - deltaLastPoint.y;
this.lastPoint = currentPoint;
} else if (currentDeltaX !== null && currentDeltaY !== null) {
deltaX = e.deltaX - currentDeltaX;
Expand Down
2 changes: 1 addition & 1 deletion src/interaction/pan.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Pan extends Interaction {
if (e.type === 'touchstart' || e.type === 'touchStart') {
this.lastPoint = e.touches[0];
}
this._handleMove(e);
// this._handleMove(e);
}

process(e) {
Expand Down

0 comments on commit fd31f03

Please sign in to comment.