Help with live wave updates

I'd like to create an interactive plot. 

The plot would consist of two markers. 

I want to be able to move one marker with my cursor, and depending on it's live x,y position in the plot have the the second marker move.  The location of the second marker is a function of the x,y coordinates of the first marker.

I have only been able to do this iteratively: Each marker is the x-y plot of two, single row waves. I use the Edit Wave tool to move the first marker, then execute a function to update the location of the second function according to the new resting location of the first marker.  

How can I make the location of the second marker update in real time as I move the first marker? Something that would continuously update 

Thanks a bunch.

Hi,

 

This can be done but it is a little advanced in programming and requires the creation of a window hook.  Here is a simple example where I assume you have two cursors on your graph specifically A and B and they are both on a trace called exampleTrace.  The example here will place cursor B 20 points away from A.  Things to note in the function is eventCode 7 specifically means that a cursor has moved.  Also notice the hookresult being set to 1 which is required for it to actually work.  Common error is to forget that.

Function MyWindowHook(s)
    STRUCT WMWinHookStruct &s
 
    Variable hookResult = 0
 
    switch(s.eventCode)
        case 7:             // cursor moved
            cursor B exampleTrace pcsr(A)+20
            hookresult=1
            break
 
        // And so on . . .
    endswitch
 
    return hookResult       // 0 if nothing done, else 1
End

But before you can use this the function needs to be attached to a specific window and in this case the window name is Demograph and recall that the window name is different than the title string.

SetWindow DemoGraph, hook(MyHook) = MyWindowHook    // Install window hook
 

This is the general idea and you will need to tailor to your own specifics.

 

Andy

How familiar are you with programming using Hook functions? Look especially for help on programming with the Cursor moved hook. A hook function would allow you to automatically move the second cursor at the point in time just after the first one has been moved.

If you're using the Edit Wave tool, then you aren't talking about the graph cursors; you are actually moving the markers for a trace. I think the only way to do that is via a dependency formula (DisplayHelpTopic "Dependencies"). Here is an example:

make/n=10 junk=xdisplay junk
•ModifyGraph mode=4ModifyGraph marker=16duplicate junk, junk2
•junk2 := junk            // <===== make a dependencydisplay junk2
•ModifyGraph mode=4,marker=19

That will make two waves, displayed in two graphs. The ":=" operator creates a dependency that makes `junk2` follow any changes to values in `junk`. Now go to the first graph, show the drawing tools and put the trace into Edit Wave mode. Move one of the data points on the trace; watch as the same thing happens to the trace in the other graph!

The dependency can call a function; that function can do just about anything you want.

<deep voice> With great power comes great responsibility.