diff --git a/src/traces/pie/helpers.js b/src/traces/pie/helpers.js index 6bf06b43fd6..0131283c9bd 100644 --- a/src/traces/pie/helpers.js +++ b/src/traces/pie/helpers.js @@ -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; +}; diff --git a/src/traces/pie/plot.js b/src/traces/pie/plot.js index 9dd866c04f0..3a1acc76749 100644 --- a/src/traces/pie/plot.js +++ b/src/traces/pie/plot.js @@ -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'; diff --git a/src/traces/sunburst/plot.js b/src/traces/sunburst/plot.js index dc69381c685..f80d707c0fe 100644 --- a/src/traces/sunburst/plot.js +++ b/src/traces/sunburst/plot.js @@ -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; @@ -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; }); } @@ -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 @@ -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), @@ -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}; } } @@ -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; } } diff --git a/test/image/baselines/treemap_sunburst_basic.png b/test/image/baselines/treemap_sunburst_basic.png index c7716c8308c..0e5970bd860 100644 Binary files a/test/image/baselines/treemap_sunburst_basic.png and b/test/image/baselines/treemap_sunburst_basic.png differ diff --git a/test/image/mocks/treemap_sunburst_basic.json b/test/image/mocks/treemap_sunburst_basic.json index f7519e7a0ea..4b007666119 100644 --- a/test/image/mocks/treemap_sunburst_basic.json +++ b/test/image/mocks/treemap_sunburst_basic.json @@ -194,6 +194,7 @@ }, { "type": "sunburst", + "rotation": 180, "level": "", "labels": [ "A1", @@ -295,6 +296,7 @@ }, { "type": "sunburst", + "rotation": 90, "level": "", "labels": [ "C1",