Skip to content

Commit b3feb85

Browse files
committed
can center labels using uniform mode as they'll get hidden if too big
1 parent 8c47c16 commit b3feb85

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/traces/pie/plot.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function plot(gd, cdModule) {
167167
if(textPosition === 'outside') {
168168
transform = transformOutsideText(textBB, pt);
169169
} else {
170-
transform = transformInsideText(textBB, pt, cd0);
170+
transform = transformInsideText(textBB, pt, cd0, fullLayout);
171171
if(textPosition === 'auto' && transform.scale < 1) {
172172
var newFont = Lib.ensureUniformFontSize(gd, trace.outsidetextfont);
173173

@@ -635,7 +635,7 @@ function prerenderTitles(cdModule, gd) {
635635
}
636636
}
637637

638-
function transformInsideText(textBB, pt, cd0) {
638+
function transformInsideText(textBB, pt, cd0, fullLayout) {
639639
var r = cd0.r || pt.rpx1;
640640
var rInscribed = pt.rInscribed;
641641

@@ -660,6 +660,7 @@ function transformInsideText(textBB, pt, cd0) {
660660
var isTangential = orientation === 'tangential';
661661
var isRadial = orientation === 'radial';
662662
var isAuto = orientation === 'auto';
663+
var isUniformModeHide = fullLayout.uniformtext.mode === 'hide';
663664

664665
var allTransforms = [];
665666
var newT;
@@ -723,7 +724,7 @@ function transformInsideText(textBB, pt, cd0) {
723724
}
724725

725726
if(isAuto || isRadial) {
726-
newT = calcRadTransform(textBB, r, ring, halfAngle, midAngle);
727+
newT = calcRadTransform(textBB, r, ring, halfAngle, midAngle, isUniformModeHide);
727728
newT.textPosAngle = (pt.startangle + pt.stopangle) / 2;
728729
allTransforms.push(newT);
729730
}
@@ -760,15 +761,15 @@ function isCrossing(pt, angle) {
760761
);
761762
}
762763

763-
function calcRadTransform(textBB, r, ring, halfAngle, midAngle) {
764+
function calcRadTransform(textBB, r, ring, halfAngle, midAngle, isUniformModeHide) {
764765
r = Math.max(0, r - 2 * TEXTPAD);
765766

766767
// max size if text is rotated radially
767768
var a = textBB.width / textBB.height;
768769
var s = calcMaxHalfSize(a, halfAngle, r, ring);
769770
return {
770771
scale: s * 2 / textBB.height,
771-
rCenter: calcRCenter(a, s / r),
772+
rCenter: isUniformModeHide ? calcRingCenter(ring) : calcRCenter(a, s / r),
772773
rotate: calcRotate(midAngle)
773774
};
774775
}
@@ -790,6 +791,10 @@ function calcRCenter(a, b) {
790791
return Math.cos(b) - a * b;
791792
}
792793

794+
function calcRingCenter(ring) {
795+
return 1 - ring / 2;
796+
}
797+
793798
function calcRotate(t) {
794799
return (180 / Math.PI * t + 720) % 180 - 90;
795800
}

src/traces/sunburst/plot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ function plotOne(gd, cd, element, transitionOpts) {
275275

276276
// position the text relative to the slice
277277
var textBB = Drawing.bBox(sliceText.node());
278-
pt.transform = transformInsideText(textBB, pt, cd0);
278+
pt.transform = transformInsideText(textBB, pt, cd0, fullLayout);
279279
pt.transform.targetX = getTargetX(pt);
280280
pt.transform.targetY = getTargetY(pt);
281281

0 commit comments

Comments
 (0)