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
9 changes: 6 additions & 3 deletions src/traces/pie/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ function plot(gd, cdModule) {
}

var hole = trace.hole;
if(hole) {
hole = +helpers.castOption(trace.hole, pt.pts) || 0;
}
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 +734,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 && !(Lib.isArrayOrTypedArray(cd0.trace.hole) ? [pt.i] : cd0.trace.hole)) return 1;// special case of 100% with no hole

return Math.min(1 / (1 + 1 / Math.sin(pt.halfangle)), pt.ring / 2);
}
Expand Down Expand Up @@ -761,7 +764,7 @@ function positionTitleInside(cd0) {
return {
x: cd0.cx,
y: cd0.cy,
scale: cd0.trace.hole * cd0.r * 2 / textDiameter,
scale: (Lib.isArrayOrTypedArray(cd0.trace.hole) ? Math.min.apply(null, cd0.trace.hole) : cd0.trace.hole) * cd0.r * 2 / textDiameter,
tx: 0,
ty: - cd0.titleBox.height / 2 + cd0.trace.title.font.size
};
Expand Down Expand Up @@ -1089,7 +1092,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 - (Lib.isArrayOrTypedArray(cd0.trace.hole) ? trace.hole[i] : trace.hole);
cdi.rInscribed = getInscribedRadiusFraction(cdi, cd0);
}
}
Expand Down
6 changes: 6 additions & 0 deletions test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -42615,13 +42615,19 @@
}
},
"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",
"max": 1,
"min": 0,
"valType": "number"
},
"holesrc": {
"description": "Sets the source reference on Chart Studio Cloud for `hole`.",
"editType": "none",
"valType": "string"
},
"hoverinfo": {
"arrayOk": true,
"description": "Determines which trace information appear on hover. If `none` or `skip` are set, no information is displayed upon hovering. But, if `none` is set, click and hover events are still fired.",
Expand Down