| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import { mix, isWx, isMy } from '../util/common';
- import Interaction from './base';
- import Chart from '../chart/chart'; // import * as FilterPlugin from '../plugin/filter';
- import MoveMixin from './mixin/move';
- import UpdateScaleMixin from './mixin/update-scale';
- class Pan extends Interaction {
- getDefaultCfg() {
- var defaultCfg = super.getDefaultCfg();
- defaultCfg = mix({}, defaultCfg, {
- startEvent: 'panstart',
- processEvent: 'panmove',
- endEvent: 'panend',
- resetEvent: 'touchend',
- mode: 'x',
- panThreshold: 10,
- // Minimal pan distance required before recognizing
- pressThreshold: 9,
- // Minimal movement that is allowed while pressing
- pressTime: 251,
- // Minimal press time in ms
- currentDeltaX: null,
- currentDeltaY: null,
- limitRange: {},
- _timestamp: 0,
- lastPoint: null,
- _panCumulativeDelta: 0,
- speed: 5
- });
- if (isWx || isMy) {
- // 小程序
- defaultCfg.startEvent = 'touchstart';
- defaultCfg.processEvent = 'touchmove';
- defaultCfg.endEvent = 'touchend';
- }
- return defaultCfg;
- }
- constructor(cfg, chart) {
- super(cfg, chart);
- var self = this;
- var {
- hammer,
- panThreshold
- } = self;
- chart.set('limitInPlot', true);
- if (hammer) {
- hammer.get('pan').set({
- threshold: panThreshold
- }); // 为了兼容hammer的pan 和 tooltips里的press, 后面去hammerjs的时候需要去掉
- chart.get('canvas').on('pan', function () {});
- } // chart.registerPlugins([ FilterPlugin, {
- // changeData() {
- // self.limitRange = {};
- // },
- // clear() {
- // self.limitRange = {};
- // }
- // }]);
- mix(this, UpdateScaleMixin, MoveMixin);
- }
- start(e) {
- if (this.pressed) return;
- this.currentDeltaX = 0;
- this.currentDeltaY = 0;
- if (e.type === 'touchstart' || e.type === 'touchStart') {
- this.lastPoint = e.touches[0];
- }
- this._handleMove(e);
- }
- process(e) {
- if (this.pressed) return;
- this._handleMove(e);
- }
- end() {
- if (this.pressed) return;
- this.currentDeltaX = null;
- this.currentDeltaY = null;
- this.lastPoint = null;
- this._panCumulativeDelta = 0;
- }
- }
- Chart.registerInteraction('pan', Pan);
- export default Pan;
|