Make Chart.controllers.* importable (#5871)

`controllers.*.js` and `core.datasetController.js` are now importable (no more function export), that's why there is so many changes mainly due to one indentation level removed. Split code for `bar/horizontalBar` and `doughnut/pie` in separate files, added a global controllers import (`src/controllers/index.js`) and add tests to check that all dataset controllers are correctly registered under `chart.controllers.{type}`.
This commit is contained in:
Simon Brunel
2018-11-29 21:06:34 +01:00
committed by GitHub
parent c84d249035
commit be8d78a900
20 changed files with 1607 additions and 1585 deletions

View File

@@ -2,6 +2,7 @@
var Animation = require('./core.animation');
var animations = require('./core.animations');
var controllers = require('../controllers/index');
var defaults = require('./core.defaults');
var helpers = require('../helpers/index');
var Interaction = require('./core.interaction');
@@ -20,9 +21,6 @@ module.exports = function(Chart) {
// Destroy method on the chart will remove the instance of the chart from this reference.
Chart.instances = {};
// Controllers available for dataset visualization eg. bar, line, slice, etc.
Chart.controllers = {};
/**
* Initializes the given config with global and chart default values.
*/
@@ -337,7 +335,7 @@ module.exports = function(Chart) {
meta.controller.updateIndex(datasetIndex);
meta.controller.linkScales();
} else {
var ControllerClass = Chart.controllers[meta.type];
var ControllerClass = controllers[meta.type];
if (ControllerClass === undefined) {
throw new Error('"' + meta.type + '" is not a chart type.');
}