From: Jukka Kurkela Date: Fri, 19 Feb 2021 22:53:01 +0000 (+0200) Subject: Remove core plugin fallbacks to root options (#8462) X-Git-Tag: v3.0.0-beta.11~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa5e0fe41305efc16a562a46adc1a1a3de5f33ea;p=thirdparty%2FChart.js.git Remove core plugin fallbacks to root options (#8462) * Remove core plugin fallbacks to root options * Legend font color default fallbacks --- diff --git a/src/plugins/plugin.legend.js b/src/plugins/plugin.legend.js index ffa8dfc3d..5cbe41215 100644 --- a/src/plugins/plugin.legend.js +++ b/src/plugins/plugin.legend.js @@ -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: [''] }; diff --git a/src/plugins/plugin.title.js b/src/plugins/plugin.title.js index 04e691796..662674459 100644 --- a/src/plugins/plugin.title.js +++ b/src/plugins/plugin.title.js @@ -180,7 +180,4 @@ export default { defaultRoutes: { color: 'color' }, - - // For easier configuration, resolve additionally from root of options and defaults. - additionalOptionScopes: [''] }; diff --git a/src/plugins/plugin.tooltip.js b/src/plugins/plugin.tooltip.js index 7edffa7f2..40b0fbbf6 100644 --- a/src/plugins/plugin.tooltip.js +++ b/src/plugins/plugin.tooltip.js @@ -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'] }; diff --git a/test/specs/plugin.legend.tests.js b/test/specs/plugin.legend.tests.js index a5d836949..096a002d6 100644 --- a/test/specs/plugin.legend.tests.js +++ b/test/specs/plugin.legend.tests.js @@ -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} + } + )); }); });