Skip to content

SignalPlot.GetPointNearestX returns incorrect pointIndex #2044

@CharlesMauldin

Description

@CharlesMauldin

Bug Report

Issue: SignalPlot.GetPointNearestX returns incorrect pointIndex
This issue started after upgrading from v4.1.52 to v4.1.54

Change#1946 seems to have broken it.
v4,1,52 used SamplePeriod
v4.1.54 uses SampleRate

Reproducing: Use AddSignal to add a SignalPlot with a sampleRate other than 1.

    public partial class MainWindow : Window
    {
        private SignalPlot sp;
        private MarkerPlot HighlightedPoint = new();
        private int LastHighlightedIndex = -1;

        public MainWindow()
        {
            InitializeComponent();

            double[] yData = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
            WpfGraph.Plot.Clear();
            sp = WpfGraph.Plot.AddSignal(yData, 2);

            // Add a red circle we can move around later as a highlighted point indicator
            HighlightedPoint = WpfGraph.Plot.AddPoint(0, 0);
            HighlightedPoint.Color = System.Drawing.Color.Red;
            HighlightedPoint.MarkerSize = 8;
            HighlightedPoint.MarkerShape = MarkerShape.openCircle;
            HighlightedPoint.IsVisible = false;

            WpfGraph.Refresh();

            WpfGraph.MouseMove += WpfGraph_MouseMove;
        }

        private void WpfGraph_MouseMove(object sender, MouseEventArgs e)
        {
            (double mouseCoordX, double mouseCoordY) = WpfGraph.GetMouseCoordinates();
            (double pointX, double pointY, int pointIndex) = sp.GetPointNearestX(mouseCoordX);

//Incorrect pointIndex returned in v4.1.55 !
            //Debug.WriteLine("pointIndex = {0}", pointIndex);
            WpfGraph.Plot.Title("pointIndex = " + pointIndex);

            // place the highlight over the point of interest
            HighlightedPoint.X = pointX;
            HighlightedPoint.Y = pointY;
            HighlightedPoint.IsVisible = true;

            // render if the highlighted point chnaged
            if (LastHighlightedIndex != pointIndex) LastHighlightedIndex = pointIndex;

            WpfGraph.Refresh();
        }
    }

System Details

  • ScottPlot Version: 4.1.53?
  • Operating System: Windows 11
  • Application Type: WPF
  • .NET Version: .NET 6.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BUGunexpected behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions