base.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. "use strict";
  2. exports.__esModule = true;
  3. exports["default"] = void 0;
  4. var _common = require("../../util/common");
  5. var _context = _interopRequireDefault(require("./context"));
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  7. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  8. var Base = /*#__PURE__*/function () {
  9. var _proto = Base.prototype;
  10. // 交互的上下文
  11. _proto.getDefaultCfg = function getDefaultCfg() {
  12. return {};
  13. };
  14. _proto.getInteractionContext = function getInteractionContext(chart) {
  15. var interactionContext = chart.get('interactionContext');
  16. if (interactionContext) {
  17. return interactionContext;
  18. }
  19. interactionContext = new _context["default"](chart);
  20. chart.set('interactionContext', interactionContext);
  21. return interactionContext;
  22. };
  23. function Base(cfg, chart) {
  24. var _this = this;
  25. _defineProperty(this, "type", '');
  26. _defineProperty(this, "startEvent", 'touchstart');
  27. _defineProperty(this, "processEvent", 'touchmove');
  28. _defineProperty(this, "endEvent", 'touchend');
  29. _defineProperty(this, "resetEvent", null);
  30. _defineProperty(this, "context", null);
  31. _defineProperty(this, "_start", function (ev) {
  32. _this.preStart && _this.preStart(ev);
  33. _this.start(ev);
  34. _this.onStart && _this.onStart(ev);
  35. });
  36. _defineProperty(this, "_process", function (ev) {
  37. _this.preProcess && _this.preProcess(ev);
  38. _this.process(ev);
  39. _this.onProcess && _this.onProcess(ev);
  40. });
  41. _defineProperty(this, "_end", function (ev) {
  42. _this.preEnd && _this.preEnd(ev);
  43. _this.end(ev);
  44. _this.onEnd && _this.onEnd(ev);
  45. });
  46. _defineProperty(this, "_reset", function (ev) {
  47. _this.preReset && _this.preReset(ev);
  48. _this.reset(ev);
  49. _this.onReset && _this.onReset(ev);
  50. });
  51. (0, _common.mix)(this, this.getDefaultCfg(), cfg);
  52. this.context = this.getInteractionContext(chart);
  53. this.chart = chart; // 只处理range, 暂时先这么处理后面再看情况调整
  54. var range = this.range;
  55. if (range) {
  56. this.context.range = range;
  57. }
  58. this._bindEvents(chart);
  59. }
  60. _proto._bindEvents = function _bindEvents(chart) {
  61. var startEvent = this.startEvent,
  62. processEvent = this.processEvent,
  63. endEvent = this.endEvent,
  64. resetEvent = this.resetEvent;
  65. var canvas = chart.get('canvas'); // 统一绑定事件
  66. canvas.on(startEvent, this._start);
  67. canvas.on(processEvent, this._process);
  68. canvas.on(endEvent, this._end);
  69. canvas.on(resetEvent, this._reset);
  70. };
  71. _proto._clearEvents = function _clearEvents() {
  72. var chart = this.chart,
  73. startEvent = this.startEvent,
  74. processEvent = this.processEvent,
  75. endEvent = this.endEvent,
  76. resetEvent = this.resetEvent;
  77. var canvas = chart.get('canvas'); // 统一绑定事件
  78. canvas.off(startEvent, this._start);
  79. canvas.off(processEvent, this._process);
  80. canvas.off(endEvent, this._end);
  81. canvas.off(resetEvent, this._start);
  82. };
  83. // override
  84. _proto.start = function start() {} // override
  85. ;
  86. _proto.process = function process() {} // override
  87. ;
  88. _proto.end = function end() {} // override
  89. ;
  90. _proto.reset = function reset() {};
  91. _proto.destroy = function destroy() {
  92. this.context.destroy();
  93. this._clearEvents();
  94. };
  95. return Base;
  96. }();
  97. var _default = Base;
  98. exports["default"] = _default;