From e090691ef76ffe0993e28763af3ce6e4a88c58b2 Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Sat, 19 Mar 2016 08:50:50 -0400 Subject: [PATCH] Better use of default scale types. --- src/core/core.controller.js | 6 ++++-- src/core/core.helpers.js | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 1c6a6f587..63bfe522f 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -126,7 +126,8 @@ module.exports = function(Chart) { if (this.options.scales) { if (this.options.scales.xAxes && this.options.scales.xAxes.length) { 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) { var scale = new ScaleClass({ ctx: this.chart.ctx, @@ -143,7 +144,8 @@ module.exports = function(Chart) { if (this.options.scales.yAxes && this.options.scales.yAxes.length) { // Build the y axes 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) { var scale = new ScaleClass({ ctx: this.chart.ctx, diff --git a/src/core/core.helpers.js b/src/core/core.helpers.js index a57cb71af..f541b4f62 100644 --- a/src/core/core.helpers.js +++ b/src/core/core.helpers.js @@ -136,11 +136,12 @@ module.exports = function(Chart) { // These properties are arrays of items if (base.hasOwnProperty(key)) { 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) { - 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) { // 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 { // Type is the same base[key][index] = helpers.configMerge(base[key][index], valueObj); @@ -149,7 +150,8 @@ module.exports = function(Chart) { } else { base[key] = []; 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") { -- 2.47.2