Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e96f7e1

Browse files
committed
More complete bar_multiline_labels test with the change disabled.
1 parent 8f8876c commit e96f7e1

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

src/plots/cartesian/axes.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,6 +2037,26 @@ axes.doTicks = function(gd, axid, skipTitle) {
20372037
});
20382038
}
20392039

2040+
// How much to shift a multi-line label to center it vertically.
2041+
function getAnchorHeight(lineCount, lineHeight, angle) {
2042+
var h = (lineCount - 1) * lineHeight;
2043+
if (axLetter === 'x') {
2044+
if (angle < -20 || 20 < angle) {
2045+
return -0.5 * h;
2046+
} else if (axside === 'top') {
2047+
return -h;
2048+
}
2049+
} else {
2050+
angle *= axside === 'left' ? 1 : -1;
2051+
if (angle < -20) {
2052+
return -h;
2053+
} else if (angle < 20) {
2054+
return -0.5 * h;
2055+
}
2056+
}
2057+
return 0;
2058+
}
2059+
20402060
function positionLabels(s, angle) {
20412061
s.each(function(d) {
20422062
var anchor = labelanchor(angle, d);
@@ -2047,22 +2067,12 @@ axes.doTicks = function(gd, axid, skipTitle) {
20472067
(' rotate(' + angle + ',' + labelx(d) + ',' +
20482068
(labely(d) - d.fontSize / 2) + ')') :
20492069
'');
2050-
var extraHeight = d.text ?
2051-
(d.text.split('<br>').length - 1) * LINE_SPACING * d.fontSize : 0;
2052-
if (axLetter === 'x') {
2053-
if (angle < -20 || 20 < angle) {
2054-
transform += ' translate(0, ' + (-0.5 * extraHeight) + ')';
2055-
} else if (axside === 'top') {
2056-
transform += ' translate(0, ' + (-extraHeight) + ')';
2057-
}
2058-
} else {
2059-
var textAngle = isNumeric(angle) ? +angle : 0;
2060-
textAngle *= axside === 'left' ? 1 : -1;
2061-
if (textAngle < -20) {
2062-
transform += ' translate(0, ' + (-extraHeight) + ')';
2063-
} else if (textAngle < 20) {
2064-
transform += ' translate(0, ' + (-0.5 * extraHeight) + ')';
2065-
}
2070+
var anchorHeight = getAnchorHeight(
2071+
svgTextUtils.lineCount(thisLabel),
2072+
LINE_SPACING * d.fontSize,
2073+
isNumeric(angle) ? +angle : 0);
2074+
if (anchorHeight) {
2075+
//transform += ' translate(0, ' + anchorHeight + ')';
20662076
}
20672077
if(mathjaxGroup.empty()) {
20682078
thisLabel.select('text').attr({
61.2 KB
Loading

test/image/mocks/bar_multiline_labels.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,56 @@
11
{
22
"data":[
33
{
4-
"x":["x 1","multiple<br>lines","one<br>two<br>three"],
5-
"y":["x 2","multiple<br>lines","one<br>two<br>three"]
4+
"type": "bar",
5+
"x":["x 1","multiple<br>lines","one<br >two<BR>three"],
6+
"y":["x 2","multiple<br>lines","one<br >two<BR>three"]
67
},
78
{
9+
"type": "bar",
810
"x":["x 2","multiple<br>lines","one<br>two<br>three"],
911
"y":["y 2","multiple<br>lines","one<br>two<br>three"],
1012
"xaxis": "x2",
1113
"yaxis": "y2"
1214
},
1315
{
16+
"type": "bar",
1417
"x":["x 3","multiple<br>lines","one<br>two<br>three"],
1518
"y":["y 3","multiple<br>lines","one<br>two<br>three"],
1619
"xaxis": "x3",
1720
"yaxis": "y3"
1821
},
1922
{
23+
"type": "bar",
2024
"x":["x 4","multiple<br>lines","one<br>two<br>three"],
2125
"y":["y 4","multiple<br>lines","one<br>two<br>three"],
2226
"xaxis": "x4",
2327
"yaxis": "y4"
2428
},
2529
{
30+
"type": "bar",
31+
"orientation": "h",
2632
"x":["x 5","multiple<br>lines","one<br>two<br>three"],
2733
"y":["y 5","multiple<br>lines","one<br>two<br>three"],
2834
"xaxis": "x5",
2935
"yaxis": "y5"
3036
},
3137
{
38+
"type": "bar",
39+
"orientation": "h",
3240
"x":["x 6","multiple<br>lines","one<br>two<br>three"],
3341
"y":["y 6","multiple<br>lines","one<br>two<br>three"],
3442
"xaxis": "x6",
3543
"yaxis": "y6"
3644
},
3745
{
46+
"type": "scatter",
3847
"x":["x 7","multiple<br>lines","one<br>two<br>three"],
3948
"y":["y 7","multiple<br>lines","one<br>two<br>three"],
4049
"xaxis": "x7",
4150
"yaxis": "y7"
4251
},
4352
{
53+
"type": "scatter",
4454
"x":["x 8","multiple<br>lines","one<br>two<br>three"],
4555
"y":["y 8","multiple<br>lines","one<br>two<br>three"],
4656
"xaxis": "x8",

0 commit comments

Comments
 (0)