Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ function mergeConfig(...args/* config objects ... */) {
});
}

function applyDefaults(config, options) {
const scaleConfig = mergeScaleConfig(config, options);

options = config.options = mergeConfig(
defaults,
defaults[config.type],
options || {});

options.scales = scaleConfig;
options.title = (options.title !== false) && merge({}, [defaults.plugins.title, options.title], {discardPrototype: true});
options.tooltips = (options.tooltips !== false) && merge({}, [defaults.plugins.tooltip, options.tooltips], {discardPrototype: true});
return options;
}

function initConfig(config) {
config = config || {};

Expand All @@ -109,17 +123,7 @@ function initConfig(config) {
data.datasets = data.datasets || [];
data.labels = data.labels || [];

const scaleConfig = mergeScaleConfig(config, config.options);

const options = config.options = mergeConfig(
defaults,
defaults[config.type],
config.options || {});

options.scales = scaleConfig;

options.title = (options.title !== false) && merge({}, [defaults.plugins.title, options.title]);
options.tooltips = (options.tooltips !== false) && merge({}, [defaults.plugins.tooltip, options.tooltips]);
applyDefaults(config, config.options);

return config;
}
Expand All @@ -129,22 +133,14 @@ function isAnimationDisabled(config) {
}

function updateConfig(chart) {
let newOptions = chart.options;
const config = chart.config;
const newOptions = chart.options;

each(chart.scales, (scale) => {
layouts.removeBox(chart, scale);
});

const scaleConfig = mergeScaleConfig(chart.config, newOptions);

newOptions = mergeConfig(
defaults,
defaults[chart.config.type],
newOptions);

chart.options = chart.config.options = newOptions;
chart.options.scales = scaleConfig;

chart.options = applyDefaults(config, newOptions);
chart._animationsDisabled = isAnimationDisabled(newOptions);
}

Expand Down
12 changes: 7 additions & 5 deletions src/helpers/helpers.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,22 @@ export function _elementsEqual(a0, a1) {
/**
* Returns a deep copy of `source` without keeping references on objects and arrays.
* @param {*} source - The value to clone.
* @param {boolean} [discardPrototype] - discard object prototype
* @returns {*}
*/
export function clone(source) {
export function clone(source, discardPrototype) {
if (isArray(source)) {
return source.map(clone);
return source.map(itm => clone(itm, discardPrototype));
}

if (isObject(source)) {
const target = Object.create(source);
const target = discardPrototype ? {} : Object.create(source);
const keys = Object.keys(source);
const klen = keys.length;
let k = 0;

for (; k < klen; ++k) {
target[keys[k]] = clone(source[keys[k]]);
target[keys[k]] = clone(source[keys[k]], discardPrototype);
}

return target;
Expand All @@ -185,7 +186,7 @@ export function _merger(key, target, source, options) {
// eslint-disable-next-line no-use-before-define
merge(tval, sval, options);
} else {
target[key] = clone(sval);
target[key] = clone(sval, options && options.discardPrototype);
}
}

Expand All @@ -196,6 +197,7 @@ export function _merger(key, target, source, options) {
* @param {object|object[]} source - Object(s) to merge into `target`.
* @param {object} [options] - Merging options:
* @param {function} [options.merger] - The merge method (key, target, source, options)
* @param {boolean} [options.discardPrototype] - Discard object prototype when cloning
* @returns {object} The `target` object.
*/
export function merge(target, source, options) {
Expand Down