mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
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).
46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
var defaults = require('./core.defaults');
|
|
var helpers = require('../helpers/index');
|
|
|
|
module.exports = function(Chart) {
|
|
|
|
Chart.scaleService = {
|
|
// Scale registration object. Extensions can register new scale types (such as log or DB scales) and then
|
|
// use the new chart options to grab the correct scale
|
|
constructors: {},
|
|
// Use a registration function so that we can move to an ES6 map when we no longer need to support
|
|
// old browsers
|
|
|
|
// Scale config defaults
|
|
defaults: {},
|
|
registerScaleType: function(type, scaleConstructor, scaleDefaults) {
|
|
this.constructors[type] = scaleConstructor;
|
|
this.defaults[type] = helpers.clone(scaleDefaults);
|
|
},
|
|
getScaleConstructor: function(type) {
|
|
return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
|
|
},
|
|
getScaleDefaults: function(type) {
|
|
// Return the scale defaults merged with the global settings so that we always use the latest ones
|
|
return this.defaults.hasOwnProperty(type) ? helpers.merge({}, [defaults.scale, this.defaults[type]]) : {};
|
|
},
|
|
updateScaleDefaults: function(type, additions) {
|
|
var me = this;
|
|
if (me.defaults.hasOwnProperty(type)) {
|
|
me.defaults[type] = helpers.extend(me.defaults[type], additions);
|
|
}
|
|
},
|
|
addScalesToLayout: function(chart) {
|
|
// Adds each scale to the chart.boxes array to be sized accordingly
|
|
helpers.each(chart.scales, function(scale) {
|
|
// Set ILayoutItem parameters for backwards compatibility
|
|
scale.fullWidth = scale.options.fullWidth;
|
|
scale.position = scale.options.position;
|
|
scale.weight = scale.options.weight;
|
|
Chart.layoutService.addBox(chart, scale);
|
|
});
|
|
}
|
|
};
|
|
};
|