Skip to content

Commit

Permalink
🔪 leaf.textposition (for now)
Browse files Browse the repository at this point in the history
- this would've been tricky to tween smoothly, most sunburst charts
  in the wild have text labels inside sectors only, so I didn't see
  the need to have this part of the first release.
  • Loading branch information
etpinard committed Mar 22, 2019
1 parent bb37e51 commit 160bf4b
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 74 deletions.
6 changes: 1 addition & 5 deletions src/traces/pie/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,9 +894,5 @@ function setCoords(cd) {

module.exports = {
plot: plot,
plotTextLines: plotTextLines,

transformInsideText: transformInsideText,
transformOutsideText: transformOutsideText,
scootLabels: scootLabels
transformInsideText: transformInsideText
};
10 changes: 0 additions & 10 deletions src/traces/sunburst/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,6 @@ module.exports = {
dflt: 0.7,
description: 'Sets the opacity of the leaves.'
},
// TODO might be a PITA to animate, most sunburst don't have outside
// text lable, OK to take it out?
textposition: {
valType: 'enumerated',
role: 'info',
values: ['inside', 'outside', 'auto'],
dflt: 'inside',
editType: 'plot',
description: 'Specifies the location of the leaf text labels.'
},
editType: 'plot'
},

Expand Down
1 change: 0 additions & 1 deletion src/traces/sunburst/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
handleDomainDefaults(traceOut, layout, coerce);

coerce('leaf.opacity');
coerce('leaf.textposition');

var text = coerce('text');
coerce('textinfo', Array.isArray(text) ? 'text+label' : 'label');
Expand Down
4 changes: 3 additions & 1 deletion src/traces/sunburst/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ module.exports = {

meta: {
description: [
'TODO'
'Visualize hierarchal data spanning outward radially from root to leaves.',
'The sunburst sectors are determined by the entries in *labels* or *ids*',
'and in *parents*.'
].join(' ')
}
};
59 changes: 2 additions & 57 deletions src/traces/sunburst/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ var setCursor = require('../../lib/setcursor');
var appendArrayPointValue = require('../../components/fx/helpers').appendArrayPointValue;

var transformInsideText = require('../pie/plot').transformInsideText;
var transformOutsideText = require('../pie/plot').transformOutsideText;
var scootLabels = require('../pie/plot').scootLabels;
var plotTextLines = require('../pie/plot').plotTextLines;
var formatPieValue = require('../pie/helpers').formatPieValue;
var styleOne = require('./style').styleOne;

Expand Down Expand Up @@ -180,10 +177,6 @@ function plotOne(gd, cd, element, transitionOpts) {

var sliceTextGroup = sliceTop.select('g.slicetext');
sliceTextGroup.attr('opacity', 0);

// for outside text - TODO maybe remove?
var sliceTextLine = sliceTop.select('path.textline');
sliceTextLine.attr('opacity', 0);
})
.remove();
} else {
Expand All @@ -203,13 +196,6 @@ function plotOne(gd, cd, element, transitionOpts) {
});
}

// used to scoot outside labels
var hasOutsideText = false;
var quadrants = [
[[], []], // y<0: x<0, x>=0
[[], []] // y>=0: x<0, x>=0
];

var updateSlices = slices;
if(hasTransition) {
updateSlices = updateSlices.transition().each('end', function() {
Expand All @@ -235,7 +221,6 @@ function plotOne(gd, cd, element, transitionOpts) {
pt.halfangle = 0.5 * Math.min(Lib.angleDelta(pt.x0, pt.x1) || Math.PI, Math.PI);
pt.ring = 1 - (pt.rpx0 / pt.rpx1);
pt.rInscribed = getInscribedRadiusFraction(pt, trace);
quadrants[pt.pxmid[1] < 0 ? 0 : 1][pt.pxmid[0] < 0 ? 0 : 1].push(pt);

if(hasTransition) {
slicePath.transition().attrTween('d', function(pt2) {
Expand All @@ -259,52 +244,20 @@ function plotOne(gd, cd, element, transitionOpts) {
s.attr('data-notex', 1);
});

var textPosition = isLeaf(pt) ? trace.leaf.textposition : 'inside';

sliceText.text(formatSliceLabel(pt, trace, fullLayout))
.classed('slicetext', true)
.attr('text-anchor', 'middle')
.call(Drawing.font, isHierachyRoot(pt) || textPosition === 'outside' ?
.call(Drawing.font, isHierachyRoot(pt) ?
determineOutsideTextFont(trace, pt, fullLayout.font) :
determineInsideTextFont(trace, pt, fullLayout.font))
.call(svgTextUtils.convertToTspans, gd);

// position the text relative to the slice
var textBB = Drawing.bBox(sliceText.node());
var transform;

if(textPosition === 'outside') {
transform = transformOutsideText(textBB, pt);
} else {
transform = transformInsideText(textBB, pt, cd0);
if(textPosition === 'auto' && transform.scale < 1) {
sliceText.call(Drawing.font, trace.outsidetextfont);
if(trace.outsidetextfont.family !== trace.insidetextfont.family ||
trace.outsidetextfont.size !== trace.insidetextfont.size) {
textBB = Drawing.bBox(sliceText.node());
}
transform = transformOutsideText(textBB, pt);
}
}

pt.transform = transform;
pt.transform = transformInsideText(textBB, pt, cd0);
pt.translateX = transTextX(pt);
pt.translateY = transTextY(pt);

// save some stuff to use later ensure no labels overlap
if(transform.outside) {
pt.px0 = rx2px(pt.rpx0, pt.x0);
pt.px1 = rx2px(pt.rpx1, pt.x1);
pt.cxFinal = cx;
pt.cyFinal = cy;
pt.yLabelMin = pt.translateY - textBB.height / 2;
pt.yLabelMid = pt.translateY;
pt.yLabelMax = pt.translateY + textBB.height / 2;
pt.labelExtraX = 0;
pt.labelExtraY = 0;
hasOutsideText = true;
}

var strTransform = function(d, textBB) {
return 'translate(' + d.translateX + ',' + d.translateY + ')' +
(d.transform.scale < 1 ? ('scale(' + d.transform.scale + ')') : '') +
Expand All @@ -325,12 +278,6 @@ function plotOne(gd, cd, element, transitionOpts) {
}
});

if(hasOutsideText) {
scootLabels(quadrants, trace);
}

plotTextLines(slices, trace);

function makeExitSliceInterpolator(pt) {
var id = getPtId(pt);
var prev = prevLookup[id];
Expand Down Expand Up @@ -482,8 +429,6 @@ function plotOne(gd, cd, element, transitionOpts) {
}
};

// TODO need to consider labelExtraX and labelExtraY ... at first (?)

var out = {
rpx1: rpx1Fn(t),
translateX: transTextX(d),
Expand Down

0 comments on commit 160bf4b

Please sign in to comment.