Skip to content

more sunburst rotation #5201

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

Merged
merged 3 commits into from
Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/traces/pie/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ exports.castOption = function castOption(item, indices) {
if(Array.isArray(item)) return exports.getFirstFilled(item, indices);
else if(item) return item;
};

exports.getRotationAngle = function(rotation) {
return (rotation === 'auto' ? 0 : rotation) * Math.PI / 180;
};
2 changes: 1 addition & 1 deletion src/traces/pie/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ function setCoords(cd) {
var cd0 = cd[0];
var r = cd0.r;
var trace = cd0.trace;
var currentAngle = trace.rotation * Math.PI / 180;
var currentAngle = helpers.getRotationAngle(trace.rotation);
var angleFactor = 2 * Math.PI / cd0.vTotal;
var firstPt = 'px0';
var lastPt = 'px1';
Expand Down
19 changes: 10 additions & 9 deletions src/traces/sunburst/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var uniformText = require('../bar/uniform_text');
var recordMinTextSize = uniformText.recordMinTextSize;
var clearMinTextSize = uniformText.clearMinTextSize;
var piePlot = require('../pie/plot');
var getRotationAngle = require('../pie/helpers').getRotationAngle;
var computeTransform = piePlot.computeTransform;
var transformInsideText = piePlot.transformInsideText;
var styleOne = require('./style').styleOne;
Expand Down Expand Up @@ -150,11 +151,11 @@ function plotOne(gd, cd, element, transitionOpts) {
// filter out slices that won't show up on graph
sliceData = sliceData.filter(function(pt) { return pt.y1 <= cutoff; });

if(trace.rotation && trace.rotation !== 'auto') {
var extraAngle = trace.rotation * Math.PI / 180;
var baseX = getRotationAngle(trace.rotation);
if(baseX) {
sliceData.forEach(function(pt) {
pt.x0 += extraAngle;
pt.x1 += extraAngle;
pt.x0 += baseX;
pt.x1 += baseX;
});
}

Expand Down Expand Up @@ -310,7 +311,7 @@ function plotOne(gd, cd, element, transitionOpts) {
var next;

if(entryPrev) {
var a = pt.x1 > entryPrev.x1 ? 2 * Math.PI : 0;
var a = (pt.x1 > entryPrev.x1 ? 2 * Math.PI : 0) + baseX;
// if pt to remove:
// - if 'below' where the root-node used to be: shrink it radially inward
// - otherwise, collapse it clockwise or counterclockwise which ever is shortest to theta=0
Expand Down Expand Up @@ -360,7 +361,7 @@ function plotOne(gd, cd, element, transitionOpts) {
// if new branch, twist it in clockwise or
// counterclockwise which ever is shorter to
// its final angle
var a = pt.x1 > nextX1ofPrevEntry ? 2 * Math.PI : 0;
var a = (pt.x1 > nextX1ofPrevEntry ? 2 * Math.PI : 0) + baseX;
prev = {x0: a, x1: a};
} else {
// if new leaf (when maxdepth is set),
Expand All @@ -375,7 +376,7 @@ function plotOne(gd, cd, element, transitionOpts) {
}
} else {
// start sector of new traces from theta=0
prev = {x0: 0, x1: 0};
prev = {x0: baseX, x1: baseX};
}
}

Expand Down Expand Up @@ -418,11 +419,11 @@ function plotOne(gd, cd, element, transitionOpts) {
}
} else {
// if new root-node
prev.x0 = prev.x1 = 0;
prev.x0 = prev.x1 = baseX;
}
} else {
// on new traces
prev.x0 = prev.x1 = 0;
prev.x0 = prev.x1 = baseX;
}
}

Expand Down
Binary file modified test/image/baselines/treemap_sunburst_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions test/image/mocks/treemap_sunburst_basic.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
},
{
"type": "sunburst",
"rotation": 180,
"level": "",
"labels": [
"A1",
Expand Down Expand Up @@ -295,6 +296,7 @@
},
{
"type": "sunburst",
"rotation": 90,
"level": "",
"labels": [
"C1",
Expand Down