From 15dd6bf47c000a541bc6241ffc7279462907fe62 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Mon, 21 Jan 2019 09:36:16 -0800 Subject: [PATCH] Updates based on feedback --- karma.conf.js | 1 - src/controllers/controller.line.js | 45 ++++++++++++++------------- src/controllers/controller.scatter.js | 8 +++-- src/core/core.controller.js | 2 +- src/core/core.datasetController.js | 24 +++++++++----- 5 files changed, 47 insertions(+), 33 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index f46d523e2c8..02878567571 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -78,7 +78,6 @@ module.exports = function(karma) { // These settings deal with browser disconnects. We had seen test flakiness from Firefox // [Firefox 56.0.0 (Linux 0.0.0)]: Disconnected (1 times), because no message in 10000 ms. // /~https://github.com/jasmine/jasmine/issues/1327#issuecomment-332939551 - browserNoActivityTimeout: 1000000, browserDisconnectTolerance: 3 }); diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index 0f234353fda..555df13bd96 100644 --- a/src/controllers/controller.line.js +++ b/src/controllers/controller.line.js @@ -26,10 +26,12 @@ defaults._set('line', { } }); -defaults._set('dataset', { - line: { - showLine: true, - spanGaps: false +defaults._set('global', { + datasets: { + line: { + showLine: true, + spanGaps: false + } } }); @@ -48,9 +50,10 @@ module.exports = DatasetController.extend({ var lineElementOptions = options.elements.line; var scale = me.getScaleForId(meta.yAxisID); var dataset = me.getDataset(); - var datasetDefaultOpts = me.getDatasetDefaultOpts(); - var datasetUserOpts = me.getDatasetUserOptions(); - var showLine = me._showLine = resolve([datasetUserOpts.showLine, options.showLines, datasetDefaultOpts.showLine]); + var datasetDefaults = me._defaults(); + var config = me._config; + // showLine doesn't use config for backwards compatibility + var showLine = me._showLine = resolve([dataset.showLine, options.showLines, datasetDefaults.showLine]); var i, ilen, custom; // Update Line @@ -58,8 +61,8 @@ module.exports = DatasetController.extend({ custom = line.custom || {}; // Compatibility: If the properties are defined with only the old name, use those values - if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) { - dataset.lineTension = dataset.tension; + if ((config.tension !== undefined) && (config.lineTension === undefined)) { + config.lineTension = config.tension; } // Utility @@ -73,18 +76,18 @@ module.exports = DatasetController.extend({ // The default behavior of lines is to break at null values, according // to /~https://github.com/chartjs/Chart.js/issues/2435#issuecomment-216718158 // This option gives lines the ability to span gaps - spanGaps: resolve([datasetUserOpts.spanGaps, options.spanGaps, datasetDefaultOpts.spanGaps]), - tension: resolve([custom.tension, dataset.lineTension, lineElementOptions.tension]), - backgroundColor: resolve([custom.backgroundColor, dataset.backgroundColor, lineElementOptions.backgroundColor]), - borderWidth: resolve([custom.borderWidth, dataset.borderWidth, lineElementOptions.borderWidth]), - borderColor: resolve([custom.borderColor, dataset.borderColor, lineElementOptions.borderColor]), - borderCapStyle: resolve([custom.borderCapStyle, dataset.borderCapStyle, lineElementOptions.borderCapStyle]), - borderDash: resolve([custom.borderDash, dataset.borderDash, lineElementOptions.borderDash]), - borderDashOffset: resolve([custom.borderDashOffset, dataset.borderDashOffset, lineElementOptions.borderDashOffset]), - borderJoinStyle: resolve([custom.borderJoinStyle, dataset.borderJoinStyle, lineElementOptions.borderJoinStyle]), - fill: resolve([custom.fill, dataset.fill, lineElementOptions.fill]), - steppedLine: resolve([custom.steppedLine, dataset.steppedLine, lineElementOptions.stepped]), - cubicInterpolationMode: resolve([custom.cubicInterpolationMode, dataset.cubicInterpolationMode, lineElementOptions.cubicInterpolationMode]), + spanGaps: resolve([dataset.spanGaps, options.spanGaps, datasetDefaults.spanGaps]), // doesn't use config for backwards compatibility + tension: resolve([custom.tension, config.lineTension, lineElementOptions.tension]), + backgroundColor: resolve([custom.backgroundColor, config.backgroundColor, lineElementOptions.backgroundColor]), + borderWidth: resolve([custom.borderWidth, config.borderWidth, lineElementOptions.borderWidth]), + borderColor: resolve([custom.borderColor, config.borderColor, lineElementOptions.borderColor]), + borderCapStyle: resolve([custom.borderCapStyle, config.borderCapStyle, lineElementOptions.borderCapStyle]), + borderDash: resolve([custom.borderDash, config.borderDash, lineElementOptions.borderDash]), + borderDashOffset: resolve([custom.borderDashOffset, config.borderDashOffset, lineElementOptions.borderDashOffset]), + borderJoinStyle: resolve([custom.borderJoinStyle, config.borderJoinStyle, lineElementOptions.borderJoinStyle]), + fill: resolve([custom.fill, config.fill, lineElementOptions.fill]), + steppedLine: resolve([custom.steppedLine, config.steppedLine, lineElementOptions.stepped]), + cubicInterpolationMode: resolve([custom.cubicInterpolationMode, config.cubicInterpolationMode, lineElementOptions.cubicInterpolationMode]), }; line.pivot(); diff --git a/src/controllers/controller.scatter.js b/src/controllers/controller.scatter.js index da757c814ff..177e563203f 100644 --- a/src/controllers/controller.scatter.js +++ b/src/controllers/controller.scatter.js @@ -33,9 +33,11 @@ defaults._set('scatter', { } }); -defaults._set('dataset', { - scatter: { - showLine: false +defaults._set('global', { + datasets: { + scatter: { + showLine: false + } } }); diff --git a/src/core/core.controller.js b/src/core/core.controller.js index b0175e8a67f..0e110fb14c1 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -503,7 +503,7 @@ helpers.extend(Chart.prototype, /** @lends Chart */ { return; } - meta.controller.update(); + meta.controller._update(); plugins.notify(me, 'afterDatasetUpdate', [args]); }, diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index ec174e4d7bd..e823ae17f3a 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -236,10 +236,20 @@ helpers.extend(DatasetController.prototype, { }, /** - * Returns the user-supplied dataset-level options - * @protected + * Private functionality to be called before every update + * @private + */ + _update: function() { + var me = this; + me._config = me._configure(); + me.update.apply(me, arguments); + }, + + /** + * Returns the merged user-supplied and default dataset-level options + * @private */ - getDatasetUserOptions: function() { + _configure: function() { var me = this; var dataset = me.getDataset(); var datasetOptions = {}; @@ -252,18 +262,18 @@ helpers.extend(DatasetController.prototype, { datasetOptions[key] = helpers.clone(dataset[key]); } } - return datasetOptions; + return helpers.merge({}, [datasetOptions, me._defaults()]); }, /** * Returns the default dataset-level options - * @protected + * @private */ - getDatasetDefaultOpts: function() { + _defaults: function() { var me = this; var dataset = me.getDataset(); var type = helpers.valueOrDefault(dataset.type, me.chart.config.type); - return defaults.dataset[type]; + return defaults.global.datasets[type]; }, update: helpers.noop,