swipe.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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');
  14. var UpdateScaleMixin = require('./mixin/update-scale');
  15. var Swipe = /*#__PURE__*/function (_Interaction) {
  16. (0, _inheritsLoose2["default"])(Swipe, _Interaction);
  17. var _super = _createSuper(Swipe);
  18. var _proto = Swipe.prototype;
  19. _proto.getDefaultCfg = function getDefaultCfg() {
  20. var defaultCfg = _Interaction.prototype.getDefaultCfg.call(this);
  21. defaultCfg = Util.mix({}, defaultCfg, {
  22. startEvent: 'touchstart',
  23. processEvent: 'swipe',
  24. endEvent: 'touchend',
  25. currentDeltaX: null,
  26. threshold: 10,
  27. // Minimal distance required before recognizing.
  28. velocity: 0.3,
  29. // Minimal velocity required before recognizing, unit is in px per ms.
  30. limitRange: {},
  31. _timestamp: 0,
  32. _panCumulativeDelta: 0,
  33. speed: 5
  34. });
  35. return defaultCfg;
  36. };
  37. function Swipe(cfg, chart) {
  38. var _this;
  39. _this = _Interaction.call(this, cfg, chart) || this;
  40. var self = (0, _assertThisInitialized2["default"])(_this);
  41. var hammer = self.hammer,
  42. threshold = self.threshold,
  43. velocity = self.velocity;
  44. if (hammer) {
  45. hammer.get('swipe').set({
  46. direction: 6,
  47. // only support horizontal
  48. threshold: threshold,
  49. velocity: velocity
  50. });
  51. }
  52. chart.registerPlugins([FilterPlugin, {
  53. changeData: function changeData() {
  54. self.limitRange = {};
  55. },
  56. clear: function clear() {
  57. self.limitRange = {};
  58. }
  59. }]);
  60. self.mode = 'x';
  61. Util.mix(self, UpdateScaleMixin, MoveMixin);
  62. return _this;
  63. }
  64. _proto.process = function process(e) {
  65. this.currentDeltaX = 0;
  66. this._handleMove(e);
  67. };
  68. _proto.end = function end() {
  69. this.currentDeltaX = null;
  70. this._panCumulativeDelta = 0;
  71. };
  72. return Swipe;
  73. }(Interaction);
  74. Chart.registerInteraction('swipe', Swipe);
  75. module.exports = Swipe;