@@ -85,6 +85,7 @@ module.exports = function autoTextPosition(gd, plotinfo, traceGroups) {
8585 const rank = Lib . extractOption ( d , trace , 'tR' , 'textrank' ) ;
8686 const x = xaxis . c2p ( d . x ) ;
8787 const y = yaxis . c2p ( d . y ) ;
88+ const bb = Drawing . textPointBBox ( tx ) ;
8889 const label = {
8990 tx,
9091 trace,
@@ -101,13 +102,14 @@ module.exports = function autoTextPosition(gd, plotinfo, traceGroups) {
101102 // `_tpAuto` survives a relayout, so a pan or zoom keeps the labels in place where it can
102103 prefer : d . _tpAuto || undefined ,
103104 preferGap : d . _tpAutoGap ,
104- rect : labelRect ( d , trace , x , y , Drawing . textPointBBox ( tx ) )
105+ rect : labelRect ( d , trace , x , y , bb )
105106 } ;
106107
107108 if ( pos === 'auto' ) {
108109 labels . push ( label ) ;
109110 } else {
110- const box = label . rect ( pos , 0 ) ;
111+ // `textPointPosition` stored the geometry that draws the fixed label
112+ const box = boxAt ( x , y , bb , d . _tpOffset ) ;
111113 box . owner = d ;
112114 fixed . push ( box ) ;
113115 }
@@ -230,25 +232,25 @@ function hasAutoTextPosition(trace) {
230232 return tp === 'auto' || ( Lib . isArrayOrTypedArray ( tp ) && tp . includes ( 'auto' ) ) ;
231233}
232234
233- // the box of a label at a given position and gap, plus its leader line, in the plot frame
234- function labelRect ( d , trace , x , y , bb ) {
235- const symbol = d . mx || ( trace . marker || { } ) . symbol ;
235+ // The box of a label at a given offset, plus its leader line, in the plot frame
236+ function boxAt ( x , y , bb , offset ) {
237+ let x0 = x + offset . dx ;
238+ if ( offset . anchor === 'end' ) x0 -= bb . width ;
239+ else if ( offset . anchor === 'middle' ) x0 -= bb . width / 2 ;
240+ const y0 = y + offset . dy + bb . top ;
236241
237- return ( pos , gap ) => {
238- const offset = Drawing . textPointBoxOffset ( pos , d . mrc , symbol , bb , gap ) ;
239-
240- let x0 = x + offset . dx ;
241- if ( offset . anchor === 'end' ) x0 -= bb . width ;
242- else if ( offset . anchor === 'middle' ) x0 -= bb . width / 2 ;
243- const y0 = y + offset . dy + bb . top ;
244-
245- const seg = offset . leader ;
246- return {
247- x0,
248- y0,
249- x1 : x0 + bb . width ,
250- y1 : y0 + bb . height ,
251- leader : seg ? [ x + seg [ 0 ] , y + seg [ 1 ] , x + seg [ 2 ] , y + seg [ 3 ] ] : null
252- } ;
242+ const seg = offset . leader ;
243+ return {
244+ x0,
245+ y0,
246+ x1 : x0 + bb . width ,
247+ y1 : y0 + bb . height ,
248+ leader : seg ? [ x + seg [ 0 ] , y + seg [ 1 ] , x + seg [ 2 ] , y + seg [ 3 ] ] : null
253249 } ;
254250}
251+
252+ // The box of an *auto* label at a given position and gap
253+ function labelRect ( d , trace , x , y , bb ) {
254+ const symbol = d . mx || ( trace . marker || { } ) . symbol ;
255+ return ( pos , gap ) => boxAt ( x , y , bb , Drawing . textPointBoxOffset ( pos , d . mrc , symbol , bb , gap ) ) ;
256+ }
0 commit comments