Skip to content

Commit c2f7f27

Browse files
committed
Update shapes_test after adding shift param to getDataToPixel
If the passed shift param is undefined, use shift 0 instead.
1 parent a617017 commit c2f7f27

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

src/components/shapes/display_labels.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ module.exports = function drawLabel(gd, index, options, shapeGroup) {
9393
var ya = Axes.getFromId(gd, options.yref);
9494
var yRefType = Axes.getRefType(options.yref);
9595
var yShift = options.y_shift;
96-
var x2p = helpers.getDataToPixel(gd, xa, false, xRefType, xShift);
97-
var y2p = helpers.getDataToPixel(gd, ya, true, yRefType, yShift);
96+
var x2p = helpers.getDataToPixel(gd, xa, xShift, false, xRefType);
97+
var y2p = helpers.getDataToPixel(gd, ya, yShift, true, yRefType);
9898
shapex0 = x2p(options.x0);
9999
shapex1 = x2p(options.x1);
100100
shapey0 = y2p(options.y0);

src/components/shapes/draw.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,12 @@ function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer, editHe
225225
// setup conversion functions
226226
var xa = Axes.getFromId(gd, shapeOptions.xref);
227227
var xRefType = Axes.getRefType(shapeOptions.xref);
228+
var xShift = shapeOptions.x_shift;
228229
var ya = Axes.getFromId(gd, shapeOptions.yref);
229230
var yRefType = Axes.getRefType(shapeOptions.yref);
230-
var x2p = helpers.getDataToPixel(gd, xa, false, xRefType);
231-
var y2p = helpers.getDataToPixel(gd, ya, true, yRefType);
231+
var yShift = shapeOptions.y_shift;
232+
var x2p = helpers.getDataToPixel(gd, xa, xShift, false, xRefType);
233+
var y2p = helpers.getDataToPixel(gd, ya, yShift, true, yRefType);
232234
var p2x = helpers.getPixelToData(gd, xa, false, xRefType);
233235
var p2y = helpers.getPixelToData(gd, ya, true, yRefType);
234236

src/components/shapes/helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ exports.extractPathCoords = function(path, paramsToUse, isRaw) {
5353
return extractedCoordinates;
5454
};
5555

56-
exports.getDataToPixel = function(gd, axis, isVertical, refType, shift) {
56+
exports.getDataToPixel = function(gd, axis, shift, isVertical, refType) {
5757
var gs = gd._fullLayout._size;
5858
var dataToPixel;
5959

@@ -74,7 +74,7 @@ exports.getDataToPixel = function(gd, axis, isVertical, refType, shift) {
7474
shiftPixels = axis.r2p(d2r(0.5, true)) * shift;
7575
}
7676
}
77-
return axis._offset + axis.r2p(d2r(v, true)) + shiftPixels;
77+
return axis._offset + axis.r2p(d2r(v, true)) + (shiftPixels || 0);
7878
};
7979

8080
if(axis.type === 'date') dataToPixel = exports.decodeDate(dataToPixel);

test/jasmine/tests/shapes_test.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,8 +1487,8 @@ describe('Test shapes', function() {
14871487
function testShapeDrag(dx, dy, layoutShape, node) {
14881488
var xa = Axes.getFromId(gd, layoutShape.xref);
14891489
var ya = Axes.getFromId(gd, layoutShape.yref);
1490-
var x2p = helpers.getDataToPixel(gd, xa);
1491-
var y2p = helpers.getDataToPixel(gd, ya, true);
1490+
var x2p = helpers.getDataToPixel(gd, xa, layoutShape.x_shift);
1491+
var y2p = helpers.getDataToPixel(gd, ya, layoutShape.y_shift, true);
14921492

14931493
var initialCoordinates = getShapeCoordinates(layoutShape, x2p, y2p);
14941494

@@ -1514,8 +1514,8 @@ describe('Test shapes', function() {
15141514
function testPathDrag(dx, dy, layoutShape, node) {
15151515
var xa = Axes.getFromId(gd, layoutShape.xref);
15161516
var ya = Axes.getFromId(gd, layoutShape.yref);
1517-
var x2p = helpers.getDataToPixel(gd, xa);
1518-
var y2p = helpers.getDataToPixel(gd, ya, true);
1517+
var x2p = helpers.getDataToPixel(gd, xa, layoutShape.x_shift);
1518+
var y2p = helpers.getDataToPixel(gd, ya, layoutShape.y_shift, true);
15191519

15201520
var initialPath = layoutShape.path;
15211521
var initialCoordinates = getPathCoordinates(initialPath, x2p, y2p);
@@ -1546,8 +1546,8 @@ describe('Test shapes', function() {
15461546
function testShapeResize(direction, dx, dy, layoutShape, node) {
15471547
var xa = Axes.getFromId(gd, layoutShape.xref);
15481548
var ya = Axes.getFromId(gd, layoutShape.yref);
1549-
var x2p = helpers.getDataToPixel(gd, xa);
1550-
var y2p = helpers.getDataToPixel(gd, ya, true);
1549+
var x2p = helpers.getDataToPixel(gd, xa, layoutShape.x_shift);
1550+
var y2p = helpers.getDataToPixel(gd, ya, layoutShape.y_shift, true);
15511551

15521552
var initialCoordinates = getShapeCoordinates(layoutShape, x2p, y2p);
15531553

@@ -1590,9 +1590,8 @@ describe('Test shapes', function() {
15901590

15911591
var xa = Axes.getFromId(gd, layoutShape.xref);
15921592
var ya = Axes.getFromId(gd, layoutShape.yref);
1593-
var x2p = helpers.getDataToPixel(gd, xa);
1594-
var y2p = helpers.getDataToPixel(gd, ya, true);
1595-
1593+
var x2p = helpers.getDataToPixel(gd, xa, layoutShape.x_shift);
1594+
var y2p = helpers.getDataToPixel(gd, ya, layoutShape.y_shift, true);
15961595

15971596
promise = promise.then(function() {
15981597
var dragHandle = pointToMove === 'start' ?

0 commit comments

Comments
 (0)