Skip to content

Commit

Permalink
Support nested scriptable defaults for datasets (#9770)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Oct 14, 2021
1 parent dd78ba0 commit 0dcf025
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/core.config.js
Expand Up @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions test/specs/core.datasetController.tests.js
Expand Up @@ -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() {
Expand Down

0 comments on commit 0dcf025

Please sign in to comment.