Skip to content

Commit 468363e

Browse files
committed
change temp render logic
1 parent c703c11 commit 468363e

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

src/components/shapes/draw.js

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -678,18 +678,13 @@ function drawLabel(gd, index, options, shapeGroup) {
678678
}
679679
}
680680

681-
// Do a fake render so we can get the text bounding box height
682-
var _labelText = labelGroup.append('text')
683-
.attr(labelTextAttrs)
684-
.classed('shape-label-text', true)
685-
.text(text);
686-
_labelText.call(function(s) {
681+
// Do an initial render so we can get the text bounding box height
682+
labelText.call(function(s) {
687683
s.call(Drawing.font, font).attr({});
688684
svgTextUtils.convertToTspans(s, gd);
689685
return s;
690686
});
691-
var textBB = Drawing.bBox(_labelText.node());
692-
_labelText.remove();
687+
var textBB = Drawing.bBox(labelText.node());
693688

694689
// Calculate correct (x,y) for text
695690
// We also determine true xanchor since xanchor depends on position when set to 'auto'
@@ -698,23 +693,17 @@ function drawLabel(gd, index, options, shapeGroup) {
698693
var texty = textPos.texty;
699694
var xanchor = textPos.xanchor;
700695

701-
function textLayout(s) {
702-
s.call(Drawing.font, font)
703-
.attr({
704-
'text-anchor': {
705-
left: 'start',
706-
center: 'middle',
707-
right: 'end'
708-
}[xanchor],
709-
'y': texty,
710-
'x': textx,
711-
'transform': 'rotate(' + textangle + ',' + textx + ',' + texty + ')'
712-
});
713-
svgTextUtils.convertToTspans(s, gd);
714-
return s;
715-
}
716-
717-
labelText.call(textLayout);
696+
// Update (x,y) position, xanchor, and angle
697+
labelText.attr({
698+
'text-anchor': {
699+
left: 'start',
700+
center: 'middle',
701+
right: 'end'
702+
}[xanchor],
703+
'y': texty,
704+
'x': textx,
705+
'transform': 'rotate(' + textangle + ',' + textx + ',' + texty + ')'
706+
}).call(svgTextUtils.positionText, textx, texty);
718707
}
719708

720709
function calcTextAngle(shapex0, shapey0, shapex1, shapey1) {

0 commit comments

Comments
 (0)