2016-02-12 04:30:53 +01:00
|
|
|
"use strict";
|
2015-09-23 03:31:26 +02:00
|
|
|
|
2016-02-12 04:30:53 +01:00
|
|
|
module.exports = function(Chart) {
|
2015-09-23 03:31:26 +02:00
|
|
|
|
2016-02-14 02:12:26 +01:00
|
|
|
var helpers = Chart.helpers;
|
2015-09-24 05:52:31 +02:00
|
|
|
|
2016-02-12 04:30:53 +01:00
|
|
|
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
|
2015-09-23 03:31:26 +02:00
|
|
|
|
2016-02-12 04:30:53 +01:00
|
|
|
// Scale config defaults
|
|
|
|
defaults: {},
|
|
|
|
registerScaleType: function(type, scaleConstructor, defaults) {
|
|
|
|
this.constructors[type] = scaleConstructor;
|
|
|
|
this.defaults[type] = helpers.clone(defaults);
|
|
|
|
},
|
|
|
|
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.scaleMerge(Chart.defaults.scale, this.defaults[type]) : {};
|
|
|
|
},
|
|
|
|
addScalesToLayout: function(chartInstance) {
|
|
|
|
// Adds each scale to the chart.boxes array to be sized accordingly
|
|
|
|
helpers.each(chartInstance.scales, function(scale) {
|
|
|
|
Chart.layoutService.addBox(chartInstance, scale);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|