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

Enhance hole property in Pie Chart for variable slice radii #6769

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions draftlogs/6769_add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Enhance `hole` property in Pie Chart for variable slice radii [[#6769](https://github.com/plotly/plotly.js/pull/6769)]
1 change: 1 addition & 0 deletions src/traces/pie/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ module.exports = {
max: 1,
dflt: 0,
editType: 'calc',
arrayOk: true,
description: [
'Sets the fraction of the radius to cut out of the pie.',
'Use this to make a donut chart.'
Expand Down
8 changes: 4 additions & 4 deletions src/traces/pie/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function plot(gd, cdModule) {
pt.largeArc + (cw ? ' 1 ' : ' 0 ') + dx + ',' + dy;
}

var hole = trace.hole;
var hole = trace.hole[i] || trace.hole;
barrymichaeldoyle marked this conversation as resolved.
Show resolved Hide resolved
if(pt.v === cd0.vTotal) { // 100% fails bcs arc start and end are identical
var outerCircle = 'M' + (cx + pt.px0[0]) + ',' + (cy + pt.px0[1]) +
arc(pt.px0, pt.pxmid, true, 1) +
Expand Down Expand Up @@ -731,7 +731,7 @@ function calcMaxHalfSize(a, halfAngle, r, ring) {
}

function getInscribedRadiusFraction(pt, cd0) {
if(pt.v === cd0.vTotal && !cd0.trace.hole) return 1;// special case of 100% with no hole
if(pt.v === cd0.vTotal && !(cd0.trace.hole[0] || cd0.trace.hole)) return 1;// special case of 100% with no hole
barrymichaeldoyle marked this conversation as resolved.
Show resolved Hide resolved

return Math.min(1 / (1 + 1 / Math.sin(pt.halfangle)), pt.ring / 2);
}
Expand Down Expand Up @@ -761,7 +761,7 @@ function positionTitleInside(cd0) {
return {
x: cd0.cx,
y: cd0.cy,
scale: cd0.trace.hole * cd0.r * 2 / textDiameter,
scale: (cd0.trace.hole[0] || cd0.trace.hole) * cd0.r * 2 / textDiameter,
barrymichaeldoyle marked this conversation as resolved.
Show resolved Hide resolved
tx: 0,
ty: - cd0.titleBox.height / 2 + cd0.trace.title.font.size
};
Expand Down Expand Up @@ -1089,7 +1089,7 @@ function setCoords(cd) {
cdi.largeArc = (cdi.v > cd0.vTotal / 2) ? 1 : 0;

cdi.halfangle = Math.PI * Math.min(cdi.v / cd0.vTotal, 0.5);
cdi.ring = 1 - trace.hole;
cdi.ring = 1 - (trace.hole[i] || trace.hole);
barrymichaeldoyle marked this conversation as resolved.
Show resolved Hide resolved
cdi.rInscribed = getInscribedRadiusFraction(cdi, cd0);
}
}
Expand Down
1 change: 1 addition & 0 deletions test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -42615,6 +42615,7 @@
}
},
"hole": {
"arrayOk": true,
"description": "Sets the fraction of the radius to cut out of the pie. Use this to make a donut chart.",
"dflt": 0,
"editType": "calc",
Expand Down