pan.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. "use strict";
  2. exports.__esModule = true;
  3. exports["default"] = void 0;
  4. var _common = require("../util/common");
  5. var _base = _interopRequireDefault(require("./base"));
  6. var _chart = _interopRequireDefault(require("../chart/chart"));
  7. var _move = _interopRequireDefault(require("./mixin/move"));
  8. var _updateScale = _interopRequireDefault(require("./mixin/update-scale"));
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  10. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  12. var Pan = /*#__PURE__*/function (_Interaction) {
  13. _inheritsLoose(Pan, _Interaction);
  14. var _proto = Pan.prototype;
  15. _proto.getDefaultCfg = function getDefaultCfg() {
  16. var defaultCfg = _Interaction.prototype.getDefaultCfg.call(this);
  17. defaultCfg = (0, _common.mix)({}, defaultCfg, {
  18. startEvent: 'panstart',
  19. processEvent: 'panmove',
  20. endEvent: 'panend',
  21. resetEvent: 'touchend',
  22. mode: 'x',
  23. panThreshold: 10,
  24. // Minimal pan distance required before recognizing
  25. pressThreshold: 9,
  26. // Minimal movement that is allowed while pressing
  27. pressTime: 251,
  28. // Minimal press time in ms
  29. currentDeltaX: null,
  30. currentDeltaY: null,
  31. limitRange: {},
  32. _timestamp: 0,
  33. lastPoint: null,
  34. _panCumulativeDelta: 0,
  35. speed: 5
  36. });
  37. if (_common.isWx || _common.isMy) {
  38. // 小程序
  39. defaultCfg.startEvent = 'touchstart';
  40. defaultCfg.processEvent = 'touchmove';
  41. defaultCfg.endEvent = 'touchend';
  42. }
  43. return defaultCfg;
  44. };
  45. function Pan(cfg, chart) {
  46. var _this;
  47. _this = _Interaction.call(this, cfg, chart) || this;
  48. var self = _assertThisInitialized(_this);
  49. var hammer = self.hammer,
  50. panThreshold = self.panThreshold;
  51. chart.set('limitInPlot', true);
  52. if (hammer) {
  53. hammer.get('pan').set({
  54. threshold: panThreshold
  55. }); // 为了兼容hammer的pan 和 tooltips里的press, 后面去hammerjs的时候需要去掉
  56. chart.get('canvas').on('pan', function () {});
  57. } // chart.registerPlugins([ FilterPlugin, {
  58. // changeData() {
  59. // self.limitRange = {};
  60. // },
  61. // clear() {
  62. // self.limitRange = {};
  63. // }
  64. // }]);
  65. (0, _common.mix)(_assertThisInitialized(_this), _updateScale["default"], _move["default"]);
  66. return _this;
  67. }
  68. _proto.start = function start(e) {
  69. if (this.pressed) return;
  70. this.currentDeltaX = 0;
  71. this.currentDeltaY = 0;
  72. if (e.type === 'touchstart' || e.type === 'touchStart') {
  73. this.lastPoint = e.touches[0];
  74. }
  75. this._handleMove(e);
  76. };
  77. _proto.process = function process(e) {
  78. if (this.pressed) return;
  79. this._handleMove(e);
  80. };
  81. _proto.end = function end() {
  82. if (this.pressed) return;
  83. this.currentDeltaX = null;
  84. this.currentDeltaY = null;
  85. this.lastPoint = null;
  86. this._panCumulativeDelta = 0;
  87. };
  88. return Pan;
  89. }(_base["default"]);
  90. _chart["default"].registerInteraction('pan', Pan);
  91. var _default = Pan;
  92. exports["default"] = _default;