Skip to content

Commit

Permalink
Updates based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Jan 21, 2019
1 parent 0d9c607 commit 15dd6bf
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 33 deletions.
1 change: 0 additions & 1 deletion karma.conf.js
Expand Up @@ -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
});

Expand Down
45 changes: 24 additions & 21 deletions src/controllers/controller.line.js
Expand Up @@ -26,10 +26,12 @@ defaults._set('line', {
}
});

defaults._set('dataset', {
line: {
showLine: true,
spanGaps: false
defaults._set('global', {
datasets: {
line: {
showLine: true,
spanGaps: false
}
}
});

Expand All @@ -48,18 +50,19 @@ 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
if (showLine) {
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
Expand All @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions src/controllers/controller.scatter.js
Expand Up @@ -33,9 +33,11 @@ defaults._set('scatter', {
}
});

defaults._set('dataset', {
scatter: {
showLine: false
defaults._set('global', {
datasets: {
scatter: {
showLine: false
}
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/core/core.controller.js
Expand Up @@ -503,7 +503,7 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
return;
}

meta.controller.update();
meta.controller._update();

plugins.notify(me, 'afterDatasetUpdate', [args]);
},
Expand Down
24 changes: 17 additions & 7 deletions src/core/core.datasetController.js
Expand Up @@ -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 = {};
Expand All @@ -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,
Expand Down

0 comments on commit 15dd6bf

Please sign in to comment.