SolveYValueAtXValue for PointLineSeries

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Arction_LasseP

Claudio_G
Posts: 13
Joined: Fri Sep 15, 2017 7:28 am

SolveYValueAtXValue for PointLineSeries

Post by Claudio_G » Wed Sep 27, 2017 11:22 am

Hi all,
I implemented a cursor annotation display, however the SolveYValueAtXValue does not return false if one or both involved points are of the same value of DataBreaking.Value.

I set my databreaking value to Double.MinValue following your performance remarks about databreaks and the if the cursor is on a series break the SolveYValueAtXValue returns Double.MinValue or the interpolated value of of Double.MinValue and the adjacent point.

I think this is a bug and the method should return false when DataBreaking is enabled and one of the interpolation sources is the databreaking value.

Claudio_G
Posts: 13
Joined: Fri Sep 15, 2017 7:28 am

Re: SolveYValueAtXValue for PointLineSeries

Post by Claudio_G » Wed Sep 27, 2017 12:38 pm

I just digged a little bit more. There are a few discrepancies in the behavior of the function SolveYValueAtXValue:

1) When you are on a Databreaking the LineSeriesValueSolveResult.SolveStatus = LineSeriesSolveStatus.OK
2) LineSeriesValueSolveResult.NearestDataPointIndex is pointing to the correct point, however LineSeriesValueSolveResult.NearestX is always equal to the SolveYValueAtXValue parameter that was passed rather than the X of the nearest point.
3) YMin and YMax values make no sense.

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

Re: SolveYValueAtXValue for PointLineSeries

Post by ArctionKestutis » Thu Sep 28, 2017 9:42 am

Hello,

Thank you for those detailed observation. Indeed SolveYValueAtXValue() method not aware about DataBreaking feature, which may lead to some unexpected results. The original version of method search for the closest point on XAxis and interpolates Y-value if needed. Therefore, you see difference between NearestX and NearestDataPointIndex. As you noted in 1st message Y-value interpolation maybe between Double.MinValue and the adjacent point.
The DataBreaking could due to X-value as well as Y-value. Therefore, generalizing above method is not going to be easy - sometime assumption of method just completely broken.
The bottom line that you should be more careful with interpreting LineSeriesValueSolveResult if you have enabled DataBreaking. First, you could enable Cursor.SnapToPoint, that way you will avoid interpolation of point. Second, (if x-values remain in progressive order) you should check that NearestDataPointIndex is not adjacent to DataBreaking.Value (and do/don't interpolation yourself).

Hope this helps.
All the best.

Claudio_G
Posts: 13
Joined: Fri Sep 15, 2017 7:28 am

Re: SolveYValueAtXValue for PointLineSeries

Post by Claudio_G » Fri Sep 29, 2017 10:46 am

I ended up doing this, which seems to work

Code: Select all

        /* true if we are on databreaking, false if solved value is OK */
        private bool CheckSolutionBug(PointLineSeries f_Series, LineSeriesValueSolveResult f_Solution_Result, double f_X_Value)
        {
            bool Result = false;

            int l_Point_1_Index;
            int l_Point_2_Index;

            double l_Nearest_X = f_Series.Points[f_Solution_Result.NearestDataPointIndex].X;

            if (l_Nearest_X > f_X_Value)
            {   /* The selected points are the solved X index and previous */
                l_Point_1_Index = f_Solution_Result.NearestDataPointIndex;
                l_Point_2_Index = l_Point_1_Index - 1;
            }
            else
            {   /* else the selected points are the solved X index and next */
                l_Point_1_Index = f_Solution_Result.NearestDataPointIndex;
                l_Point_2_Index = l_Point_1_Index + 1;
            }

            if(f_Series.Points[l_Point_1_Index].Y == Double.MinValue)
            {
                Result = true;
            }

            if (f_Series.Points[l_Point_2_Index].Y == Double.MinValue)
            {
                Result = true;
            }


            return Result;
        }

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

Re: SolveYValueAtXValue for PointLineSeries

Post by ArctionKestutis » Mon Oct 02, 2017 6:56 am

Looks good to me.
Sorry for inconvenience.