From 0dcf025ab75812a68aa2444902c2be61993286ce Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Thu, 14 Oct 2021 15:35:51 +0300 Subject: [PATCH] Support nested scriptable defaults for datasets (#9770) --- src/core/core.config.js | 2 +- test/specs/core.datasetController.tests.js | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/core/core.config.js b/src/core/core.config.js index ef129b88f4d..02826667849 100644 --- a/src/core/core.config.js +++ b/src/core/core.config.js @@ -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); diff --git a/test/specs/core.datasetController.tests.js b/test/specs/core.datasetController.tests.js index 3ec7a661260..05bef5b65b6 100644 --- a/test/specs/core.datasetController.tests.js +++ b/test/specs/core.datasetController.tests.js @@ -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() {