LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Pan and zoom on graphs

I've enabled the pan and zoom on my graph and I've also set the graph to "auto scale" to start. Here's my delimma:

When the user pans or zooms on a graph I want to disable the "auto scale" when I plot new data. In other words, I want to keep the settings on the graph that are a result of the user panning or zooming.

If, however, the user resets the graph by pressing + (as per the instructions in the UserInterface Manual) I want to set the graph back to "auto scale" mode when new data is being plotted.

How do I accomplish these things?

Thanks in advance,
--Marianne

specs:
LabWindows/CVI 5.5
0 Kudos
Message 1 of 6
(4,435 Views)
Hello

Here is an idea you could try. Disable the "auto scaling " option in the graph control on your UIR file. And since you would know the lenght of your data array, you can use the SetAxisScalingMode function to do manual scaling. Because the way autoscaling works is that if that that option enabled, everytime you plot anything new on the graph, it would autoscale the graph. Setting the scaling mode to manual lets you use the auto-zooming and panning, and would let you re-plot the data without the autoscaling kicking in.

The + actually returns the graph to the previous state it was in. For example, if you plot the data, zoom in, and then pan to another location, after pressing the key sequence, it would go to the zoom, not the original plot


If you want to get back to the same state the graph was, you could use getctrlattribute to obtain and save the values of the x and y axis before the zooming and panning happened, and then reset the graph with a reset callback, which would essentially assign the x and y axis with its original values. You can assign a shortcut key to the reset button under its edit options on the UIR.

I hope this helps

Bilal Durrani
National Instruments
Bilal Durrani
NI
0 Kudos
Message 2 of 6
(4,435 Views)
bilalD,

I didn't know that about the + (returning to the previous state). Thanks! I'll keep that in mind. I'm going to try the things you suggested and see how it goes. Thank you for your reponse.

--Marianne
0 Kudos
Message 4 of 6
(4,435 Views)
Marianne,

One thing I want to point out is that when the user zooms or pans on a graph, two events get generated: EVENT_LEFT_CLICK (for zoom) and EVENT_RIGHT_CLICK (for panning). When the user presses + to reset the graph to its previous state, the graph generates the EVENT_KEYPRESS event.

You can check for these events to set/unset the autoscaling accordingly. For example, you can check if the user has pressed ctrl+spacebar and set the autoscaling back on before you start plotting.

However note that if you want to reset the graph to its original state (before any zooming or panning) it is best to save the original coordinates at the beginning of your program, and then restore both axes with these values when you receive the EVENT_KEYPRESS even
t.

Good luck,
Azucena
0 Kudos
Message 3 of 6
(4,435 Views)
aperez,

I thought about using the events generated with the mouse-clicks. However, I also have snap-to-point cursors on the graphs -- wouldn't that interfere with the pan and zoom control? Is there a way where I can poll an event to see if the key is pressed down at the same time as a mouse-click?

Thanks for your response,
--Marianne
0 Kudos
Message 5 of 6
(4,435 Views)
Yes, that would certainly interfere. To tell you the truth, there's no straightfoward way to detect when the user is zooming/panning. In other words, I don't know of a way to determine if the ctrl key was pressed while the mouse-click was generated.
So I would suggest that you do the following instead:

1) Plot your data (with autoscaling on if you need it)
2) Call SetAxisScalingMode for each of the axis with VAL_LOCK on the Axis Scaling (unless you are using a strip chart). This will turn off autoscaling while preserving the autoscaled min and max values.

If you need to plot again with autoscaling on, just call SetAxisScalingMode again to turn it on right before plotting.

Regards,
Azucena
0 Kudos
Message 6 of 6
(4,435 Views)