Skip to content

Commit

Permalink
Enable pointStyle for doughnut, pie, and polar area charts (#9341)
Browse files Browse the repository at this point in the history
* Enable pointStyle for doughnut, pie, and polar area charts

* Fix whitespace
  • Loading branch information
etimberg committed Jul 1, 2021
1 parent 3a79032 commit 3934935
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
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",
"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

0 comments on commit 3934935

Please sign in to comment.