Trace Toggler

Creates a panel to easily toggle the visibility of traces on the selected graph, useful to quickly compare many sets of data all plotted together. A trace visibility selector. Perhaps a bit long for a code "snippet" but could probably be condensed a bit more.
menu "Macros"
    "Trace Toggler",CreateTogglerPanel()
end

function CreateTogglerPanel()
    string trl=tracenamelist("",";",1) //list of all traces on graph
    string vtrl=tracenamelist("",";",1+4) //list of visible traces on graph
    string item,itemname
    variable items=itemsinlist(trl),i
    string ttlabel="Trace Toggler for "+WinName(0,1)
    string ttwinname="tt"+WinName(0,1)
   
    DoWindow/K $ttwinname
    NewPanel/W=(0,0,220,20*(items+2)+40)/N=$ttwinname/K=1 as "Toggle Traces"
    TitleBox tb1,pos={110,20},size={0,0},anchor=MC,title=ttlabel
    ModifyPanel/W=$ttwinname noEdit=1, fixedSize=0
   
    String topGraph=WinName(0,1)
    if(strlen(topGraph))
        AutoPositionWindow/M=0/R=$topGraph $ttwinname
    endif

    //Create a checkbox for each trace, checked if visible and unchecked if already hidden
    for(i=0;i<items;i+=1)
        item=stringfromlist(i,trl)
        print item
        itemname=replacestring("'",item,"") //remove ugly single quotes for label
        if (stringmatch(vtrl,"*"+item+"*"))
            CheckBox $("box"+num2str(i)) pos={20,40+i*20},value=1,proc=ToggleTrace,userdata=item,title=itemname
        else
            CheckBox $("box"+num2str(i)) pos={20,40+i*20},value=0,proc=ToggleTrace,userdata=item,title=itemname
        endif
    endfor
    Button closeme pos={50,40+i*20},size={130,20},proc=endTraceToggler,title="Close and reset",userdata=ttwinname
    Button closeme2 pos={50,60+i*20},size={130,20},proc=endTraceToggler2,title="Close without reset",userdata=ttwinname
end

Function ToggleTrace(cba) : CheckBoxControl
    STRUCT WMCheckboxAction &cba
    string tracename=cba.userdata
   
    switch( cba.eventCode )
        case 2: // mouse up
            Variable checked = cba.checked
            If (checked==1)
                ModifyGraph hideTrace($tracename)=0
            Else
                ModifyGraph hideTrace($tracename)=2
            endif
            break
        case -1: // control being killed
            break
    endswitch

    return 0
End

Function endTraceToggler(cba): ButtonControl
    struct WMButtonAction &cba
    string ttwinname=cba.userdata
   
    if (cba.eventcode==2)
        DoWindow/K $ttwinname
        ModifyGraph hideTrace=0
    endif
End

Function endTraceToggler2(cba): ButtonControl
    struct WMButtonAction &cba
    string ttwinname=cba.userdata
    if (cba.eventcode==2)
        DoWindow/K $ttwinname
    endif
End

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More