Skip to content

Commit 8b76d46

Browse files
authored
Merge pull request #5201 from plotly/sunburst-rotation-tests
more sunburst rotation
2 parents 4d821e3 + d6defa1 commit 8b76d46

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

src/traces/pie/helpers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ exports.castOption = function castOption(item, indices) {
4040
if(Array.isArray(item)) return exports.getFirstFilled(item, indices);
4141
else if(item) return item;
4242
};
43+
44+
exports.getRotationAngle = function(rotation) {
45+
return (rotation === 'auto' ? 0 : rotation) * Math.PI / 180;
46+
};

src/traces/pie/plot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ function setCoords(cd) {
10451045
var cd0 = cd[0];
10461046
var r = cd0.r;
10471047
var trace = cd0.trace;
1048-
var currentAngle = trace.rotation * Math.PI / 180;
1048+
var currentAngle = helpers.getRotationAngle(trace.rotation);
10491049
var angleFactor = 2 * Math.PI / cd0.vTotal;
10501050
var firstPt = 'px0';
10511051
var lastPt = 'px1';

src/traces/sunburst/plot.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var uniformText = require('../bar/uniform_text');
1818
var recordMinTextSize = uniformText.recordMinTextSize;
1919
var clearMinTextSize = uniformText.clearMinTextSize;
2020
var piePlot = require('../pie/plot');
21+
var getRotationAngle = require('../pie/helpers').getRotationAngle;
2122
var computeTransform = piePlot.computeTransform;
2223
var transformInsideText = piePlot.transformInsideText;
2324
var styleOne = require('./style').styleOne;
@@ -150,11 +151,11 @@ function plotOne(gd, cd, element, transitionOpts) {
150151
// filter out slices that won't show up on graph
151152
sliceData = sliceData.filter(function(pt) { return pt.y1 <= cutoff; });
152153

153-
if(trace.rotation && trace.rotation !== 'auto') {
154-
var extraAngle = trace.rotation * Math.PI / 180;
154+
var baseX = getRotationAngle(trace.rotation);
155+
if(baseX) {
155156
sliceData.forEach(function(pt) {
156-
pt.x0 += extraAngle;
157-
pt.x1 += extraAngle;
157+
pt.x0 += baseX;
158+
pt.x1 += baseX;
158159
});
159160
}
160161

@@ -310,7 +311,7 @@ function plotOne(gd, cd, element, transitionOpts) {
310311
var next;
311312

312313
if(entryPrev) {
313-
var a = pt.x1 > entryPrev.x1 ? 2 * Math.PI : 0;
314+
var a = (pt.x1 > entryPrev.x1 ? 2 * Math.PI : 0) + baseX;
314315
// if pt to remove:
315316
// - if 'below' where the root-node used to be: shrink it radially inward
316317
// - otherwise, collapse it clockwise or counterclockwise which ever is shortest to theta=0
@@ -360,7 +361,7 @@ function plotOne(gd, cd, element, transitionOpts) {
360361
// if new branch, twist it in clockwise or
361362
// counterclockwise which ever is shorter to
362363
// its final angle
363-
var a = pt.x1 > nextX1ofPrevEntry ? 2 * Math.PI : 0;
364+
var a = (pt.x1 > nextX1ofPrevEntry ? 2 * Math.PI : 0) + baseX;
364365
prev = {x0: a, x1: a};
365366
} else {
366367
// if new leaf (when maxdepth is set),
@@ -375,7 +376,7 @@ function plotOne(gd, cd, element, transitionOpts) {
375376
}
376377
} else {
377378
// start sector of new traces from theta=0
378-
prev = {x0: 0, x1: 0};
379+
prev = {x0: baseX, x1: baseX};
379380
}
380381
}
381382

@@ -418,11 +419,11 @@ function plotOne(gd, cd, element, transitionOpts) {
418419
}
419420
} else {
420421
// if new root-node
421-
prev.x0 = prev.x1 = 0;
422+
prev.x0 = prev.x1 = baseX;
422423
}
423424
} else {
424425
// on new traces
425-
prev.x0 = prev.x1 = 0;
426+
prev.x0 = prev.x1 = baseX;
426427
}
427428
}
428429

1.71 KB
Loading

test/image/mocks/treemap_sunburst_basic.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
194194
},
195195
{
196196
"type": "sunburst",
197+
"rotation": 180,
197198
"level": "",
198199
"labels": [
199200
"A1",
@@ -295,6 +296,7 @@
295296
},
296297
{
297298
"type": "sunburst",
299+
"rotation": 90,
298300
"level": "",
299301
"labels": [
300302
"C1",

0 commit comments

Comments
 (0)