Skip to content

Commit 222357c

Browse files
committed
Set legend text x position before potential MathJax conversion,
Also extract the number 40 into a new legend constant "textOffsetX"
1 parent 6c27224 commit 222357c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Diff for: src/components/legend/constants.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ module.exports = {
1212
scrollBarWidth: 6,
1313
scrollBarMinHeight: 20,
1414
scrollBarColor: '#808BA4',
15-
scrollBarMargin: 4
15+
scrollBarMargin: 4,
16+
textOffsetX: 40
1617
};

Diff for: src/components/legend/draw.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ function drawTexts(g, gd, maxLength) {
415415
.call(Drawing.font, fullLayout.legend.font)
416416
.text(isEditable ? ensureLength(name, maxLength) : name);
417417

418+
svgTextUtils.positionText(textEl, constants.textOffsetX, 0);
419+
418420
function textLayout(s) {
419421
svgTextUtils.convertToTspans(s, gd, function() {
420422
computeTextDimensions(g, gd);
@@ -520,7 +522,7 @@ function computeTextDimensions(g, gd) {
520522
height = mathjaxBB.height;
521523
width = mathjaxBB.width;
522524

523-
Drawing.setTranslate(mathjaxGroup, 40, (height / 4));
525+
Drawing.setTranslate(mathjaxGroup, 0, (height / 4));
524526
}
525527
else {
526528
var text = g.select('.legendtext');
@@ -533,9 +535,7 @@ function computeTextDimensions(g, gd) {
533535
// approximation to height offset to center the font
534536
// to avoid getBoundingClientRect
535537
var textY = lineHeight * (0.3 + (1 - textLines) / 2);
536-
// TODO: this 40 should go in a constants file (along with other
537-
// values related to the legend symbol size)
538-
svgTextUtils.positionText(text, 40, textY);
538+
svgTextUtils.positionText(text, constants.textOffsetX, textY);
539539
}
540540

541541
height = Math.max(height, 16) + 3;

0 commit comments

Comments
 (0)