register.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. exports.__esModule = true;
  3. exports["default"] = void 0;
  4. var _common = require("../util/common");
  5. var _chart = _interopRequireDefault(require("../chart/chart"));
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  7. _chart["default"]._Interactions = {};
  8. _chart["default"].registerInteraction = function (type, constructor) {
  9. _chart["default"]._Interactions[type] = constructor;
  10. };
  11. _chart["default"].getInteraction = function (type) {
  12. return _chart["default"]._Interactions[type];
  13. };
  14. _chart["default"].prototype.interaction = function (type, cfg) {
  15. var interactions = this._interactions || {};
  16. if (interactions[type]) {
  17. // if reprated, destroy last
  18. interactions[type].destroy();
  19. }
  20. var Ctor = _chart["default"].getInteraction(type);
  21. var interact = new Ctor(cfg, this);
  22. interactions[type] = interact;
  23. this._interactions = interactions;
  24. return this;
  25. };
  26. _chart["default"].prototype.clearInteraction = function (type) {
  27. var interactions = this._interactions;
  28. if (!interactions) return;
  29. if (type) {
  30. interactions[type] && interactions[type].destroy();
  31. delete interactions[type];
  32. } else {
  33. (0, _common.each)(interactions, function (interaction, key) {
  34. interaction.destroy();
  35. delete interactions[key];
  36. });
  37. }
  38. return this;
  39. };
  40. var _default = _chart["default"];
  41. exports["default"] = _default;