});
}
-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,
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;
}
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);
}
}
});
});
+ 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({
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);