Find traces that intersect the graph marquee

This snippet shows a function that will examing the named graph and return a list of all traces that have points that fall within the graph marquee. Note that the traces must have points in the marquee, it's not enough that they intersect the marquee. The snippet handles the standard additive offset. I have not tried it on log axes. As written, it handles only the left and bottom axes.

#include <Graph Utility Procs>

// Make a list of all traces that have points that fall within the marquee
Function/S ListTracesInMarquee(graphname)
    String graphname
   
    String tlist = TraceNameList(graphname, ";", 1)
    Variable ntraces = ItemsInList(tlist)
   
    Make/O/D/N=4/FREE marqueeX, marqueeY
   
    GetMarquee/W=$graphname left, bottom
    marqueeY = {V_top, V_top, V_bottom, V_bottom}
    MarqueeX = {V_left, V_right, V_right, V_left}
   
    String theList = ""
    Variable i
    for (i = 0; i < ntraces; i += 1)
        String onetrace = StringFromList(i, tlist)
        Wave ywave = TraceNameToWaveRef(graphname, onetrace)
        Wave/Z xwave = XWaveRefFromTrace(graphname, onetrace)
        if (!WaveExists(xwave))
            Duplicate/O/FREE ywave, xwave
            xwave = pnt2x(ywave, p)
        endif
        String offsetinfo = WMGetRECREATIONInfoByKey("offset(x)", traceinfo(graphname, onetrace, 0))
        offsetinfo = offsetinfo[1, strlen(offsetinfo)-2]
        Variable xoffset = str2num(stringfromlist(0, offsetinfo, ","))
        Variable yoffset = str2num(stringfromlist(1, offsetinfo, ","))
        marqueeY -= yoffset
        marqueeX -= xoffset
        FindPointsInPoly xwave, ywave, marqueeX, marqueeY
        marqueeY += yoffset
        marqueeX += xoffset
        Wave W_inPoly
        if (sum(W_inPoly) > 0)
            theList += onetrace+";"
        endif
    endfor
   
    return theList
end

// Example of using ListTracesInMarquee: change the color of all traces that intersect the marquee
Function ColorTracesInMarquee(graphname, red, green, blue)
    String graphname
    Variable red, green, blue
   
    String tlist = ListTracesInMarquee(graphname)
    Variable ntraces = ItemsInList(tlist)
   
    Variable i
    for (i = 0; i < ntraces; i += 1)
        String onetrace = StringFromList(i, tlist)
        ModifyGraph/W=$graphname rgb($onetrace)=(red, green, blue)
    endfor
end

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More