@@ -104,16 +104,33 @@ module.exports = function drawLabel(gd, index, options, shapeGroup) {
104104 const xRefType1 = Axes . getRefType ( isArrayXref ? options . xref [ 1 ] : options . xref ) ;
105105 const yRefType0 = Axes . getRefType ( isArrayYref ? options . yref [ 0 ] : options . yref ) ;
106106 const yRefType1 = Axes . getRefType ( isArrayYref ? options . yref [ 1 ] : options . yref ) ;
107- const x2p = function ( v , shift , xa , xRefType ) {
108- return helpers . getDataToPixel ( gd , xa , shift , false , xRefType ) ( v ) ;
109- } ;
110- const y2p = function ( v , shift , ya , yRefType ) {
111- return helpers . getDataToPixel ( gd , ya , shift , true , yRefType ) ( v ) ;
112- } ;
113- shapex0 = x2p ( options . x0 , options . x0shift , xa0 , xRefType0 ) ;
114- shapex1 = x2p ( options . x1 , options . x1shift , xa1 , xRefType1 ) ;
115- shapey0 = y2p ( options . y0 , options . y0shift , ya0 , yRefType0 ) ;
116- shapey1 = y2p ( options . y1 , options . y1shift , ya1 , yRefType1 ) ;
107+ const x2p = ( v , shift , xa , xRefType ) => helpers . getDataToPixel ( gd , xa , shift , false , xRefType ) ( v ) ;
108+ const y2p = ( v , shift , ya , yRefType ) => helpers . getDataToPixel ( gd , ya , shift , true , yRefType ) ( v ) ;
109+ // When using pixel offset mode it's necessary to add the anchor position for the
110+ // correct final value
111+ if ( options . xsizemode === 'pixel' ) {
112+ const xAnchorPos = x2p ( options . xanchor , undefined , xa0 , xRefType0 ) ;
113+ // Use xa0 for both shifts because in pixel mode x0/x1 are offsets from the
114+ // anchor, which is always on xa0 (pixel mode with array xref is unsupported)
115+ const xShift0 = helpers . getPixelShift ( xa0 , options . x0shift ) ;
116+ const xShift1 = helpers . getPixelShift ( xa0 , options . x1shift ) ;
117+ shapex0 = xAnchorPos + options . x0 + xShift0 ;
118+ shapex1 = xAnchorPos + options . x1 + xShift1 ;
119+ } else {
120+ shapex0 = x2p ( options . x0 , options . x0shift , xa0 , xRefType0 ) ;
121+ shapex1 = x2p ( options . x1 , options . x1shift , xa1 , xRefType1 ) ;
122+ }
123+ if ( options . ysizemode === 'pixel' ) {
124+ const yAnchorPos = y2p ( options . yanchor , undefined , ya0 , yRefType0 ) ;
125+ // Both shifts use ya0 for the same reason as above
126+ const yShift0 = helpers . getPixelShift ( ya0 , options . y0shift ) ;
127+ const yShift1 = helpers . getPixelShift ( ya0 , options . y1shift ) ;
128+ shapey0 = yAnchorPos - options . y0 + yShift0 ;
129+ shapey1 = yAnchorPos - options . y1 + yShift1 ;
130+ } else {
131+ shapey0 = y2p ( options . y0 , options . y0shift , ya0 , yRefType0 ) ;
132+ shapey1 = y2p ( options . y1 , options . y1shift , ya1 , yRefType1 ) ;
133+ }
117134 }
118135
119136 // Handle `auto` angle
0 commit comments