swipe.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 FilterPlugin = _interopRequireWildcard(require("../plugin/filter"));
  8. var _move = _interopRequireDefault(require("./mixin/move"));
  9. var _updateScale = _interopRequireDefault(require("./mixin/update-scale"));
  10. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
  11. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  13. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  15. var Swipe = /*#__PURE__*/function (_Interaction) {
  16. _inheritsLoose(Swipe, _Interaction);
  17. var _proto = Swipe.prototype;
  18. _proto.getDefaultCfg = function getDefaultCfg() {
  19. var defaultCfg = _Interaction.prototype.getDefaultCfg.call(this);
  20. defaultCfg = (0, _common.mix)({}, defaultCfg, {
  21. startEvent: 'touchstart',
  22. processEvent: 'swipe',
  23. endEvent: 'touchend',
  24. currentDeltaX: null,
  25. threshold: 10,
  26. // Minimal distance required before recognizing.
  27. velocity: 0.3,
  28. // Minimal velocity required before recognizing, unit is in px per ms.
  29. limitRange: {},
  30. _timestamp: 0,
  31. _panCumulativeDelta: 0,
  32. speed: 5
  33. });
  34. return defaultCfg;
  35. };
  36. function Swipe(cfg, chart) {
  37. var _this;
  38. _this = _Interaction.call(this, cfg, chart) || this;
  39. var self = _assertThisInitialized(_this);
  40. var hammer = self.hammer,
  41. threshold = self.threshold,
  42. velocity = self.velocity;
  43. if (hammer) {
  44. hammer.get('swipe').set({
  45. direction: 6,
  46. // only support horizontal
  47. threshold: threshold,
  48. velocity: velocity
  49. });
  50. }
  51. chart.registerPlugins([FilterPlugin, {
  52. changeData: function changeData() {
  53. self.limitRange = {};
  54. },
  55. clear: function clear() {
  56. self.limitRange = {};
  57. }
  58. }]);
  59. self.mode = 'x';
  60. (0, _common.mix)(self, _updateScale["default"], _move["default"]);
  61. return _this;
  62. }
  63. _proto.process = function process(e) {
  64. this.currentDeltaX = 0;
  65. this._handleMove(e);
  66. };
  67. _proto.end = function end() {
  68. this.currentDeltaX = null;
  69. this._panCumulativeDelta = 0;
  70. };
  71. return Swipe;
  72. }(_base["default"]);
  73. _chart["default"].registerInteraction('swipe', Swipe);
  74. var _default = Swipe;
  75. exports["default"] = _default;