Scale XY by Same Range

This code snippet will put up a panel that allows you to scale the x and y ranges of a graph by the same amount. Inputs are x0 (starting x), y0 (starting y), and zoom factor. The zoom factor is in powers of 10 from -3 to 3 in steps of 0.5. This will work on the frontmost graph window.

#pragma rtGlobals=1     // Use modern global access method.

Window ScaleGraph() : Panel
    PauseUpdate; Silent 1       // building window...
    NewPanel /W=(659,70,835,193)
    SetDrawLayer UserBack
    DrawText 54,67,"Zoom Range"
    Slider sliderx,pos={15,71},size={150,52},proc=SliderProc
    Slider sliderx,limits={-3,3,0.5},value= 0,vert= 0
    SetVariable setvarx0,pos={14,31},size={100,16},proc=SetVarProc,title="x0"
    SetVariable setvarx0,value= _NUM:0
    SetVariable setvary0,pos={14,8},size={100,16},proc=SetVarProc,title="y0"
    SetVariable setvary0,value= _NUM:3
EndMacro

Function SliderProc(sa) : SliderControl
    STRUCT WMSliderAction &sa

    string fWin
    variable x0, y0, ve
   
    switch( sa.eventCode )
        case -1: // control being killed
            break
        default:
            if( sa.eventCode & 1 ) // value set
                fWin = WinName(0,1)
                if (strlen(fWin)==0)
                    break
                endif
                ControlInfo setvarx0
                x0 = V_value
                ve = x0 + 10^sa.curval
                SetAxis/W=$fWin bottom, x0, ve
                ControlInfo setvary0
                y0 = V_value
                ve = y0 + 10^sa.curval
                SetAxis/W=$fWin left, y0, ve
            endif
            break
    endswitch

    return 0
End

Function SetVarProc(sva) : SetVariableControl
    STRUCT WMSetVariableAction &sva

    string fWin
    variable x0, y0, ve, sf

    switch( sva.eventCode )
        case 1: // mouse up
        case 2: // Enter key
        case 3: // Live update
            Variable dval = sva.dval
            fWin = WinName(0,1)
            if (strlen(fWin)==0)
                break
            endif
            ControlInfo sliderx
            sf = V_value
            ControlInfo setvarx0
            x0 = V_value
            ve = x0 + 10^sf
            SetAxis/W=$fWin bottom, x0, ve
            ControlInfo setvary0
            y0 = V_value
            ve = y0 + 10^sf
            SetAxis/W=$fWin left, y0, ve
            break
        case -1: // control being killed
            break
    endswitch

    return 0
End

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More