Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

drag xy cursor and InteractionModeDefault to zoomxy

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

0 Kudos
Message 11 of 18
(2,402 Views)

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.

 

 

private void waveformGraph1_PlotAreaMouseWheel(object sender, MouseEventArgs e)
{
    RectangleF rect = new RectangleF();
    if (e.Delta > 0)
    {
        rect.X = (float)waveformPlot1.XAxis.Range.Minimum - 1;
        rect.Y = (float)waveformPlot1.YAxis.Range.Minimum - 1;
        rect.Height = (float)(waveformPlot1.YAxis.Range.Maximum -
            waveformPlot1.YAxis.Range.Minimum + 2);
        rect.Width = (float)(waveformPlot1.XAxis.Range.Maximum -
            waveformPlot1.XAxis.Range.Minimum + 2);
        waveformGraph1.ZoomXY(waveformPlot1, rect.X, rect.Y, rect.Width, rect.Height);

    }
    else
    {
        rect.X = (float)waveformPlot1.XAxis.Range.Minimum + 1;
        rect.Y = (float)waveformPlot1.YAxis.Range.Minimum + 1;
        rect.Height = (float)(waveformPlot1.YAxis.Range.Maximum -
            waveformPlot1.YAxis.Range.Minimum - 2);
        rect.Width = (float)(waveformPlot1.XAxis.Range.Maximum -
            waveformPlot1.XAxis.Range.Minimum - 2);
        waveformGraph1.ZoomXY(waveformPlot1, rect.X, rect.Y, rect.Width, rect.Height);
    }
}

 

Let me know if you have any questions about this snippet

 

NickB

National Instruments  

0 Kudos
Message 12 of 18
(2,399 Views)

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.

0 Kudos
Message 13 of 18
(2,385 Views)

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.Smiley Wink

 

Thanks

Eric

0 Kudos
Message 14 of 18
(1,759 Views)

Hey Eric,

 

What version of Measurement Studio are you using? The graph control may be different in your version.

National Instruments
0 Kudos
Message 15 of 18
(1,737 Views)

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. Smiley Wink

 

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);
}
}
}
}
Message 16 of 18
(1,728 Views)

Thanks for the great code Eric!

National Instruments
0 Kudos
Message 17 of 18
(1,710 Views)

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)
            {
            }
        }

 

0 Kudos
Message 18 of 18
(1,407 Views)