Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/plugins/plugin.legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: ['']
};
3 changes: 0 additions & 3 deletions src/plugins/plugin.title.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,4 @@ export default {
defaultRoutes: {
color: 'color'
},

// For easier configuration, resolve additionally from root of options and defaults.
additionalOptionScopes: ['']
};
4 changes: 2 additions & 2 deletions src/plugins/plugin.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
};
65 changes: 62 additions & 3 deletions test/specs/plugin.legend.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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}
}
));
});
});

Expand Down