| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import { each } from '../util/common';
- import Chart from '../chart/chart';
- Chart._Interactions = {};
- Chart.registerInteraction = function (type, constructor) {
- Chart._Interactions[type] = constructor;
- };
- Chart.getInteraction = function (type) {
- return Chart._Interactions[type];
- };
- Chart.prototype.interaction = function (type, cfg) {
- var interactions = this._interactions || {};
- if (interactions[type]) {
- // if reprated, destroy last
- interactions[type].destroy();
- }
- var Ctor = Chart.getInteraction(type);
- var interact = new Ctor(cfg, this);
- interactions[type] = interact;
- this._interactions = interactions;
- return this;
- };
- Chart.prototype.clearInteraction = function (type) {
- var interactions = this._interactions;
- if (!interactions) return;
- if (type) {
- interactions[type] && interactions[type].destroy();
- delete interactions[type];
- } else {
- each(interactions, function (interaction, key) {
- interaction.destroy();
- delete interactions[key];
- });
- }
- return this;
- };
- export default Chart;
|