| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
- var Util = require('../util/common');
- var Interaction = require('./base');
- var Chart = require('../chart/chart');
- var FilterPlugin = require('../plugin/filter');
- var MoveMixin = require('./mixin/move');
- var PressTooltipMixin = require('./mixin/press-tooltip');
- var UpdateScaleMixin = require('./mixin/update-scale');
- var Pan =
- /*#__PURE__*/
- function (_Interaction) {
- _inheritsLoose(Pan, _Interaction);
- var _proto = Pan.prototype;
- _proto.getDefaultCfg = function getDefaultCfg() {
- var defaultCfg = _Interaction.prototype.getDefaultCfg.call(this);
- defaultCfg = Util.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 (Util.isWx || Util.isMy) {
- // 小程序
- defaultCfg.startEvent = 'touchstart';
- defaultCfg.processEvent = 'touchmove';
- defaultCfg.endEvent = 'touchend';
- }
- return defaultCfg;
- };
- function Pan(cfg, chart) {
- var _this;
- _this = _Interaction.call(this, cfg, chart) || this;
- var self = _assertThisInitialized(_assertThisInitialized(_this));
- var hammer = self.hammer,
- panThreshold = self.panThreshold;
- if (hammer) {
- hammer.get('pan').set({
- threshold: panThreshold
- });
- }
- chart.registerPlugins([FilterPlugin, {
- changeData: function changeData() {
- self.limitRange = {};
- },
- clear: function clear() {
- self.limitRange = {};
- }
- }]);
- Util.mix(_assertThisInitialized(_assertThisInitialized(_this)), UpdateScaleMixin, MoveMixin, PressTooltipMixin);
- _this._bindPress();
- return _this;
- }
- _proto.start = function 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);
- };
- _proto.process = function process(e) {
- if (this.pressed) return;
- this._handleMove(e);
- };
- _proto.end = function end() {
- if (this.pressed) return;
- this.currentDeltaX = null;
- this.currentDeltaY = null;
- this.lastPoint = null;
- this._panCumulativeDelta = 0;
- };
- return Pan;
- }(Interaction);
- Chart.registerInteraction('pan', Pan);
- module.exports = Pan;
|