pan.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
  4. var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
  5. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  6. var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
  7. function _createSuper(Derived) { return function () { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
  8. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  9. var Util = require('../util/common');
  10. var Interaction = require('./base');
  11. var Chart = require('../chart/chart');
  12. var FilterPlugin = require('../plugin/filter');
  13. var MoveMixin = require('./mixin/move'); // const PressTooltipMixin = require('./mixin/press-tooltip');
  14. var UpdateScaleMixin = require('./mixin/update-scale');
  15. var Pan = /*#__PURE__*/function (_Interaction) {
  16. (0, _inheritsLoose2["default"])(Pan, _Interaction);
  17. var _super = _createSuper(Pan);
  18. var _proto = Pan.prototype;
  19. _proto.getDefaultCfg = function getDefaultCfg() {
  20. var defaultCfg = _Interaction.prototype.getDefaultCfg.call(this);
  21. defaultCfg = Util.mix({}, defaultCfg, {
  22. startEvent: 'panstart',
  23. processEvent: 'panmove',
  24. endEvent: 'panend',
  25. resetEvent: 'touchend',
  26. mode: 'x',
  27. panThreshold: 10,
  28. // Minimal pan distance required before recognizing
  29. pressThreshold: 9,
  30. // Minimal movement that is allowed while pressing
  31. pressTime: 251,
  32. // Minimal press time in ms
  33. currentDeltaX: null,
  34. currentDeltaY: null,
  35. limitRange: {},
  36. _timestamp: 0,
  37. lastPoint: null,
  38. _panCumulativeDelta: 0,
  39. speed: 5
  40. });
  41. if (Util.isWx || Util.isMy) {
  42. // 小程序
  43. defaultCfg.startEvent = 'touchstart';
  44. defaultCfg.processEvent = 'touchmove';
  45. defaultCfg.endEvent = 'touchend';
  46. }
  47. return defaultCfg;
  48. };
  49. function Pan(cfg, chart) {
  50. var _this;
  51. _this = _Interaction.call(this, cfg, chart) || this;
  52. var self = (0, _assertThisInitialized2["default"])(_this);
  53. var hammer = self.hammer,
  54. panThreshold = self.panThreshold;
  55. if (hammer) {
  56. hammer.get('pan').set({
  57. threshold: panThreshold
  58. }); // 为了兼容hammer的pan 和 tooltips里的press, 后面去hammerjs的时候需要去掉
  59. chart.get('canvas').on('pan', function () {});
  60. }
  61. chart.registerPlugins([FilterPlugin, {
  62. changeData: function changeData() {
  63. self.limitRange = {};
  64. },
  65. clear: function clear() {
  66. self.limitRange = {};
  67. }
  68. }]);
  69. Util.mix((0, _assertThisInitialized2["default"])(_this), UpdateScaleMixin, MoveMixin);
  70. return _this;
  71. }
  72. _proto.start = function start(e) {
  73. if (this.pressed) return;
  74. this.currentDeltaX = 0;
  75. this.currentDeltaY = 0;
  76. if (e.type === 'touchstart' || e.type === 'touchStart') {
  77. this.lastPoint = e.touches[0];
  78. }
  79. this._handleMove(e);
  80. };
  81. _proto.process = function process(e) {
  82. if (this.pressed) return;
  83. this._handleMove(e);
  84. };
  85. _proto.end = function end() {
  86. if (this.pressed) return;
  87. this.currentDeltaX = null;
  88. this.currentDeltaY = null;
  89. this.lastPoint = null;
  90. this._panCumulativeDelta = 0;
  91. };
  92. return Pan;
  93. }(Interaction);
  94. Chart.registerInteraction('pan', Pan);
  95. module.exports = Pan;