Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable pointStyle for doughnut, pie, and polar area charts #9341

Merged
merged 2 commits into from Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/controllers/controller.doughnut.js
Expand Up @@ -364,6 +364,8 @@ DoughnutController.overrides = {
generateLabels(chart) {
const data = chart.data;
if (data.labels.length && data.datasets.length) {
const {labels: {pointStyle}} = chart.legend.options;

return data.labels.map((label, i) => {
const meta = chart.getDatasetMeta(0);
const style = meta.controller.getStyle(i);
Expand All @@ -373,6 +375,7 @@ DoughnutController.overrides = {
fillStyle: style.backgroundColor,
strokeStyle: style.borderColor,
lineWidth: style.borderWidth,
pointStyle: pointStyle,
hidden: !chart.getDataVisibility(i),

// Extra data used for toggling the correct item
Expand Down
3 changes: 3 additions & 0 deletions src/controllers/controller.polarArea.js
Expand Up @@ -155,6 +155,8 @@ PolarAreaController.overrides = {
generateLabels(chart) {
const data = chart.data;
if (data.labels.length && data.datasets.length) {
const {labels: {pointStyle}} = chart.legend.options;

return data.labels.map((label, i) => {
const meta = chart.getDatasetMeta(0);
const style = meta.controller.getStyle(i);
Expand All @@ -164,6 +166,7 @@ PolarAreaController.overrides = {
fillStyle: style.backgroundColor,
strokeStyle: style.borderColor,
lineWidth: style.borderWidth,
pointStyle: pointStyle,
hidden: !chart.getDataVisibility(i),

// Extra data used for toggling the correct item
Expand Down
29 changes: 29 additions & 0 deletions test/fixtures/plugin.legend/legend-doughnut-point-style.json
@@ -0,0 +1,29 @@
{
"config": {
"type": "doughnut",
"data": {
"labels": [""],
"datasets": [{
"data": [10],
"backgroundColor": "#00ff00",
"borderWidth": 0
}]
},
"options": {
"plugins": {
"legend": {
"labels": {
"pointStyle": "triangle",
etimberg marked this conversation as resolved.
Show resolved Hide resolved
"usePointStyle": true
}
}
}
}
},
"options": {
"canvas": {
"height": 256,
"width": 512
}
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 12 additions & 6 deletions test/specs/global.defaults.tests.js
Expand Up @@ -103,23 +103,26 @@ describe('Default Configs', function() {
index: 0,
strokeStyle: '#000',
textAlign: undefined,
lineWidth: 2
lineWidth: 2,
pointStyle: undefined
}, {
text: 'label2',
fillStyle: 'green',
hidden: false,
index: 1,
strokeStyle: '#000',
textAlign: undefined,
lineWidth: 2
lineWidth: 2,
pointStyle: undefined
}, {
text: 'label3',
fillStyle: 'blue',
hidden: false,
index: 2,
strokeStyle: '#000',
textAlign: undefined,
lineWidth: 2
lineWidth: 2,
pointStyle: undefined
}];
expect(chart.legend.legendItems).toEqual(expected);
});
Expand Down Expand Up @@ -197,23 +200,26 @@ describe('Default Configs', function() {
index: 0,
strokeStyle: '#000',
textAlign: undefined,
lineWidth: 2
lineWidth: 2,
pointStyle: undefined
}, {
text: 'label2',
fillStyle: 'green',
hidden: false,
index: 1,
strokeStyle: '#000',
textAlign: undefined,
lineWidth: 2
lineWidth: 2,
pointStyle: undefined
}, {
text: 'label3',
fillStyle: 'blue',
hidden: false,
index: 2,
strokeStyle: '#000',
textAlign: undefined,
lineWidth: 2
lineWidth: 2,
pointStyle: undefined
}];
expect(chart.legend.legendItems).toEqual(expected);
});
Expand Down