mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Merge Chart.scales into Chart.scaleService to be consistent
This commit is contained in:
parent
30019dfddd
commit
1f16b349d2
@ -220,7 +220,7 @@
|
||||
this.scales = {};
|
||||
|
||||
// Build the x axis. The line chart only supports a single x axis
|
||||
var ScaleClass = Chart.scales.getScaleConstructor(this.options.scales.xAxes[0].type);
|
||||
var ScaleClass = Chart.scaleService.getScaleConstructor(this.options.scales.xAxes[0].type);
|
||||
var xScale = new ScaleClass({
|
||||
ctx: this.chart.ctx,
|
||||
options: this.options.scales.xAxes[0],
|
||||
@ -231,7 +231,7 @@
|
||||
|
||||
// Build up all the y scales
|
||||
helpers.each(this.options.scales.yAxes, function(yAxisOptions) {
|
||||
var ScaleClass = Chart.scales.getScaleConstructor(yAxisOptions.type);
|
||||
var ScaleClass = Chart.scaleService.getScaleConstructor(yAxisOptions.type);
|
||||
var scale = new ScaleClass({
|
||||
ctx: this.chart.ctx,
|
||||
options: yAxisOptions,
|
||||
|
||||
@ -344,7 +344,7 @@
|
||||
|
||||
// Build the x axes
|
||||
helpers.each(this.options.scales.xAxes, function(xAxisOptions) {
|
||||
var ScaleClass = Chart.scales.getScaleConstructor(xAxisOptions.type);
|
||||
var ScaleClass = Chart.scaleService.getScaleConstructor(xAxisOptions.type);
|
||||
var scale = new ScaleClass({
|
||||
ctx: this.chart.ctx,
|
||||
options: xAxisOptions,
|
||||
@ -357,7 +357,7 @@
|
||||
|
||||
// Build the y axes
|
||||
helpers.each(this.options.scales.yAxes, function(yAxisOptions) {
|
||||
var ScaleClass = Chart.scales.getScaleConstructor(yAxisOptions.type);
|
||||
var ScaleClass = Chart.scaleService.getScaleConstructor(yAxisOptions.type);
|
||||
var scale = new ScaleClass({
|
||||
ctx: this.chart.ctx,
|
||||
options: yAxisOptions,
|
||||
|
||||
@ -66,7 +66,7 @@
|
||||
|
||||
// Scale setup
|
||||
var self = this;
|
||||
var ScaleClass = Chart.scales.getScaleConstructor(this.options.scale.type);
|
||||
var ScaleClass = Chart.scaleService.getScaleConstructor(this.options.scale.type);
|
||||
this.scale = new ScaleClass({
|
||||
options: this.options.scale,
|
||||
lineArc: true,
|
||||
|
||||
@ -302,7 +302,7 @@
|
||||
buildScale: function() {
|
||||
var self = this;
|
||||
|
||||
var ScaleConstructor = Chart.scales.getScaleConstructor(this.options.scale.type);
|
||||
var ScaleConstructor = Chart.scaleService.getScaleConstructor(this.options.scale.type);
|
||||
this.scale = new ScaleConstructor({
|
||||
options: this.options.scale,
|
||||
height: this.chart.height,
|
||||
|
||||
@ -9,6 +9,18 @@
|
||||
// a service where scales are registered with their respective charts so that changing the
|
||||
// scales does not require
|
||||
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
|
||||
registerScaleType: function(type, scaleConstructor) {
|
||||
this.constructors[type] = scaleConstructor;
|
||||
},
|
||||
getScaleConstructor: function(type) {
|
||||
return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
|
||||
},
|
||||
|
||||
// The interesting function
|
||||
fitScalesForChart: function(chartInstance, width, height) {
|
||||
var xPadding = width > 30 ? 5 : 2;
|
||||
@ -287,19 +299,4 @@
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 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
|
||||
Chart.scales = {
|
||||
constructors: {},
|
||||
// Use a registration function so that we can move to an ES6 map when we no longer need to support
|
||||
// old browsers
|
||||
registerScaleType: function(type, scaleConstructor) {
|
||||
this.constructors[type] = scaleConstructor;
|
||||
},
|
||||
getScaleConstructor: function(type) {
|
||||
return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
||||
@ -233,8 +233,5 @@
|
||||
}
|
||||
}
|
||||
});
|
||||
Chart.scales.registerScaleType("category", DatasetScale);
|
||||
|
||||
|
||||
|
||||
Chart.scaleService.registerScaleType("category", DatasetScale);
|
||||
}).call(this);
|
||||
|
||||
@ -523,7 +523,6 @@
|
||||
}
|
||||
}
|
||||
});
|
||||
Chart.scales.registerScaleType("linear", LinearScale);
|
||||
|
||||
|
||||
Chart.scaleService.registerScaleType("linear", LinearScale);
|
||||
|
||||
}).call(this);
|
||||
|
||||
@ -374,7 +374,7 @@
|
||||
}
|
||||
}
|
||||
});
|
||||
Chart.scales.registerScaleType("radialLinear", LinearRadialScale);
|
||||
Chart.scaleService.registerScaleType("radialLinear", LinearRadialScale);
|
||||
|
||||
|
||||
}).call(this);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user