Skip to content

Commit a6dde4c

Browse files
author
wfr
committed
Add bottom-up and right-left orientations to Sankey
Adjust node label alignment for vertical case (labels below still need work)
1 parent 348aa23 commit a6dde4c

1 file changed

Lines changed: 23 additions & 19 deletions

File tree

src/traces/sankey/render.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,8 +1069,10 @@ module.exports = function(gd, svg, calcData, layout, callbacks) {
10691069
svgTextUtils.convertToTspans(e, gd);
10701070
})
10711071
.attr('text-anchor', function(d) {
1072-
// right-left mirrors the layout horizontally, so the outer side (and anchor) flips.
1073-
return (d.horizontal && (d.left !== d.rightLeft)) ? 'end' : 'start';
1072+
// vertical: labels are centered over the node. horizontal: aligned to the outer
1073+
// edge (right-left mirrors the layout, so the outer side and anchor flip).
1074+
if(!d.horizontal) return 'middle';
1075+
return (d.left !== d.rightLeft) ? 'end' : 'start';
10741076
})
10751077
.attr('transform', function(d) {
10761078
var e = d3.select(this);
@@ -1080,25 +1082,27 @@ module.exports = function(gd, svg, calcData, layout, callbacks) {
10801082
(nLines - 1) * LINE_SPACING - CAP_SHIFT
10811083
);
10821084

1083-
var posX = d.nodeLineWidth / 2 + TEXTPAD;
1084-
var posY = ((d.horizontal ? d.visibleHeight : d.visibleWidth) - blockHeight) / 2;
1085-
if(d.horizontal) {
1086-
if(d.left) {
1087-
posX = -posX;
1088-
} else {
1089-
posX += d.visibleWidth;
1090-
}
1091-
}
1085+
var pad = d.nodeLineWidth / 2 + TEXTPAD;
10921086

1093-
var flipText = d.horizontal ?
1094-
(d.rightLeft ? 'scale(-1,1)' : '') : (
1095-
d.bottomUp ? strRotate(90) : ('scale(-1,1)' + strRotate(90))
1096-
);
1087+
if(!d.horizontal) {
1088+
var across = d.visibleHeight / 2;
1089+
var gap = pad + CAP_SHIFT * d.textFont.size;
1090+
// letzte Spalte (originalLayer === 1): Label nach innen, damit es nicht ueber den
1091+
// aeusseren Plot-Rand laeuft - analog zum horizontalen d.left-Fall.
1092+
var outside = d.left ? -gap : (d.visibleWidth + gap);
1093+
var flipV = d.bottomUp ? strRotate(90) : ('scale(-1,1)' + strRotate(90));
1094+
return strTranslate(outside, across) + flipV;
1095+
}
10971096

1098-
return strTranslate(
1099-
d.horizontal ? posX : posY,
1100-
d.horizontal ? posY : posX
1101-
) + flipText;
1097+
// horizontal: center along the node length, place just past the thickness edge.
1098+
var posX = pad;
1099+
var posY = (d.visibleHeight - blockHeight) / 2;
1100+
if(d.left) {
1101+
posX = -posX;
1102+
} else {
1103+
posX += d.visibleWidth;
1104+
}
1105+
return strTranslate(posX, posY) + (d.rightLeft ? 'scale(-1,1)' : '');
11021106
});
11031107

11041108
nodeLabel

0 commit comments

Comments
 (0)