pan.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  2. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  3. var Util = require('../util/common');
  4. var Interaction = require('./base');
  5. var Chart = require('../chart/chart');
  6. var FilterPlugin = require('../plugin/filter');
  7. var MoveMixin = require('./mixin/move');
  8. var PressTooltipMixin = require('./mixin/press-tooltip');
  9. var UpdateScaleMixin = require('./mixin/update-scale');
  10. var Pan =
  11. /*#__PURE__*/
  12. 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 = Util.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 (Util.isWx || Util.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(_assertThisInitialized(_this));
  49. var hammer = self.hammer,
  50. panThreshold = self.panThreshold;
  51. if (hammer) {
  52. hammer.get('pan').set({
  53. threshold: panThreshold
  54. });
  55. }
  56. chart.registerPlugins([FilterPlugin, {
  57. changeData: function changeData() {
  58. self.limitRange = {};
  59. },
  60. clear: function clear() {
  61. self.limitRange = {};
  62. }
  63. }]);
  64. Util.mix(_assertThisInitialized(_assertThisInitialized(_this)), UpdateScaleMixin, MoveMixin, PressTooltipMixin);
  65. _this._bindPress();
  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. }(Interaction);
  90. Chart.registerInteraction('pan', Pan);
  91. module.exports = Pan;