Remove core plugin fallbacks to root options (#8462)

* Remove core plugin fallbacks to root options
* Legend font color default fallbacks
This commit is contained in:
Jukka Kurkela 2021-02-20 00:53:01 +02:00 committed by GitHub
parent ce0f7ff903
commit aa5e0fe413
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 17 deletions

View 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: ['']
};

View File

@ -180,7 +180,4 @@ export default {
defaultRoutes: {
color: 'color'
},
// For easier configuration, resolve additionally from root of options and defaults.
additionalOptionScopes: ['']
};

View 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']
};

View 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}
}
));
});
});