@@ -53,7 +53,7 @@ exports.extractPathCoords = function(path, paramsToUse, isRaw) {
53
53
return extractedCoordinates ;
54
54
} ;
55
55
56
- exports . getDataToPixel = function ( gd , axis , isVertical , refType ) {
56
+ exports . getDataToPixel = function ( gd , axis , shift , isVertical , refType ) {
57
57
var gs = gd . _fullLayout . _size ;
58
58
var dataToPixel ;
59
59
@@ -66,7 +66,8 @@ exports.getDataToPixel = function(gd, axis, isVertical, refType) {
66
66
var d2r = exports . shapePositionToRange ( axis ) ;
67
67
68
68
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 ;
70
71
} ;
71
72
72
73
if ( axis . type === 'date' ) dataToPixel = exports . decodeDate ( dataToPixel ) ;
@@ -179,6 +180,10 @@ exports.getPathString = function(gd, options) {
179
180
var ya = Axes . getFromId ( gd , options . yref ) ;
180
181
var gs = gd . _fullLayout . _size ;
181
182
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 ) ;
182
187
var x0 , x1 , y0 , y1 ;
183
188
184
189
if ( xa ) {
@@ -208,23 +213,22 @@ exports.getPathString = function(gd, options) {
208
213
if ( ya && ya . type === 'date' ) y2p = exports . decodeDate ( y2p ) ;
209
214
return convertPath ( options , x2p , y2p ) ;
210
215
}
211
-
212
216
if ( options . xsizemode === 'pixel' ) {
213
217
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 ;
216
220
} else {
217
- x0 = x2p ( options . x0 ) ;
218
- x1 = x2p ( options . x1 ) ;
221
+ x0 = x2p ( options . x0 ) + xShiftStart ;
222
+ x1 = x2p ( options . x1 ) + xShiftEnd ;
219
223
}
220
224
221
225
if ( options . ysizemode === 'pixel' ) {
222
226
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 ;
225
229
} else {
226
- y0 = y2p ( options . y0 ) ;
227
- y1 = y2p ( options . y1 ) ;
230
+ y0 = y2p ( options . y0 ) + yShiftStart ;
231
+ y1 = y2p ( options . y1 ) + yShiftEnd ;
228
232
}
229
233
230
234
if ( type === 'line' ) return 'M' + x0 + ',' + y0 + 'L' + x1 + ',' + y1 ;
@@ -279,3 +283,12 @@ function convertPath(options, x2p, y2p) {
279
283
return segmentType + paramString ;
280
284
} ) ;
281
285
}
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