diff --git a/src/core/core.config.js b/src/core/core.config.js index 4fda6e38b..9723aa264 100644 --- a/src/core/core.config.js +++ b/src/core/core.config.js @@ -101,25 +101,12 @@ function mergeConfig(...args/* config objects ... */) { }); } -function includeDefaults(options, type) { - return mergeConfig( +function includeDefaults(config, options) { + const scaleConfig = mergeScaleConfig(config, options); + options = mergeConfig( defaults, - defaults.controllers[type], + defaults.controllers[config.type], options || {}); -} - -function initConfig(config) { - config = config || {}; - - // Do NOT use mergeConfig for the data object because this method merges arrays - // and so would change references to labels and datasets, preventing data updates. - const data = config.data = config.data || {datasets: [], labels: []}; - data.datasets = data.datasets || []; - data.labels = data.labels || []; - - const scaleConfig = mergeScaleConfig(config, config.options); - - const options = config.options = includeDefaults(config.options, config.type); options.hover = merge(Object.create(null), [ defaults.interaction, @@ -140,6 +127,19 @@ function initConfig(config) { options.interaction, options.tooltips ]); + return options; +} + +function initConfig(config) { + config = config || {}; + + // Do NOT use mergeConfig for the data object because this method merges arrays + // and so would change references to labels and datasets, preventing data updates. + const data = config.data = config.data || {datasets: [], labels: []}; + data.datasets = data.datasets || []; + data.labels = data.labels || []; + + config.options = includeDefaults(config, config.options); return config; } @@ -171,11 +171,6 @@ export default class Config { update(options) { const config = this._config; - const scaleConfig = mergeScaleConfig(config, options); - - options = includeDefaults(options, config.type); - - options.scales = scaleConfig; - config.options = options; + config.options = includeDefaults(config, options); } } diff --git a/test/specs/core.controller.tests.js b/test/specs/core.controller.tests.js index 60a1a4b0b..00d968810 100644 --- a/test/specs/core.controller.tests.js +++ b/test/specs/core.controller.tests.js @@ -355,6 +355,28 @@ describe('Chart', function() { }); }); + describe('Updating options', function() { + it('update should result to same set of options as construct', function() { + var chart = acquireChart({ + type: 'line', + data: [], + options: { + animation: false, + locale: 'en-US', + responsive: false + } + }); + const options = chart.options; + chart.options = { + animation: false, + locale: 'en-US', + responsive: false + }; + chart.update(); + expect(chart.options).toEqual(jasmine.objectContaining(options)); + }); + }); + describe('config.options.responsive: true (maintainAspectRatio: false)', function() { it('should fill parent width and height', function() { var chart = acquireChart({ diff --git a/test/utils.js b/test/utils.js index 4a8508de7..010971dde 100644 --- a/test/utils.js +++ b/test/utils.js @@ -58,7 +58,6 @@ function acquireChart(config, options) { config.options = config.options || {}; config.options.animation = config.options.animation === undefined ? false : config.options.animation; config.options.responsive = config.options.responsive === undefined ? false : config.options.responsive; - config.options.fontFamily = config.options.fontFamily || 'Arial'; config.options.locale = config.options.locale || 'en-US'; wrapper.appendChild(canvas);