Skip to content

Commit

Permalink
Add a way for a graph object to add to the help.
Browse files Browse the repository at this point in the history
A graph object can only add to the help when it is selected.

The help is also updated when focus moves within the object to different
defining points.  So the graph object can give a different message
depending on which point is focused.  The sine wave tool uses this to
let the user know restrictions on how the focused point can move.
  • Loading branch information
drgrice1 committed Dec 11, 2024
1 parent f54fc3b commit 13e3cb3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 13 additions & 1 deletion htdocs/js/GraphTool/graphtool.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ window.graphTool = (containerId, options) => {
gt.setMessageText(
gt.tools
.map((tool) => (typeof tool.helpText === 'function' ? tool.helpText() : tool.helpText || ''))
.concat([gt.selectedObj?.helpText()])
.filter((helpText) => !!helpText)
);
};
Expand Down Expand Up @@ -846,6 +847,8 @@ window.graphTool = (containerId, options) => {
return this.definingPts.some((point) => point.rendNode === e.target);
}

helpText() {}

update() {}

fillCmp(/* point */) {
Expand Down Expand Up @@ -1305,6 +1308,11 @@ window.graphTool = (containerId, options) => {
return false;
}

helpText() {
if ('helpText' in graphObject) return graphObject.helpText.call(this, gt);
else if (parentObject) return super.helpText();
}

update() {
if ('update' in graphObject) graphObject.update.call(this, gt);
else if (parentObject) super.update();
Expand Down Expand Up @@ -1519,6 +1527,7 @@ window.graphTool = (containerId, options) => {
lastSelected = gt.selectedObj;
} else {
focusPoint?.rendNode.focus();
gt.updateHelp();
return;
}
}
Expand Down Expand Up @@ -1566,7 +1575,10 @@ window.graphTool = (containerId, options) => {
}

// Attach a focusin handler to all points to update the coordinates display.
point.focusInHandler = () => gt.setTextCoords(point.X(), point.Y());
point.focusInHandler = () => {
gt.setTextCoords(point.X(), point.Y());
setTimeout(() => gt.updateHelp());
};
point.rendNode.addEventListener('focusin', point.focusInHandler);
});
}
Expand Down
7 changes: 7 additions & 0 deletions htdocs/js/GraphTool/sinewavetool.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
return new gt.graphObjectTypes.sineWave(shiftPoint, periodPoint, amplitudePoint, /solid/.test(string));
},

helpText(_gt) {
if (this.focusPoint == this.definingPts[1])
return 'Note that the selected point can only be moved left and right.';
else if (this.focusPoint == this.definingPts[2])
return 'Note that the selected point can only be moved up and down.';
},

helperMethods: {
createSineWave(gt, point, period, amplitude, solid, color) {
return gt.board.create(
Expand Down

0 comments on commit 13e3cb3

Please sign in to comment.