Make Chart.defaults/Ticks/Interaction importable (#4512)

Default options can now be accessed by importing `core/core.defaults`. The returned object acts as a singleton and is populated when importing classes that expose their own default values (meaning that importing only `code.defaults` results in an empty object). Also make `Chart.Ticks` and `Chart.Interaction` importable since existing defaults rely on these values.

Add the `defaults._set` method that make easier declaring new defaults by merging given values with existing ones for a specific scope (`global`, `scale`, `bar`, etc).
This commit is contained in:
Simon Brunel
2017-07-16 19:38:19 +02:00
committed by GitHub
parent 1833614e1d
commit 889ecd560b
32 changed files with 1154 additions and 1097 deletions

View File

@@ -1,6 +1,8 @@
'use strict';
var defaults = require('./core.defaults');
var helpers = require('../helpers/index');
var Interaction = require('./core.interaction');
var platform = require('../platforms/platform');
module.exports = function(Chart) {
@@ -29,8 +31,8 @@ module.exports = function(Chart) {
data.labels = data.labels || [];
config.options = helpers.configMerge(
Chart.defaults.global,
Chart.defaults[config.type],
defaults.global,
defaults[config.type],
config.options || {});
return config;
@@ -601,19 +603,19 @@ module.exports = function(Chart) {
// Get the single element that was clicked on
// @return : An object containing the dataset index and element index of the matching element. Also contains the rectangle that was draw
getElementAtEvent: function(e) {
return Chart.Interaction.modes.single(this, e);
return Interaction.modes.single(this, e);
},
getElementsAtEvent: function(e) {
return Chart.Interaction.modes.label(this, e, {intersect: true});
return Interaction.modes.label(this, e, {intersect: true});
},
getElementsAtXAxis: function(e) {
return Chart.Interaction.modes['x-axis'](this, e, {intersect: true});
return Interaction.modes['x-axis'](this, e, {intersect: true});
},
getElementsAtEventForMode: function(e, mode, options) {
var method = Chart.Interaction.modes[mode];
var method = Interaction.modes[mode];
if (typeof method === 'function') {
return method(this, e, options);
}
@@ -622,7 +624,7 @@ module.exports = function(Chart) {
},
getDatasetAtEvent: function(e) {
return Chart.Interaction.modes.dataset(this, e, {intersect: true});
return Interaction.modes.dataset(this, e, {intersect: true});
},
getDatasetMeta: function(datasetIndex) {