Graph Live Updateupon user interaction

Dear Forum,

It's the first time I am trying to use sliders and other controls to streamline the interaction of user with the script.
In a first attempt to do that, I have a slider that scales from 0 to 100 that will define a threshold which will sit between the minimum and the maximum value of a wave containing data. The threshold will be used towards finding peaks, and to better aid the user to define a suitable threshold, it should be plotted as a line across the graph where the data (containing a succession of small and large peaks) is also plotted. Now, I could do an update button to update the graph every time the thumb position is changed - but that's a bit too lame. Instead, the threshold line should update automatically. Can anyone please give me a hand, maybe with some example code, or with suggestion of core functions to do this? I did have a look at some of the examples that come with Igor, but a more direct and specific example would be of extra value to begin understanding this.

Many thanks in advance.

R.
Hi John,

thanks for the reply.
I post below the relevant part of the code. DisplayDataProc is called from another panel not shown here. Once called it creates a graph containing a control bar area with a slider and an update button next to it. This update button is what i use to define the threshold. ideally, I would like to get rid of it altogeher. Can you maybe illustrate what exactly you mean based on this?

Many thanks,

R.

Function DisplayDataProc(CtrlName) : ButtonControl
    string CtrlName
    Wave WF
    Display /N=Graph_Data /w=(210, 0, 1150, 150) /k=1 WF // and display in a graph
    ModifyGraph /W=Graph_Data rgb(WF)=(0,0,0)
    ControlBar /L /W=Graph_Data 100
    Variable /G Percent_Max
    SetVariable setvar0,pos={0,120},size={90,50},limits={0,100,1},value=Percent_Max
    Slider Slider01, pos={0,10}, size={50,110}, ticks=10, live=1
    Slider Slider01, limits={0,100,1}, variable=Percent_Max, side=2, thumbColor=(1000,1000,0)
    Button Update_Threshold, pos={55,10}, size={40,80}, Proc=Update_Threshold, title="UPDATE"
    Make /O /N=2 W_Threshold_X
    Make /O /N=2 W_Threshold_Y
    AppendToGraph /W=Graph_Data W_Threshold_Y vs W_Threshold_X

   
    //For FFT
    Duplicate/O WF WF1 
    If (mod(numpnts(WF1),2) != 0)   // check remainder of division of 2
            deletepoints numpnts(WF1)-1, 1, WF1 // delete last point if remainder is not zero
    endif
   
    FFT /OUT=3 /WINF=Hanning /DEST=WF_FFT WF1
    Display /N=Graph_FFT /w=(210, 210, 410, 410) /k=1 WF_FFT // and display in a graph
    SetAxis /W=Graph_FFT bottom 0.1,2
    SetAxis /W=Graph_FFT /A=2 left

End


Function Update_Threshold(CtrlName) : ButtonControl
    String CtrlName
   
    //Display threshold to be used in the peak detection routine
    Wave WF, W_Threshold_X, W_Threshold_Y
    Variable /G Percent_Max
    Variable /G Threshold = ((Wavemax(WF)-Wavemin(WF))*Percent_Max/100)+Wavemin(WF)
   
    W_Threshold_X[0] = 0
    W_Threshold_X[1] = pnt2x(WF, numpnts(WF)-1)
   
    W_Threshold_Y[0] = Threshold
    W_Threshold_Y[1] = Threshold
    DoUpdate
   
END
I get it now :)

You need an action proc for the slider and SetVariable controls that does what the button's action proc does. If I were doing it, I would write a single function with appropriate inputs that changes the graph. Then call it from the two action procs.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Thank you John! That makes perfect sense.
So I change controls from the button to the slider, and I appended the PROC to the slider01, and replaced the function control from ButtonControl to SliderControl. The whole thing compiles, but at runtime I get a syntax error of "expected right parenthesis".

Can anyone tell me what exactly I am doing wrong?

Currently, it looks like this:

//Function to close window after baseline correction and display baseline corrected graph
Function CloseWindow(CtrlName):ButtonControl
    String CtrlName
    MenuSubtractBaseline()
    DoWindow /K Graph_Baseline
    SVAR RawWaveName
    String/G WaveNewName = RawWaveName+"_sub"  
    Display /N=Graph_Data /w=(210, 0, 1150, 350) /k=1 $WaveNewName
    ModifyGraph /W=Graph_Data rgb($WaveNewName)=(0,0,0)
    SetAxis /W=Graph_Data Bottom 0,5
    Execute /P "WMAppendAxisSlider()"
    ModifyGraph mode($WaveNewName)=4,marker($WaveNewName)=19,rgb($WaveNewName)=(0,0,0)
    DoUpdate
    ControlBar /L /W=Graph_Data 100
    Variable /G Percent_Max
    //SetVariable setvar0,pos={0,120},size={90,50},limits={0,100,1},value=Percent_Max
    Slider Slider01, pos={0,50}, size={50,200}, ticks=10, live=1// thumbColor=(1000,1000,0)
    Slider Slider01, limits={0,100,1}, variable=Percent_Max, side=2
    Slider Slider01, Proc=Update_Threshold
    //Button Update_Threshold, pos={0,280}, size={80,80}, Proc=Update_Threshold, title="UPDATE"
    DoWindow /F Graph_Data
End

Function Update_Threshold(CtrlName) : SliderControl
    String CtrlName
   
    //Display threshold to be used in the peak detection routine
    SVAR WaveNewName
   
    Make /O /N=2 W_Threshold_X
    Make /O /N=2 W_Threshold_Y
    Variable /G Percent_Max
    Variable /G Threshold = ((Wavemax($WaveNewName)-Wavemin($WaveNewName))*Percent_Max/100)+Wavemin($WaveNewName)
   
   
    W_Threshold_X[0] = 0
    W_Threshold_X[1] = pnt2x($WaveNewName, numpnts($WaveNewName)-1)
   
    W_Threshold_Y[0] = Threshold
    W_Threshold_Y[1] = Threshold
   
    AppendToGraph /W=Graph_Data W_Threshold_Y vs W_Threshold_X
    DoUpdate
   
END
I have two initial thoughts...

First, because this error occurs at runtime and not at compile, the problem may be related to the Execute statement.

Second, enable the debugger if you haven't tried this already. To enable it, right click on the procedure window and select the Enable Debugger item in the context menu. When the error occurs, Igor with open the debugger window with the execution point at the line after the position where the error occurred.

This may keep you afloat until real help arrives.
Thanks for the input JTIgor!

The execute command, and the rest of the code, works fine until I change the control from Button to Slider.

The execute command adds a top control bar with a horizontal slider to allow sliding over the x-axis wit a small data-window; it is very useful for long datasets or with many features packed very closely together. It is in fact part of the standard Igor packages.

I did try using the debugger, but it did not highlight any errors, or warning signs. The moment, I click the slider01 thumb it is havoc: the syntax error dialog pops up telling me that it was expecting a right parenthesis somewhere and I cannot continue.

So by activating the slider with a mouse click I get a problem. I had no problems before in clicking in the slider to set the value for the associated variable.

So, I continue confused.
The debugger will not highlight (as I recall) faulty code, but it will pause execution at the line following the line where the error occurred.

A missing parenthesis should be caught during compile unless is occurs in a macro or if there is an error in the design of an Execute command. I would look at these two possibilities.
Each control type has its own required format for the action proc. A slider requires one with the signature like this:
Function MySliderProc(name, value, event) : SliderControl
    String name     // name of this slider control
    Variable value  // value of slider
    Variable event  // bit field: bit 0: value set; 1: mouse down,
                        //   2: mouse up, 3: mouse moved

But these action procs with simple input parameters are old-fashioned. You really should be using the ones that take a structure as input:
Function ActionProcName(S_Struct) : SliderControl
    STRUCT WMSliderAction &S_Struct

The structure-based procs give better performance, and when we create new features for a control, it is likely to be supported only by the structure-based versions. That's because it's easier to extend the structure for new features without breaking existing code.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Many thanks John & JTIgor!
I will have a look and post here later if run into problems.

Cheers,

R.