]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Better use of default scale types. 2155/head
authorEvert Timberg <evert.timberg@gmail.com>
Sat, 19 Mar 2016 12:50:50 +0000 (08:50 -0400)
committerEvert Timberg <evert.timberg@gmail.com>
Sat, 19 Mar 2016 12:50:50 +0000 (08:50 -0400)
src/core/core.controller.js
src/core/core.helpers.js

index 1c6a6f587e928852413504702b521d931231d80f..63bfe522f1c09917fdbf8c4b2535313e7a6355af 100644 (file)
@@ -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,
index a57cb71af7df0c4227db2b723b6b28bd75714799..f541b4f62715cc6db00d37806de256c26d9d4fae 100644 (file)
@@ -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") {