@@ -1067,9 +1067,9 @@ module.exports = function(gd, svg, calcData, layout, callbacks) {
10671067 svgTextUtils . convertToTspans ( e , gd ) ;
10681068 } )
10691069 . attr ( 'text-anchor' , function ( d ) {
1070- // vertical: labels are centered over the node. horizontal: aligned to the outer
1071- // edge (reverse mirrors the layout, so the outer side and anchor flip) .
1072- if ( ! d . horizontal ) return 'middle ' ;
1070+ // horizontal: aligned to the outer edge (reverse flips which side is outer).
1071+ // vertical: inside-node placement, anchored at 'start' .
1072+ if ( ! d . horizontal ) return 'start ' ;
10731073 return ( d . left !== d . reverse ) ? 'end' : 'start' ;
10741074 } )
10751075 . attr ( 'transform' , function ( d ) {
@@ -1083,12 +1083,18 @@ module.exports = function(gd, svg, calcData, layout, callbacks) {
10831083 var pad = d . nodeLineWidth / 2 + TEXTPAD ;
10841084
10851085 if ( ! d . horizontal ) {
1086- var posY = d . visibleHeight / 2 ;
1087- // last Column (originalLayer === 1): put label towards center.
1088- var posX = d . reverse ?
1089- ( d . left ? - ( pad + CAP_SHIFT * d . textFont . size ) : ( d . visibleWidth + pad ) ) : ( d . left ? - pad : ( d . visibleWidth + pad + CAP_SHIFT * d . textFont . size ) ) ;
1086+ // vertical: label sits inside the node, centered along its length.
1087+ // forward's local flip (scale(-1,1) + rotate(90)) is a reflection,
1088+ // reverse's (rotate(90) alone) a pure rotation; the group
1089+ // matrix has the same opposing handedness. That flips the sign with which
1090+ // the CAP_SHIFT baseline correction (baked into blockHeight) lands on
1091+ // screen, so it must be applied with the opposite sign for reverse -
1092+ // otherwise the label renders about half a line height too high.
1093+ var posY = d . reverse
1094+ ? ( d . visibleWidth + blockHeight ) / 2
1095+ : ( d . visibleWidth - blockHeight ) / 2 ;
10901096 var flipV = d . reverse ? strRotate ( 90 ) : ( 'scale(-1,1)' + strRotate ( 90 ) ) ;
1091- return strTranslate ( posX , posY ) + flipV ;
1097+ return strTranslate ( posY , pad ) + flipV ;
10921098 }
10931099
10941100 // horizontal: center along the node length, place just past the thickness edge.
0 commit comments