Skip to content

Commit

Permalink
Fix coordinate hints in the GraphTool for restricted sine wave points.
Browse files Browse the repository at this point in the history
After construction of a sine wave is completed, if the point that
determines amplitude is selected and moved with the mouse cursor, then
the x-coordinate of the point can't change.  However, the x-coordinate
of the coordinate hints in the lower right corner of the board does
change if the mouse is moved to the left and right while dragging that
point, and should not be.

The same thing happens with the point that determines period on relative
to the vertical axis.  The y-coordinate of that point can't change, but
the y-coordinate of the coordinate hints do change if the mouse cursor
is moved up or down.

This pull request fixes the issue by overriding the default graph object
`updateTextCoords` method for the sine wave graph object.  A flag set on
the point when it is dragged, and the `updateTextCoords` override
checks for the flag and sets the coordinate hints with the coordinates
of the point instead of using the mouse cursor coordinates which might
be incorrect.

This is similar to the issue that @Alex-Jordan noticed in openwebwork#1157,
although that was during the construction phase of the sine wave.
  • Loading branch information
drgrice1 committed Jan 29, 2025
1 parent 6f12013 commit 57cdc62
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions htdocs/js/GraphTool/sinewavetool.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
this.focusPoint = shiftPoint;
},

updateTextCoords(gt, coords) {
for (const point of this.definingPts) {
if (point.dragged || point.hasPoint(coords.scrCoords[1], coords.scrCoords[2])) {
delete point.dragged;
gt.setTextCoords(point.X(), point.Y());
return true;
}
}
return false;
},

stringify(gt) {
return [
this.baseObj.getAttribute('dash') == 0 ? 'solid' : 'dashed',
Expand Down Expand Up @@ -183,6 +194,8 @@

if (shiftPoint) periodPoint?.setPosition(JXG.COORDS_BY_USER, [periodPoint.X(), shiftPoint.Y()]);

if (e.type === 'pointermove') this.dragged = true;

gt.updateObjects();
gt.updateText();
},
Expand Down

0 comments on commit 57cdc62

Please # to comment.