LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Graph zooming with the wheel

Hello, hello,

I'm starting a project that will involve a lot of zooming in graphs.

Has anyone ever written code to allow for simple zooming in and out with the mouse wheel ?

There's an EVENT_ZOOM and of course EVENT_MOUSE_WHEEL_SCROLL, but I don't think there's any way to set the zoom level and coord in code, now is there ? So the only way would be to manage the axes limits manually. Any other idea ?

0 Kudos
Message 1 of 3
(1,266 Views)

Hi,

 

actually I did 🙂

 

Zooming the graph scale via the mouse wheel is along these lines:

 

case EVENT_MOUSE_WHEEL_SCROLL:
    GetKeyModifierStates (  );
    if ( ctrl_modifier )
    {
        if ( !graph_zoom_scroll )
        {
            GetAxisRange ( ,,VAL_LEFT_YAXIS, &y_minimum, &y_maximum  );
        }
        GetAxisRange ( ,, VAL_LEFT_YAXIS, &y_scroll_minimum, &y_scroll_maximum );
        double delta_left_y = ( y_maximum - y_minimum ) / 200.0;
        if ( eventData1 == MOUSE_WHEEL_SCROLL_UP )
        {

            y_scroll_maximum += delta_left_y;
            y_scroll_minimum -= delta_left_y;
        }
        else if ( eventData1 == MOUSE_WHEEL_SCROLL_DOWN )
        {
            y_scroll_maximum -= delta_left_y;
            y_scroll_minimum += delta_left_y;
        }
        if ( y_scroll_maximum > y_scroll_minimum )
        {
            SetAxisRange ( ,,VAL_LEFT_YAXIS,y_scroll_minimum,y_scroll_maximum );

            graph_zoom_scroll = true;

        }

 

So basically I increment / decrement the axis scale by every mouse wheel scroll event. Works well, actually.

Hope it helps,

Wolfgang

0 Kudos
Message 2 of 3
(1,228 Views)

Thanks Wolfgang,

I implemented it a bit different so that the zooming would be centered on the mouse position:

 

case EVENT_MOUSE_WHEEL_SCROLL:
int CtrlX, CtrlY, KeyModifiers;
int PaH, PaW, PaT, PaL;
GetRelativeMouseState(panel, control, &CtrlX, &CtrlY, NULL, NULL, &KeyModifiers);
GetAxisScalingMode(panel, control, VAL_LEFT_YAXIS, NULL, &Y0, &Y1);
GetAxisScalingMode(panel, control, VAL_BOTTOM_XAXIS, NULL, &X0, &X1);
GetCtrlAttribute (panel, control, ATTR_PLOT_AREA_HEIGHT,&PaH);
GetCtrlAttribute (panel, control, ATTR_PLOT_AREA_WIDTH, &PaW);
GetCtrlAttribute (panel, control, ATTR_PLOT_AREA_TOP, &PaT);
GetCtrlAttribute (panel, control, ATTR_PLOT_AREA_LEFT, &PaL);
double Y=Y0-(Y1-Y0)*(CtrlY-PaT-PaH)/PaH;
double X=X0+(X1-X0)*(CtrlX-PaL)/PaW;
if ( eventData1 == MOUSE_WHEEL_SCROLL_DOWN ) {
X0=X+(X0-X)*2; X1=X+(X1-X)*2;
Y0=Y+(Y0-Y)*2; Y1=Y+(Y1-Y)*2;
} else if ( eventData1 == MOUSE_WHEEL_SCROLL_UP ) {
X0=X+(X0-X)/2; X1=X+(X1-X)/2;
Y0=Y+(Y0-Y)/2; Y1=Y+(Y1-Y)/2;
}
SetAxisScalingMode(panel, control, VAL_LEFT_YAXIS, VAL_MANUAL, Y0, Y1);
SetAxisScalingMode(panel, control, VAL_BOTTOM_XAXIS, VAL_MANUAL, X0, X1);
SetAxisScalingMode(panel, control, VAL_LEFT_YAXIS, VAL_LOCK, 0, 0);
SetAxisScalingMode(panel, control, VAL_BOTTOM_XAXIS, VAL_LOCK, 0, 0);
break;

 

Message 3 of 3
(1,158 Views)