2016-04-17 18:02:33 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
module.exports = function(Chart) {
|
|
|
|
var helpers = Chart.helpers;
|
|
|
|
|
|
|
|
// Plugins are stored here
|
|
|
|
Chart.plugins = [];
|
|
|
|
Chart.pluginService = {
|
|
|
|
// Register a new plugin
|
|
|
|
register: function(plugin) {
|
2016-05-05 01:35:01 +02:00
|
|
|
var p = Chart.plugins;
|
|
|
|
if (p.indexOf(plugin) === -1) {
|
|
|
|
p.push(plugin);
|
2016-04-17 18:02:33 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Remove a registered plugin
|
|
|
|
remove: function(plugin) {
|
2016-05-05 01:35:01 +02:00
|
|
|
var p = Chart.plugins;
|
|
|
|
var idx = p.indexOf(plugin);
|
2016-04-17 18:02:33 +02:00
|
|
|
if (idx !== -1) {
|
2016-05-05 01:35:01 +02:00
|
|
|
p.splice(idx, 1);
|
2016-04-17 18:02:33 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Iterate over all plugins
|
2016-04-17 18:25:47 +02:00
|
|
|
notifyPlugins: function(method, args, scope) {
|
2016-04-17 18:02:33 +02:00
|
|
|
helpers.each(Chart.plugins, function(plugin) {
|
|
|
|
if (plugin[method] && typeof plugin[method] === 'function') {
|
2016-04-17 18:25:47 +02:00
|
|
|
plugin[method].apply(scope, args);
|
2016-04-17 18:02:33 +02:00
|
|
|
}
|
|
|
|
}, scope);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-05 01:35:01 +02:00
|
|
|
var noop = helpers.noop;
|
2016-04-17 18:02:33 +02:00
|
|
|
Chart.PluginBase = Chart.Element.extend({
|
|
|
|
// Plugin methods. All functions are passed the chart instance
|
|
|
|
|
|
|
|
// Called at start of chart init
|
2016-05-05 01:35:01 +02:00
|
|
|
beforeInit: noop,
|
2016-04-17 18:02:33 +02:00
|
|
|
|
|
|
|
// Called at end of chart init
|
2016-05-05 01:35:01 +02:00
|
|
|
afterInit: noop,
|
2016-04-17 18:02:33 +02:00
|
|
|
|
|
|
|
// Called at start of update
|
2016-05-05 01:35:01 +02:00
|
|
|
beforeUpdate: noop,
|
2016-04-17 18:02:33 +02:00
|
|
|
|
|
|
|
// Called at end of update
|
2016-05-05 01:35:01 +02:00
|
|
|
afterUpdate: noop,
|
2016-04-17 18:02:33 +02:00
|
|
|
|
|
|
|
// Called at start of draw
|
2016-05-05 01:35:01 +02:00
|
|
|
beforeDraw: noop,
|
2016-04-17 18:02:33 +02:00
|
|
|
|
|
|
|
// Called at end of draw
|
2016-05-05 01:35:01 +02:00
|
|
|
afterDraw: noop,
|
2016-04-18 00:55:20 +02:00
|
|
|
|
|
|
|
// Called during destroy
|
2016-05-05 01:35:01 +02:00
|
|
|
destroy: noop,
|
2016-04-17 18:02:33 +02:00
|
|
|
});
|
2016-04-21 17:25:37 +02:00
|
|
|
};
|