mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 20:29:12 +02:00
Merge pull request #2155 from nnnick/fix/2154
Better use of default scale types.
This commit is contained in:
commit
74fd697351
@ -126,7 +126,8 @@ module.exports = function(Chart) {
|
|||||||
if (this.options.scales) {
|
if (this.options.scales) {
|
||||||
if (this.options.scales.xAxes && this.options.scales.xAxes.length) {
|
if (this.options.scales.xAxes && this.options.scales.xAxes.length) {
|
||||||
helpers.each(this.options.scales.xAxes, function(xAxisOptions, index) {
|
helpers.each(this.options.scales.xAxes, function(xAxisOptions, index) {
|
||||||
var ScaleClass = Chart.scaleService.getScaleConstructor(xAxisOptions.type);
|
var xType = helpers.getValueOrDefault(xAxisOptions.type, 'category');
|
||||||
|
var ScaleClass = Chart.scaleService.getScaleConstructor(xType);
|
||||||
if (ScaleClass) {
|
if (ScaleClass) {
|
||||||
var scale = new ScaleClass({
|
var scale = new ScaleClass({
|
||||||
ctx: this.chart.ctx,
|
ctx: this.chart.ctx,
|
||||||
@ -143,7 +144,8 @@ module.exports = function(Chart) {
|
|||||||
if (this.options.scales.yAxes && this.options.scales.yAxes.length) {
|
if (this.options.scales.yAxes && this.options.scales.yAxes.length) {
|
||||||
// Build the y axes
|
// Build the y axes
|
||||||
helpers.each(this.options.scales.yAxes, function(yAxisOptions, index) {
|
helpers.each(this.options.scales.yAxes, function(yAxisOptions, index) {
|
||||||
var ScaleClass = Chart.scaleService.getScaleConstructor(yAxisOptions.type);
|
var yType = helpers.getValueOrDefault(yAxisOptions.type, 'linear');
|
||||||
|
var ScaleClass = Chart.scaleService.getScaleConstructor(yType);
|
||||||
if (ScaleClass) {
|
if (ScaleClass) {
|
||||||
var scale = new ScaleClass({
|
var scale = new ScaleClass({
|
||||||
ctx: this.chart.ctx,
|
ctx: this.chart.ctx,
|
||||||
|
@ -136,11 +136,12 @@ module.exports = function(Chart) {
|
|||||||
// These properties are arrays of items
|
// These properties are arrays of items
|
||||||
if (base.hasOwnProperty(key)) {
|
if (base.hasOwnProperty(key)) {
|
||||||
helpers.each(value, function(valueObj, index) {
|
helpers.each(value, function(valueObj, index) {
|
||||||
|
var axisType = helpers.getValueOrDefault(valueObj.type, key === 'xAxes' ? 'category' : 'linear');
|
||||||
if (index >= base[key].length || !base[key][index].type) {
|
if (index >= base[key].length || !base[key][index].type) {
|
||||||
base[key].push(helpers.configMerge(valueObj.type ? Chart.scaleService.getScaleDefaults(valueObj.type) : {}, valueObj));
|
base[key].push(helpers.configMerge(Chart.scaleService.getScaleDefaults(axisType), valueObj));
|
||||||
} else if (valueObj.type !== base[key][index].type) {
|
} else if (valueObj.type !== base[key][index].type) {
|
||||||
// Type changed. Bring in the new defaults before we bring in valueObj so that valueObj can override the correct scale defaults
|
// Type changed. Bring in the new defaults before we bring in valueObj so that valueObj can override the correct scale defaults
|
||||||
base[key][index] = helpers.configMerge(base[key][index], valueObj.type ? Chart.scaleService.getScaleDefaults(valueObj.type) : {}, valueObj);
|
base[key][index] = helpers.configMerge(base[key][index], Chart.scaleService.getScaleDefaults(axisType), valueObj);
|
||||||
} else {
|
} else {
|
||||||
// Type is the same
|
// Type is the same
|
||||||
base[key][index] = helpers.configMerge(base[key][index], valueObj);
|
base[key][index] = helpers.configMerge(base[key][index], valueObj);
|
||||||
@ -149,7 +150,8 @@ module.exports = function(Chart) {
|
|||||||
} else {
|
} else {
|
||||||
base[key] = [];
|
base[key] = [];
|
||||||
helpers.each(value, function(valueObj) {
|
helpers.each(value, function(valueObj) {
|
||||||
base[key].push(helpers.configMerge(valueObj.type ? Chart.scaleService.getScaleDefaults(valueObj.type) : {}, valueObj));
|
var axisType = helpers.getValueOrDefault(valueObj.type, key === 'xAxes' ? 'category' : 'linear');
|
||||||
|
base[key].push(helpers.configMerge(Chart.scaleService.getScaleDefaults(axisType), valueObj));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (base.hasOwnProperty(key) && typeof base[key] === "object" && base[key] !== null && typeof value === "object") {
|
} else if (base.hasOwnProperty(key) && typeof base[key] === "object" && base[key] !== null && typeof value === "object") {
|
||||||
|
Loading…
Reference in New Issue
Block a user