Graph Cursor

Hi,

I am wondering if it is possible to simply click on a data point in a graph to select the data point, without having to drag the cursor from the bottom of the graph window onto the data point.

Also, can I execute a command upon selecting a data point with the cursor, instead of using a roundabout method of executing that command (e.g having the user press a button)?

Thanks.
You can do those things if you're willing to write a window hook function. Execute this command:

DisplayHelpTopic "Window Hook Functions"

Keep reading through Named Window Hook Functions; we strongly recommend using the more-modern named hook functions.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
So far, I have:
Function Hook(s)
STRUCT WMWinHookStruct &s
Variable hookResult = 0 // 0 if we do not handle event, 1 if we handle it.
switch(s.eventCode)
case 7: // "cursorMoved"
Desired_Function()
hookResult = 1
break
endswitch
return hookResult // If non-zero, we handled event and Igor will ignore it.
End

Within "Window Graph0(): Graph", I call the window hook function with "SetWindow Graph0,hook(MyHook)=Hook".

such that the desired action executes upon selecting a data point with the cursor. However, I am still confused as to how to make it so that I can move the cursor with just a left click of the mouse, without having to drag the cursor around. The cursor would ideally latch onto the closest point. I know eventCode = 5 is for mouseup, and once a cursor is locked onto a point, s.pointNumber and s.cursorName is generated. Also, s.mouseLoc.v and s.mouseLoc.h gives the mouse position. I haven't gotten much further than that.
You need to handle mousedown (3) and maybe mouseup (5), and possibly mousemoved (4). You can use the functions PixelFromAxisVal, AxisValFromPixel, and TraceFromPixel to figure out where the mouse click landed and what trace might be under it.

You will use the Cursor operation to set the cursor to the right place.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Thank you. I got it to work using MouseUp and TraceFromPixel (to determine the trace and point number index based on the mouse position). Then, I used sscanf to retrieve the point number index. With the cursor function, I set the cursor on the retrieved index in the current trace and tagged on my original code to execute the desired action.