]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Remove core plugin fallbacks to root options (#8462)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Fri, 19 Feb 2021 22:53:01 +0000 (00:53 +0200)
committerGitHub <noreply@github.com>
Fri, 19 Feb 2021 22:53:01 +0000 (17:53 -0500)
* Remove core plugin fallbacks to root options
* Legend font color default fallbacks

src/plugins/plugin.legend.js
src/plugins/plugin.title.js
src/plugins/plugin.tooltip.js
test/specs/plugin.legend.tests.js

index ffa8dfc3d4539b3d14f51ee33d473d1285aeb6c6..5cbe412152047366ffabb98b4cdcc0bc14ae5ec2 100644 (file)
@@ -561,6 +561,7 @@ export default {
     onLeave: null,
 
     labels: {
+      color: (ctx) => ctx.chart.options.color,
       boxWidth: 40,
       padding: 10,
       // Generates labels shown in the legend
@@ -605,24 +606,17 @@ export default {
     },
 
     title: {
+      color: (ctx) => ctx.chart.options.color,
       display: false,
       position: 'center',
       text: '',
     }
   },
 
-  defaultRoutes: {
-    'labels.color': 'color',
-    'title.color': 'color'
-  },
-
   descriptors: {
     _scriptable: (name) => !name.startsWith('on'),
     labels: {
-      _scriptable: false,
+      _scriptable: (name) => !['generateLabels', 'filter', 'sort'].includes(name),
     }
   },
-
-  // For easier configuration, resolve additionally from root of options and defaults.
-  additionalOptionScopes: ['']
 };
index 04e6917969d0eb46ba82f7afabfd70610aa3516b..662674459c4c1f9b005e3d2e4623060c88055265 100644 (file)
@@ -180,7 +180,4 @@ export default {
   defaultRoutes: {
     color: 'color'
   },
-
-  // For easier configuration, resolve additionally from root of options and defaults.
-  additionalOptionScopes: ['']
 };
index 7edffa7f27ef64d42bd597ea4cab400738fa8cf7..40b0fbbf62345bbe5b34fab8a36f38da2d430af3 100644 (file)
@@ -1206,6 +1206,6 @@ export default {
     }
   },
 
-  // For easier configuration, resolve additionally from `interaction` and root of options and defaults.
-  additionalOptionScopes: ['interaction', '']
+  // Resolve additionally from `interaction` options and defaults.
+  additionalOptionScopes: ['interaction']
 };
index a5d836949938519c7c4c5c7b910166a9724111a6..096a002d63cf8651a85cb5c4decdba0f79c9a3c5 100644 (file)
@@ -17,14 +17,14 @@ describe('Legend block tests', function() {
       onLeave: null,
 
       labels: {
-        color: Chart.defaults.color,
+        color: jasmine.any(Function),
         boxWidth: 40,
         padding: 10,
         generateLabels: jasmine.any(Function)
       },
 
       title: {
-        color: Chart.defaults.color,
+        color: jasmine.any(Function),
         display: false,
         position: 'center',
         text: '',
@@ -736,6 +736,58 @@ describe('Legend block tests', function() {
     });
   });
 
+  it('should not read onClick from chart options', function() {
+    var chart = window.acquireChart({
+      type: 'bar',
+      data: {
+        labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
+        datasets: [{
+          label: 'dataset',
+          backgroundColor: 'red',
+          borderColor: 'red',
+          data: [120, 23, 24, 45, 51]
+        }]
+      },
+      options: {
+        responsive: true,
+        onClick() { },
+        plugins: {
+          legend: {
+            display: true
+          }
+        }
+      }
+    });
+    expect(chart.legend.options.onClick).toBe(Chart.defaults.plugins.legend.onClick);
+  });
+
+  it('should read labels.color from chart options', function() {
+    var chart = window.acquireChart({
+      type: 'bar',
+      data: {
+        labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
+        datasets: [{
+          label: 'dataset',
+          backgroundColor: 'red',
+          borderColor: 'red',
+          data: [120, 23, 24, 45, 51]
+        }]
+      },
+      options: {
+        responsive: true,
+        color: 'green',
+        plugins: {
+          legend: {
+            display: true
+          }
+        }
+      }
+    });
+    expect(chart.legend.options.labels.color).toBe('green');
+    expect(chart.legend.options.title.color).toBe('green');
+  });
+
+
   describe('config update', function() {
     it('should update the options', function() {
       var chart = acquireChart({
@@ -827,7 +879,14 @@ describe('Legend block tests', function() {
       chart.options.plugins.legend = {};
       chart.update();
       expect(chart.legend).not.toBe(undefined);
-      expect(chart.legend.options).toEqualOptions(Chart.defaults.plugins.legend);
+      expect(chart.legend.options).toEqualOptions(Object.assign({},
+        // replace scriptable options with resolved values
+        Chart.defaults.plugins.legend,
+        {
+          labels: {color: Chart.defaults.color},
+          title: {color: Chart.defaults.color}
+        }
+      ));
     });
   });