register.js 1.2 KB

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