Skip to content

Signal: how to get the vertical range (not just point) near the cursor #4496

@NiRott

Description

@NiRott

In analogy to your function AxisLine.IsUnderMouse in the example of draggable axis lines(cookbook 5.0.36), I tried to do the same with signal plots. The only problem is that I only find points and no lines. Is there is probably a better solution?

ScottPlot Version: 5.0.44

private int GetIndexOfSignalPlot(Pixel mousePixel)
{
    Coordinates coord = SP.Plot.GetCoordinates(mousePixel);

    double Mindistance = double.PositiveInfinity;
    int IndexNearest = -1;
    for (int i = 0; i < SignalPlots.Count(); i++)
    {
        var Index = SignalPlots[i].GetNearestX(coord, SP.Plot.LastRender, float.MaxValue);
        if (plotViewModel.ListView_Model.Count > i) plotViewModel.ListView_Model[i].ChannelValue = Index.Y.ToString();
        if (!SignalPlots[i].IsVisible) continue;
        DataPoint nearest = SignalPlots[i].GetNearest(coord, SP.Plot.LastRender);
        if (nearest.IsReal)
        {
            double distance = Math.Sqrt(Math.Pow(nearest.X - coord.X, 2) + Math.Pow(nearest.X - coord.X, 2));
            Log.WriteDebug(i.ToString(), distance.ToString());
            if (distance < Mindistance)
            {
                Mindistance = distance;
                IndexNearest = i;
            }
        }
    }
    return IndexNearest;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions