CoordToValue ViewSmith Issue

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
lokesh
Posts: 45
Joined: Tue Feb 14, 2017 8:48 am

CoordToValue ViewSmith Issue

Post by lokesh » Tue Apr 25, 2017 4:22 pm

Hi,
I was trying to figure out some points from Smith chart and following is my code:

Code: Select all

      private void LcuBitmapContour_MouseMove(object sender, MouseEventArgs e)
      {
         var vals = lcuBitmapContour.ViewSmith.Axis.CoordToValue(new PointFloat(Cursor.Position.X, Cursor.Position.Y));
         lblBitmap.Text = $"{vals.RealValue}, {vals.ImgValue}";
      }
The code works fine except that the data I get from CoordToValue() might be giving me wrong values and returns different values when I keep my test application at different places or when maximized.

When the window is at around middle left of the screen:
issue 1.png
issue 1.png (21.74 KiB) Viewed 7488 times
When the window is maximized:
issue 2.jpg
issue 2.jpg (127.17 KiB) Viewed 7488 times
The red dot represents the mouse position with a small precision error
My axis reference value is set to 1.
Is there something that I am doing wrong?

Thanks.

Regards,
Lokesh

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: CoordToValue ViewSmith Issue

Post by ArctionKestutis » Thu Apr 27, 2017 10:33 am

Hi Lokesh,

The CoordToValue method return absolute Real/Imaginary value pair (as written in description). From the image it looks like you are using 'Normalized scale'. You need to do conversion. Something like following will work for both scales:

Code: Select all

            PointSmith vals = _chart.ViewSmith.Axis.CoordToValue(new PointFloat(e.X, e.Y), false);
       
            if (_chart.ViewSmith.Axis.ShowAbsoluteValues == false)
            {
                vals.RealValue /= _chart.ViewSmith.Axis.ReferenceValue;
                vals.ImgValue /= _chart.ViewSmith.Axis.ReferenceValue;
            }

All the best,
Kestutis

lokesh
Posts: 45
Joined: Tue Feb 14, 2017 8:48 am

Re: CoordToValue ViewSmith Issue

Post by lokesh » Thu Apr 27, 2017 1:53 pm

Hi Dr.,
Thanks for the reply.
As I mentioned, my reference value is set to 1.

Plus, I noted that (in a different scenario), if I get the reference point using ValueToCoord and add an offset and then plot it using CoordToValue, it plots correctly irrespective of position and size of window which is what is expected.
I am a bit confused here.

Thanks again.

Lokesh

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: CoordToValue ViewSmith Issue

Post by ArctionKestutis » Thu Apr 27, 2017 2:45 pm

I was testing with latest v7.2.6.1 and latest v8.
I used _chart.MouseDoubleClick event in WinForms.
I still see correct values independent of Chart size and location.
If you need help in debugging, please send you app for testing to Arction support email.

All the best.

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: CoordToValue ViewSmith Issue

Post by ArctionKestutis » Fri Apr 28, 2017 10:24 am

The Cursor.Position property gives you absolute screen coordinates (relatively to top-left monitor corner). For usage in LightningChart you need screen coordinates relatively to Chart’s top-left corner.
MouseMove event handler argument MouseEventArgs gives you correct coordinates to be used in LightningChart. Replace line

Code: Select all

      private void LcuBitmapContour_MouseMove(object sender, MouseEventArgs e)
      {
         var vals = lcuBitmapContour.ViewSmith.Axis.CoordToValue(new PointFloat(e.X, e.Y), false);
         lblBitmap.Text = $"{vals.RealValue}, {vals.ImgValue}";
      }
and everything will be just fine.

Post Reply