Support nested scriptable defaults for datasets (#9770)

This commit is contained in:
Jukka Kurkela
2021-10-14 15:35:51 +03:00
committed by GitHub
parent dd78ba0368
commit 0dcf025ab7
2 changed files with 25 additions and 1 deletions

View File

@@ -372,7 +372,7 @@ function getResolver(resolverCache, scopes, prefixes) {
}
const hasFunction = value => isObject(value)
&& Object.keys(value).reduce((acc, key) => acc || isFunction(value[key]), false);
&& Object.getOwnPropertyNames(value).reduce((acc, key) => acc || isFunction(value[key]), false);
function needContext(proxy, names) {
const {isScriptable, isIndexable} = _descriptors(proxy);

View File

@@ -919,6 +919,30 @@ describe('Chart.DatasetController', function() {
}
});
});
it('should support nested scriptable defaults', function() {
Chart.defaults.datasets.line.fill = {
value: (ctx) => ctx.type === 'dataset' ? 75 : 0
};
const chart = acquireChart({
type: 'line',
data: {
datasets: [{
data: [100, 120, 130],
}]
},
});
const controller = chart.getDatasetMeta(0).controller;
const opts = controller.resolveDatasetElementOptions();
expect(opts).toEqualOptions({
fill: {
value: 75
}
});
delete Chart.defaults.datasets.line.fill;
});
});
describe('_resolveAnimations', function() {