]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Support nested scriptable defaults for datasets (#9770)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Thu, 14 Oct 2021 12:35:51 +0000 (15:35 +0300)
committerGitHub <noreply@github.com>
Thu, 14 Oct 2021 12:35:51 +0000 (08:35 -0400)
src/core/core.config.js
test/specs/core.datasetController.tests.js

index ef129b88f4df2ac3cee1ba9f4e8340d0b2da4a54..02826667849e1c7d738ed2d9307adbfc9eb2b97b 100644 (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);
index 3ec7a661260cca46975b14c4f87e9969b8556a8b..05bef5b65b6a42826f45d7e46d2dce881191fd34 100644 (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() {