mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-19 22:56:54 +01:00
Support nested scriptable defaults for datasets (#9770)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user