Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix coordinate hints in the GraphTool for restricted sine wave points. #1185

Merged
merged 3 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions htdocs/js/GraphTool/cubictool.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
preInit(gt, point1, point2, point3, point4, solid) {
[point1, point2, point3, point4].forEach((point) => {
point.setAttribute(gt.definingPointAttributes);
point.on('down', () => (gt.board.containerObj.style.cursor = 'none'));
point.on('up', () => (gt.board.containerObj.style.cursor = 'auto'));
if (!gt.isStatic) {
point.on('down', () => gt.onPointDown(point));
point.on('up', () => gt.onPointUp(point));
}
});
return gt.graphObjectTypes.cubic.createCubic(point1, point2, point3, point4, solid, gt.color.curve);
},
Expand Down Expand Up @@ -163,6 +165,7 @@

groupedPointDrag(gt, e) {
gt.graphObjectTypes.cubic.adjustDragPosition(e, this, this.grouped_points);
gt.setTextCoords(this.X(), this.Y());
gt.updateObjects();
gt.updateText();
},
Expand Down Expand Up @@ -439,6 +442,7 @@

gt.setTextCoords(this.hlObjs.hl_point.X(), this.hlObjs.hl_point.Y());
gt.board.update();
return true;
},

deactivate(gt) {
Expand Down
80 changes: 53 additions & 27 deletions htdocs/js/GraphTool/graphtool.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,8 @@ window.graphTool = (containerId, options) => {
// degenerate.
gt.adjustDragPosition = (e, point, pairedPoint) => {
if (
(Math.abs(point.X() - pairedPoint?.X()) < JXG.Math.eps &&
(pairedPoint &&
Math.abs(point.X() - pairedPoint?.X()) < JXG.Math.eps &&
Math.abs(point.Y() - pairedPoint?.Y()) < JXG.Math.eps) ||
!gt.boardHasPoint(point.X(), point.Y())
) {
Expand Down Expand Up @@ -732,6 +733,7 @@ window.graphTool = (containerId, options) => {

gt.pairedPointDrag = (e, point) => {
gt.adjustDragPosition(e, point, point.paired_point);
gt.setTextCoords(point.X(), point.Y());
gt.updateObjects();
gt.updateText();
};
Expand All @@ -741,8 +743,9 @@ window.graphTool = (containerId, options) => {
// already been moved by JSXGraph. This prevents parabolas from being made degenerate.
gt.adjustDragPositionRestricted = (e, point, pairedPoint) => {
if (
Math.abs(point.X() - pairedPoint?.X()) < JXG.Math.eps ||
Math.abs(point.Y() - pairedPoint?.Y()) < JXG.Math.eps ||
(pairedPoint &&
(Math.abs(point.X() - pairedPoint.X()) < JXG.Math.eps ||
Math.abs(point.Y() - pairedPoint.Y()) < JXG.Math.eps)) ||
!gt.boardHasPoint(point.X(), point.Y())
) {
const bbox = gt.board.getBoundingBox();
Expand Down Expand Up @@ -782,10 +785,21 @@ window.graphTool = (containerId, options) => {

gt.pairedPointDragRestricted = (e, point) => {
gt.adjustDragPositionRestricted(e, point, point.paired_point);
gt.setTextCoords(point.X(), point.Y());
gt.updateObjects();
gt.updateText();
};

gt.onPointDown = (point) => {
point.dragging = true;
gt.board.containerObj.style.cursor = 'none';
};

gt.onPointUp = (point) => {
delete point.dragging;
gt.board.containerObj.style.cursor = 'auto';
};

gt.createPoint = (x, y, paired_point, restrict) => {
const point = gt.board.create('point', [gt.snapRound(x, gt.snapSizeX), gt.snapRound(y, gt.snapSizeY)], {
snapSizeX: gt.snapSizeX,
Expand All @@ -794,8 +808,8 @@ window.graphTool = (containerId, options) => {
});
point.setAttribute({ snapToGrid: true });
if (!gt.isStatic) {
point.on('down', () => (gt.board.containerObj.style.cursor = 'none'));
point.on('up', () => (gt.board.containerObj.style.cursor = 'auto'));
point.on('down', () => gt.onPointDown(point));
point.on('up', () => gt.onPointUp(point));
if (typeof paired_point !== 'undefined') {
point.paired_point = paired_point;
paired_point.paired_point = point;
Expand Down Expand Up @@ -893,13 +907,19 @@ window.graphTool = (containerId, options) => {
onResize() {}

updateTextCoords(coords) {
return !this.definingPts.every((point) => {
for (const point of this.definingPts) {
if (point.dragging) {
gt.setTextCoords(point.X(), point.Y());
return true;
}
}
for (const point of this.definingPts) {
if (point.hasPoint(coords.scrCoords[1], coords.scrCoords[2])) {
gt.setTextCoords(point.X(), point.Y());
return false;
return true;
}
return true;
});
}
return false;
}

static restore(string) {
Expand Down Expand Up @@ -1759,15 +1779,17 @@ window.graphTool = (containerId, options) => {

gt.board.off('up');

this.point1.setAttribute(gt.definingPointAttributes);
this.point1.on('down', () => (gt.board.containerObj.style.cursor = 'none'));
this.point1.on('up', () => (gt.board.containerObj.style.cursor = 'auto'));
const point1 = this.point1;
delete this.point1;

point1.setAttribute(gt.definingPointAttributes);
point1.on('down', () => gt.onPointDown(point1));
point1.on('up', () => gt.onPointUp(point1));

const point2 = gt.createPoint(coords[1], coords[2], this.point1);
gt.selectedObj = new gt.graphObjectTypes.line(this.point1, point2, gt.drawSolid);
const point2 = gt.createPoint(coords[1], coords[2], point1);
gt.selectedObj = new gt.graphObjectTypes.line(point1, point2, gt.drawSolid);
gt.selectedObj.focusPoint = point2;
gt.graphedObjs.push(gt.selectedObj);
delete this.point1;

this.finish();
}
Expand Down Expand Up @@ -1905,15 +1927,17 @@ window.graphTool = (containerId, options) => {

gt.board.off('up');

this.center.setAttribute(gt.definingPointAttributes);
this.center.on('down', () => (gt.board.containerObj.style.cursor = 'none'));
this.center.on('up', () => (gt.board.containerObj.style.cursor = 'auto'));
const center = this.center;
delete this.center;

const point = gt.createPoint(coords[1], coords[2], this.center);
gt.selectedObj = new gt.graphObjectTypes.circle(this.center, point, gt.drawSolid);
center.setAttribute(gt.definingPointAttributes);
center.on('down', () => gt.onPointDown(center));
center.on('up', () => gt.onPointUp(center));

const point = gt.createPoint(coords[1], coords[2], center);
gt.selectedObj = new gt.graphObjectTypes.circle(center, point, gt.drawSolid);
gt.selectedObj.focusPoint = point;
gt.graphedObjs.push(gt.selectedObj);
delete this.center;

this.finish();
}
Expand Down Expand Up @@ -2065,15 +2089,17 @@ window.graphTool = (containerId, options) => {

gt.board.off('up');

this.vertex.setAttribute(gt.definingPointAttributes);
this.vertex.on('down', () => (gt.board.containerObj.style.cursor = 'none'));
this.vertex.on('up', () => (gt.board.containerObj.style.cursor = 'auto'));
const vertex = this.vertex;
delete this.vertex;

const point = gt.createPoint(coords[1], coords[2], this.vertex, true);
gt.selectedObj = new gt.graphObjectTypes.parabola(this.vertex, point, this.vertical, gt.drawSolid);
vertex.setAttribute(gt.definingPointAttributes);
vertex.on('down', () => gt.onPointDown(vertex));
vertex.on('up', () => gt.onPointUp(vertex));

const point = gt.createPoint(coords[1], coords[2], vertex, true);
gt.selectedObj = new gt.graphObjectTypes.parabola(vertex, point, this.vertical, gt.drawSolid);
gt.selectedObj.focusPoint = point;
gt.graphedObjs.push(gt.selectedObj);
delete this.vertex;

this.finish();
}
Expand Down
5 changes: 4 additions & 1 deletion htdocs/js/GraphTool/intervaltools.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@
pairedPointDrag(gt, e, point) {
gt.adjustDragPositionRestricted(e, point, point.paired_point);
if (point.Y() !== 0) point.setPosition(JXG.COORDS_BY_USER, [point.X(), 0]);
gt.setTextCoords(this.X(), 0);
gt.updateObjects();
gt.updateText();
},
Expand Down Expand Up @@ -417,6 +418,7 @@

pointDown(gt, point) {
if (gt.activeTool !== gt.selectTool) return;
point.dragging = true;

const thisObj = gt.graphedObjs.filter(
(obj) => obj.definingPts.filter((pt) => pt === point).length
Expand All @@ -436,7 +438,8 @@
gt.board.containerObj.style.cursor = 'none';
},

pointUp(gt) {
pointUp(gt, point) {
delete point.dragging;
gt.board.containerObj.style.cursor = 'auto';
},

Expand Down
4 changes: 2 additions & 2 deletions htdocs/js/GraphTool/pointtool.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
this.focusPoint = this.baseObj;

if (!gt.isStatic) {
this.on('down', () => (gt.board.containerObj.style.cursor = 'none'));
this.on('up', () => (gt.board.containerObj.style.cursor = 'auto'));
this.on('down', () => gt.onPointDown(this.baseObj));
this.on('up', () => gt.onPointUp(this.baseObj));
this.on('drag', (e) => {
gt.adjustDragPosition(e, this.baseObj);
gt.updateText();
Expand Down
7 changes: 5 additions & 2 deletions htdocs/js/GraphTool/quadratictool.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
preInit(gt, point1, point2, point3, solid) {
[point1, point2, point3].forEach((point) => {
point.setAttribute(gt.definingPointAttributes);
point.on('down', () => (gt.board.containerObj.style.cursor = 'none'));
point.on('up', () => (gt.board.containerObj.style.cursor = 'auto'));
if (!gt.isStatic) {
point.on('down', () => gt.onPointDown(point));
point.on('up', () => gt.onPointUp(point));
}
});
return gt.graphObjectTypes.quadratic.createQuadratic(point1, point2, point3, solid, gt.color.curve);
},
Expand Down Expand Up @@ -123,6 +125,7 @@

groupedPointDrag(gt, e) {
gt.graphObjectTypes.quadratic.adjustDragPosition(e, this, this.grouped_points);
gt.setTextCoords(this.X(), this.Y());
gt.updateObjects();
gt.updateText();
},
Expand Down
7 changes: 5 additions & 2 deletions htdocs/js/GraphTool/sinewavetool.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
preInit(gt, shiftPoint, periodPoint, amplitudePoint, solid) {
[shiftPoint, periodPoint, amplitudePoint].forEach((point) => {
point.setAttribute(gt.definingPointAttributes);
point.on('down', () => (gt.board.containerObj.style.cursor = 'none'));
point.on('up', () => (gt.board.containerObj.style.cursor = 'auto'));
if (!gt.isStatic) {
point.on('down', () => gt.onPointDown(point));
point.on('up', () => gt.onPointUp(point));
}
});
return gt.graphObjectTypes.sineWave.createSineWave(
shiftPoint,
Expand Down Expand Up @@ -183,6 +185,7 @@

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

gt.setTextCoords(this.X(), this.Y());
gt.updateObjects();
gt.updateText();
},
Expand Down