09-28-2009 12:03 PM
Thks for your answer.
can you give an example because i do'nt manage coding zoom in and out through ZoomXY method...
thks by advance
09-28-2009 01:09 PM
Hello -
There are a couple different overloads on the ZoomXY method. The snippet below shows the overload that takes a plot, and four doubles, and may be a good place for you to start from. This is just a very simple handling of the mouse wheel scrolling.
Let me know if you have any questions about this snippet
NickB
National Instruments
09-30-2009 10:53 AM
Hello sstrenn,
I have a similar issue with my customer.
I derived my own control from the ScatterGraph and used ScatterPlot.ZoomXY() to implement Zoom/Unzoom features as per their wishes.
01-19-2011 04:05 PM
I have same problem.
I try solution described above without success. It resize but not correctly. I use scatterGraph.
I wonder if there is 2 public methods :ZoomIn and ZoomOut to ensure standard behavior. They should have something internally. Why just don't let those 2 functions available to us ?
It will ensure standard behavior all the time and enable customers to zoom the way they want.![]()
Thanks
Eric
01-20-2011 06:07 PM
Hey Eric,
What version of Measurement Studio are you using? The graph control may be different in your version.
01-21-2011 07:54 AM
Hi D Biel,
Thanks for your feedback.
In fact I solved my problem with the following code. It resize without modifiers keys but also enable me to resize only in X or Y depending on "Alt" or "Ctrl" key. It also have the advantage to resize the same ratio as NI default.
Also note that my code should work in any situation (I think).
Also... NI Should give us access to there "ZoomIn" and "ZommOut" function. It take only 5 minutes of development time and save us and also NI support a lot of time and troubles. ![]()
Thanks
Eric
private void scatterGraph1_PlotAreaMouseWheel(object sender, MouseEventArgs e)
{
if (!(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))) // No shift, do not overide default behavior
{
double zoomFactor;
if (e.Delta > 0)
{
zoomFactor = .8; // .008 = 1/1.25, same as NI
}
else
{
zoomFactor = 1.25;
}
RectangleF rect = new RectangleF();
rect.X = (float)scatterGraph1.Plots[0].XAxis.Range.Minimum;
rect.Width = (float)(scatterGraph1.Plots[0].XAxis.Range.Maximum - scatterGraph1.XAxes[0].Range.Minimum);
rect.Y = (float)scatterGraph1.Plots[0].YAxis.Range.Minimum;
rect.Height = (float)(scatterGraph1.Plots[0].YAxis.Range.Maximum - scatterGraph1.YAxes[0].Range.Minimum);
double newWidth = rect.Width * zoomFactor;
double newHeight = rect.Height * zoomFactor;
if (Keyboard.Modifiers == 0)
{
scatterGraph1.ZoomXY(scatterGraph1.Plots[0], rect.X + ((rect.Width - newWidth) / 2),
rect.Y + ((rect.Height - newHeight) / 2), newWidth, newHeight);
}
else
{
if (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))
{
Debug.Print("Alt");
scatterGraph1.ZoomXY(scatterGraph1.Plots[0], rect.X,
rect.Y + ((rect.Height - newHeight) / 2), rect.Width, newHeight);
}
else if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
Debug.Print("Ctl");
scatterGraph1.ZoomXY(scatterGraph1.Plots[0], rect.X + ((rect.Width - newWidth) / 2),
rect.Y, newWidth, rect.Height);
}
}
}
}
01-24-2011 09:38 AM
Thanks for the great code Eric!
02-21-2014 09:38 AM
I made a slight modifcation to this sample code so that the zoom would occur only in the X direction and around the position of mouse.
The largest change is the scaling factor (originally it was 0.5 or "/2". By using the PointToVirtual function you get a value from 0 to 1 for X which is a normalized mouse position on the X axis. Using this as the scaling factor for the X start position of the zoom causes the zoom to happen around the mouse position. It's much more intuitive and doesn't require any panning after the zoom. Thanks for the original idea it works great!.
PointF pos = waveformGraph1.PointToVirtual(e.Location);
bool mouseWheelEvent = false;
private void waveformGraph1_PlotAreaMouseWheel(object sender, MouseEventArgs e)
{
try
{
mouseWheelEvent = true;
if (!(Control.ModifierKeys == Keys.LShiftKey) && !(Control.ModifierKeys == Keys.RShiftKey))
// if (!(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))) // No shift, do not overide default behavior
{
double zoomFactor;
if (e.Delta > 0)
{
zoomFactor = .8; // .008 = 1/1.25, same as NI
}
else
{
zoomFactor = 1.25;
}
RectangleF rect = new RectangleF();
rect.X = (float)waveformGraph1.Plots[0].XAxis.Range.Minimum;
rect.Width = (float)(waveformGraph1.Plots[0].XAxis.Range.Maximum - waveformGraph1.XAxes[0].Range.Minimum);
rect.Y = (float)waveformGraph1.Plots[0].YAxis.Range.Minimum;
rect.Height = (float)(waveformGraph1.Plots[0].YAxis.Range.Maximum - waveformGraph1.YAxes[0].Range.Minimum);
PointF pos = waveformGraph1.PointToVirtual(e.Location);
double newWidth = rect.Width * zoomFactor;
double newHeight = rect.Height * zoomFactor;
if (Control.ModifierKeys == 0)
{
waveformGraph1.ZoomXY(waveformGraph1.Plots[0], rect.X + ((rect.Width - newWidth) * pos.X),
rect.Y, newWidth, rect.Height);
}
else
{
if (Control.ModifierKeys == Keys.Alt)
{
Debug.Print("Alt");
waveformGraph1.ZoomXY(waveformGraph1.Plots[0], rect.X,
rect.Y + ((rect.Height - newHeight) / 2), rect.Width, newHeight);
}
else if (Control.ModifierKeys == Keys.LControlKey || Control.ModifierKeys == Keys.LControlKey)
{
Debug.Print("Ctl");
waveformGraph1.ZoomXY(waveformGraph1.Plots[0], rect.X + ((rect.Width - newWidth) / 2),
rect.Y, newWidth, rect.Height);
}
}
}
}
catch (Exception exp)
{
}
}