Skip to content
20 changes: 16 additions & 4 deletions src/components/shapes/draw_newshape/newshapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function newShapes(outlines, dragOptions) {
clearOutline(gd);

var editHelpers = dragOptions.editHelpers;
var plotinfo = dragOptions.plotinfo;
var modifyItem = (editHelpers || {}).modifyItem;

var allShapes = [];
Expand All @@ -84,10 +85,21 @@ function newShapes(outlines, dragOptions) {
case 'line':
case 'rect':
case 'circle':
modifyItem('x0', afterEdit.x0 - (beforeEdit.x0shift || 0));
modifyItem('x1', afterEdit.x1 - (beforeEdit.x1shift || 0));
modifyItem('y0', afterEdit.y0 - (beforeEdit.y0shift || 0));
modifyItem('y1', afterEdit.y1 - (beforeEdit.y1shift || 0));
if (beforeEdit.xref.includes("x") && plotinfo.xaxis.type.includes("category")) {
plotinfo.xaxis.r2c(afterEdit.x0)
modifyItem('x0', plotinfo.xaxis.r2c(afterEdit.x0) - (beforeEdit.x0shift || 0));
modifyItem('x1', plotinfo.xaxis.r2c(afterEdit.x1) - (beforeEdit.x1shift || 0));
} else {
modifyItem('x0', afterEdit.x0);
modifyItem('x1', afterEdit.x1);
}
if (beforeEdit.yref.includes("y") && plotinfo.yaxis.type.includes("category")) {
modifyItem('y0', plotinfo.xaxis.r2c(afterEdit.y0) - (beforeEdit.y0shift || 0));
modifyItem('y1', plotinfo.xaxis.r2c(afterEdit.y1) - (beforeEdit.y1shift || 0));
} else {
modifyItem('y0', afterEdit.y0);
modifyItem('y1', afterEdit.y1);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @my-tien for the fix.
Two questions:

  1. Is a similar fix needed for the case of path?
  2. Could you please add a test here:
    describe('Activate and edit editable shapes', function() {
    ?

Copy link
Contributor Author

@my-tien my-tien Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have a look at path and adding a test. However, my fix is not yet correct. Among other things, afterEdit can be a shape with xref and yref paper apparently even if the ref was something different before. I'll have to see, how I can correctly translate the shift variables to paper as well. I will probably push some changes later today.

UPDATE: This is a separate bug. As mentioned further below, I'll open an issue for it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the path case the change is not necessary, because the shift properties are ignored if path is used instead of x0, x1, y0, y1.

Regarding the test, I added one with a test case that previously failed and now works. However, I am not sure how to test this locally because for some reason on my machine several Jasmine tests always fail. Could you please look at it on your end and make the necessary adjustments?

break;

case 'path':
Expand Down