mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-11 18:56:49 +01:00
File structure for extensibility
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
|
||||
scales: {
|
||||
xAxes: [{
|
||||
scaleType: "dataset", // scatter should not use a dataset axis
|
||||
type: "category", // scatter should not use a dataset axis
|
||||
display: true,
|
||||
position: "bottom",
|
||||
id: "x-axis-1", // need an ID so datasets can reference the scale
|
||||
@@ -43,7 +43,7 @@
|
||||
},
|
||||
}],
|
||||
yAxes: [{
|
||||
scaleType: "linear", // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
|
||||
type: "linear", // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
|
||||
display: true,
|
||||
position: "left",
|
||||
id: "y-axis-1",
|
||||
@@ -398,7 +398,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].scaleType);
|
||||
var ScaleClass = Chart.scales.getScaleConstructor(this.options.scales.xAxes[0].type);
|
||||
var xScale = new ScaleClass({
|
||||
ctx: this.chart.ctx,
|
||||
options: this.options.scales.xAxes[0],
|
||||
@@ -413,7 +413,7 @@
|
||||
|
||||
// Build up all the y scales
|
||||
helpers.each(this.options.scales.yAxes, function(yAxisOptions) {
|
||||
var ScaleClass = Chart.scales.getScaleConstructor(yAxisOptions.scaleType);
|
||||
var ScaleClass = Chart.scales.getScaleConstructor(yAxisOptions.type);
|
||||
var scale = new ScaleClass({
|
||||
ctx: this.chart.ctx,
|
||||
options: yAxisOptions,
|
||||
@@ -11,8 +11,8 @@
|
||||
Chart.scaleService = {
|
||||
// The interesting function
|
||||
fitScalesForChart: function(chartInstance, width, height) {
|
||||
var xPadding = 5;
|
||||
var yPadding = 5;
|
||||
var xPadding = width > 30 ? 5 : 2;
|
||||
var yPadding = height > 30 ? 5 : 2;
|
||||
|
||||
if (chartInstance) {
|
||||
var leftScales = helpers.where(chartInstance.scales, function(scaleInstance) {
|
||||
@@ -294,11 +294,11 @@
|
||||
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(scaleType, scaleConstructor) {
|
||||
this.constructors[scaleType] = scaleConstructor;
|
||||
registerScaleType: function(type, scaleConstructor) {
|
||||
this.constructors[type] = scaleConstructor;
|
||||
},
|
||||
getScaleConstructor: function(scaleType) {
|
||||
return this.constructors.hasOwnProperty(scaleType) ? this.constructors[scaleType] : undefined;
|
||||
getScaleConstructor: function(type) {
|
||||
return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -207,7 +207,7 @@
|
||||
}
|
||||
}
|
||||
});
|
||||
Chart.scales.registerScaleType("dataset", DatasetScale);
|
||||
Chart.scales.registerScaleType("category", DatasetScale);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user