mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 04:09:08 +02:00
Fix setting options in array of objects (#9062)
* Fix setting options in array of objects * CC
This commit is contained in:
parent
024f406223
commit
f1ca99bfd4
@ -290,13 +290,8 @@ function createSubResolver(parentScopes, resolver, prop, value) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return _createResolver([...set], [''], rootScopes, fallback, () => {
|
||||
const parent = resolver._getTarget();
|
||||
if (!(prop in parent)) {
|
||||
parent[prop] = {};
|
||||
}
|
||||
return parent[prop];
|
||||
});
|
||||
return _createResolver([...set], [''], rootScopes, fallback,
|
||||
() => subGetTarget(resolver, prop, value));
|
||||
}
|
||||
|
||||
function addScopesFromKey(set, allScopes, key, fallback) {
|
||||
@ -306,6 +301,19 @@ function addScopesFromKey(set, allScopes, key, fallback) {
|
||||
return key;
|
||||
}
|
||||
|
||||
function subGetTarget(resolver, prop, value) {
|
||||
const parent = resolver._getTarget();
|
||||
if (!(prop in parent)) {
|
||||
parent[prop] = {};
|
||||
}
|
||||
const target = parent[prop];
|
||||
if (isArray(target) && isObject(value)) {
|
||||
// For array of objects, the object is used to store updated values
|
||||
return value;
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
function _resolveWithPrefixes(prop, prefixes, scopes, proxy) {
|
||||
let value;
|
||||
for (const prefix of prefixes) {
|
||||
|
@ -752,6 +752,23 @@ describe('Chart.helpers.config', function() {
|
||||
expect(fn()).toEqual('ok');
|
||||
});
|
||||
|
||||
it('should properly set value to object in array of objects', function() {
|
||||
const defaults = {};
|
||||
const options = {
|
||||
annotations: [{
|
||||
value: 10
|
||||
}, {
|
||||
value: 20
|
||||
}]
|
||||
};
|
||||
const resolver = _attachContext(_createResolver([options, defaults]), {test: true});
|
||||
expect(resolver.annotations[0].value).toEqual(10);
|
||||
|
||||
resolver.annotations[0].value = 15;
|
||||
expect(options.annotations[0].value).toEqual(15);
|
||||
expect(options.annotations[1].value).toEqual(20);
|
||||
});
|
||||
|
||||
describe('_indexable and _scriptable', function() {
|
||||
it('should default to true', function() {
|
||||
const options = {
|
||||
|
Loading…
Reference in New Issue
Block a user