Skip to content

Commit c52890c

Browse files
committed
simplify text placement logic
1 parent 97f0b0e commit c52890c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/traces/bar/plot.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,21 @@ function appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, r, overhead, op
473473
var barWidth = lx - 2 * TEXTPAD;
474474
var barHeight = ly - 2 * TEXTPAD;
475475

476+
// If corners are rounded, subtract extra from barWidth and barHeight
477+
// to account for rounding
478+
if(barIsRounded) {
479+
if(hasB) {
480+
barWidth -= 2 * r;
481+
barHeight -= 2 * r;
482+
} else if(isHorizontal) {
483+
barWidth -= r - overhead;
484+
} else {
485+
barHeight -= r - overhead;
486+
}
487+
}
488+
476489
var textSelection;
490+
477491
var textBB;
478492
var textWidth;
479493
var textHeight;
@@ -503,10 +517,10 @@ function appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, r, overhead, op
503517
(barWidth >= textWidth * (barHeight / textHeight)) :
504518
(barHeight >= textHeight * (barWidth / textWidth));
505519

506-
if(textHasSize && (barIsRounded || (
520+
if(textHasSize && (
507521
fitsInside ||
508522
fitsInsideIfRotated ||
509-
fitsInsideIfShrunk))
523+
fitsInsideIfShrunk)
510524
) {
511525
textPosition = 'inside';
512526
} else {

0 commit comments

Comments
 (0)