const defaultColor = defaults.color;
const rtlHelper = getRtlAdapter(opts.rtl, this.left, this.width);
const labelFont = toFont(labelOpts.font);
- const {color: fontColor, padding} = labelOpts;
+ const {padding} = labelOpts;
const fontSize = labelFont.size;
const halfFontSize = fontSize / 2;
let cursor;
const lineHeight = itemHeight + padding;
this.legendItems.forEach((legendItem, i) => {
- // TODO: Remove fallbacks at v4
- ctx.strokeStyle = legendItem.fontColor || fontColor; // for strikethrough effect
- ctx.fillStyle = legendItem.fontColor || fontColor; // render in correct colour
+ ctx.strokeStyle = legendItem.fontColor; // for strikethrough effect
+ ctx.fillStyle = legendItem.fontColor; // render in correct colour
const textWidth = ctx.measureText(legendItem.text).width;
const textAlign = rtlHelper.textAlign(legendItem.textAlign || (legendItem.textAlign = labelOpts.textAlign));
// lineWidth :
generateLabels(chart) {
const datasets = chart.data.datasets;
- const {labels: {usePointStyle, pointStyle, textAlign, color}} = chart.legend.options;
+ const {labels: {usePointStyle, pointStyle, textAlign, color, useBorderRadius, borderRadius}} = chart.legend.options;
return chart._getSortedDatasetMetas().map((meta) => {
const style = meta.controller.getStyle(usePointStyle ? 0 : undefined);
pointStyle: pointStyle || style.pointStyle,
rotation: style.rotation,
textAlign: textAlign || style.textAlign,
- borderRadius: 0, // TODO: v4, default to style.borderRadius
+ borderRadius: useBorderRadius && (borderRadius || style.borderRadius),
// Below is extra data used for toggling the datasets
datasetIndex: meta.index
expect(chart.legend.legendItems).toEqual([{
text: 'dataset1',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: '#f31',
fontColor: '#666',
hidden: false,
datasetIndex: 0
}, {
text: 'dataset2',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: 'rgba(0,0,0,0.1)',
fontColor: '#666',
hidden: true,
datasetIndex: 1
}, {
text: 'dataset3',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: 'rgba(0,0,0,0.1)',
fontColor: '#666',
hidden: false,
expect(chart.legend.legendItems).toEqual([{
text: 'dataset1',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: '#f31',
fontColor: '#666',
hidden: false,
datasetIndex: 0
}, {
text: 'dataset2',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: 'rgba(0,0,0,0.1)',
fontColor: '#666',
hidden: true,
datasetIndex: 1
}, {
text: 'dataset3',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: 'rgba(0,0,0,0.1)',
fontColor: '#666',
hidden: false,
expect(chart.legend.legendItems).toEqual([{
text: 'dataset3',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: 'rgba(0,0,0,0.1)',
fontColor: '#666',
hidden: false,
datasetIndex: 2
}, {
text: 'dataset2',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: 'rgba(0,0,0,0.1)',
fontColor: '#666',
hidden: true,
datasetIndex: 1
}, {
text: 'dataset1',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: '#f31',
fontColor: '#666',
hidden: false,
hidden: true,
borderJoinStyle: 'miter',
data: [],
- legendHidden: true
+ legendHidden: true,
}, {
label: 'dataset3',
borderWidth: 10,
+ borderRadius: 10,
borderColor: 'green',
pointStyle: 'crossRot',
data: []
expect(chart.legend.legendItems).toEqual([{
text: 'dataset1',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: '#f31',
fontColor: '#666',
hidden: false,
datasetIndex: 0
}, {
text: 'dataset3',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: 'rgba(0,0,0,0.1)',
fontColor: '#666',
hidden: false,
expect(chart.legend.legendItems).toEqual([{
text: 'dataset3',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: 'rgba(0,0,0,0.1)',
fontColor: '#666',
hidden: false,
datasetIndex: 2
}, {
text: 'dataset2',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: 'rgba(0,0,0,0.1)',
fontColor: '#666',
hidden: true,
datasetIndex: 1
}, {
text: 'dataset1',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: '#f31',
fontColor: '#666',
hidden: false,
expect(chart.legend.legendItems).toEqual([{
text: 'dataset1',
- borderRadius: 0,
+ borderRadius: undefined,
+ fillStyle: '#f31',
+ fontColor: '#666',
+ hidden: false,
+ lineCap: undefined,
+ lineDash: undefined,
+ lineDashOffset: undefined,
+ lineJoin: undefined,
+ lineWidth: 5,
+ strokeStyle: 'red',
+ pointStyle: undefined,
+ rotation: undefined,
+ textAlign: undefined,
+ datasetIndex: 0
+ }]);
+ });
+
+ it('should use the borderRadius in the legend', function() {
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [{
+ label: 'dataset1',
+ backgroundColor: ['#f31', '#666', '#14e'],
+ borderWidth: [5, 10, 15],
+ borderColor: ['red', 'green', 'blue'],
+ borderRadius: 10,
+ data: []
+ }],
+ labels: []
+ },
+ options: {
+ plugins: {
+ legend: {
+ labels: {
+ useBorderRadius: true,
+ }
+ }
+ }
+ }
+ });
+
+ expect(chart.legend.legendItems).toEqual([{
+ text: 'dataset1',
+ borderRadius: 10,
fillStyle: '#f31',
fontColor: '#666',
hidden: false,
expect(chart.legend.legendItems).toEqual([{
text: 'dataset1',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: 'rgb(50, 0, 0)',
fontColor: '#666',
hidden: false,
expect(chart.legend.legendItems).toEqual([{
text: 'dataset1',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: 'rgba(0,0,0,0.1)',
fontColor: '#666',
hidden: false,
datasetIndex: 0
}, {
text: 'dataset2',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: '#f31',
fontColor: '#666',
hidden: false,
expect(chart.legend.legendItems).toEqual([{
text: 'dataset1',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: 'rgba(0,0,0,0.1)',
fontColor: '#666',
hidden: false,
datasetIndex: 0
}, {
text: 'dataset2',
- borderRadius: 0,
+ borderRadius: undefined,
fillStyle: '#f31',
fontColor: '#666',
hidden: false,