@@ -112,8 +112,6 @@ exports.convertToTspans = function(_context, gd, _callback) {
112112 var x = + _context . attr ( 'x' ) ;
113113 var y = + _context . attr ( 'y' ) ;
114114
115- var newX = x - newSvgW *
116- { start : 0 , middle : 0.5 , end : 1 } [ _context . attr ( 'text-anchor' ) || 'start' ] ;
117115 // font baseline is about 1/4 fontSize below centerline
118116 var textHeight = fontSize || _context . node ( ) . getBoundingClientRect ( ) . height ;
119117 var dy = - textHeight / 4 ;
@@ -123,15 +121,26 @@ exports.convertToTspans = function(_context, gd, _callback) {
123121 transform : 'rotate(' + [ - 90 , x , y ] +
124122 ')' + strTranslate ( - newSvgW / 2 , dy - newSvgH / 2 )
125123 } ) ;
126- newSvg . attr ( { x : x , y : y } ) ;
127124 } else if ( svgClass [ 0 ] === 'l' ) {
128- newSvg . attr ( { x : x , y : dy - ( newSvgH / 2 ) } ) ;
125+ y = dy - newSvgH / 2 ;
129126 } else if ( svgClass [ 0 ] === 'a' && svgClass . indexOf ( 'atitle' ) !== 0 ) {
130- newSvg . attr ( { x : 0 , y : dy } ) ;
127+ x = 0 ;
128+ y = dy ;
131129 } else {
132- newSvg . attr ( { x : newX , y : ( y + dy - newSvgH / 2 ) } ) ;
130+ var anchor = _context . attr ( 'text-anchor' ) ;
131+
132+ x = x - newSvgW * (
133+ anchor === 'middle' ? 0.5 :
134+ anchor === 'end' ? 1 : 0
135+ ) ;
136+ y = y + dy - newSvgH / 2 ;
133137 }
134138
139+ newSvg . attr ( {
140+ x : x ,
141+ y : y
142+ } ) ;
143+
135144 if ( _callback ) _callback . call ( _context , mathjaxGroup ) ;
136145 resolve ( mathjaxGroup ) ;
137146 } ) ;
0 commit comments