@@ -53,7 +53,7 @@ exports.extractPathCoords = function(path, paramsToUse, isRaw) {
5353 return extractedCoordinates ;
5454} ;
5555
56- exports . getDataToPixel = function ( gd , axis , isVertical , refType ) {
56+ exports . getDataToPixel = function ( gd , axis , shift , isVertical , refType ) {
5757 var gs = gd . _fullLayout . _size ;
5858 var dataToPixel ;
5959
@@ -66,7 +66,8 @@ exports.getDataToPixel = function(gd, axis, isVertical, refType) {
6666 var d2r = exports . shapePositionToRange ( axis ) ;
6767
6868 dataToPixel = function ( v ) {
69- return axis . _offset + axis . r2p ( d2r ( v , true ) ) ;
69+ var shiftPixels = getPixelShift ( axis , shift ) ;
70+ return axis . _offset + axis . r2p ( d2r ( v , true ) ) + shiftPixels ;
7071 } ;
7172
7273 if ( axis . type === 'date' ) dataToPixel = exports . decodeDate ( dataToPixel ) ;
@@ -179,6 +180,10 @@ exports.getPathString = function(gd, options) {
179180 var ya = Axes . getFromId ( gd , options . yref ) ;
180181 var gs = gd . _fullLayout . _size ;
181182 var x2r , x2p , y2r , y2p ;
183+ var xShiftStart = getPixelShift ( xa , options . x0shift ) ;
184+ var xShiftEnd = getPixelShift ( xa , options . x1shift ) ;
185+ var yShiftStart = getPixelShift ( ya , options . y0shift ) ;
186+ var yShiftEnd = getPixelShift ( ya , options . y1shift ) ;
182187 var x0 , x1 , y0 , y1 ;
183188
184189 if ( xa ) {
@@ -208,23 +213,22 @@ exports.getPathString = function(gd, options) {
208213 if ( ya && ya . type === 'date' ) y2p = exports . decodeDate ( y2p ) ;
209214 return convertPath ( options , x2p , y2p ) ;
210215 }
211-
212216 if ( options . xsizemode === 'pixel' ) {
213217 var xAnchorPos = x2p ( options . xanchor ) ;
214- x0 = xAnchorPos + options . x0 ;
215- x1 = xAnchorPos + options . x1 ;
218+ x0 = xAnchorPos + options . x0 + xShiftStart ;
219+ x1 = xAnchorPos + options . x1 + xShiftEnd ;
216220 } else {
217- x0 = x2p ( options . x0 ) ;
218- x1 = x2p ( options . x1 ) ;
221+ x0 = x2p ( options . x0 ) + xShiftStart ;
222+ x1 = x2p ( options . x1 ) + xShiftEnd ;
219223 }
220224
221225 if ( options . ysizemode === 'pixel' ) {
222226 var yAnchorPos = y2p ( options . yanchor ) ;
223- y0 = yAnchorPos - options . y0 ;
224- y1 = yAnchorPos - options . y1 ;
227+ y0 = yAnchorPos - options . y0 + yShiftStart ;
228+ y1 = yAnchorPos - options . y1 + yShiftEnd ;
225229 } else {
226- y0 = y2p ( options . y0 ) ;
227- y1 = y2p ( options . y1 ) ;
230+ y0 = y2p ( options . y0 ) + yShiftStart ;
231+ y1 = y2p ( options . y1 ) + yShiftEnd ;
228232 }
229233
230234 if ( type === 'line' ) return 'M' + x0 + ',' + y0 + 'L' + x1 + ',' + y1 ;
@@ -279,3 +283,12 @@ function convertPath(options, x2p, y2p) {
279283 return segmentType + paramString ;
280284 } ) ;
281285}
286+
287+ function getPixelShift ( axis , shift ) {
288+ shift = shift || 0 ;
289+ var shiftPixels = 0 ;
290+ if ( shift && axis && ( axis . type === 'category' || axis . type === 'multicategory' ) ) {
291+ shiftPixels = ( axis . r2p ( 1 ) - axis . r2p ( 0 ) ) * shift ;
292+ }
293+ return shiftPixels ;
294+ }
0 commit comments