0

I have a PlotModel with multiple LineSeries painted. What I'm looking for is a trick to select all the LineSeries which the point, detect by the MouseDown event, belongs to.

I've done this:

this.MouseDown += CheckIfLineSeriesHasBeenSelected;

private void CheckIfLineSeriesHasBeenSelected(object sender, OxyMouseDownEventArgs e)
{
     switch (e.ChangedButton)
     {
          case OxyMouseButton.Left:
               var series = (LineSeries) this.GetSeriesFromPoint(e.Position, 10);
               series.StrokeThickness = 4;
           break;
      }
 }

But in this way the model changes the thickness of only a small part of the entire LineSeries. Do you have any suggestions? Thanks!

ctt_it
  • 339
  • 1
  • 6
  • 22

1 Answers1

0

You can search randomly around e.Position and select the series:

    private void PlotModel_MouseDown(object sender, OxyMouseDownEventArgs e)
    {
        int radius = 5;
        List<LineSeries> ss = new List<LineSeries>();
        searchAndAdd(ref ss, e.Position);
        Random rand = new Random();
        for (int i = 0; i < 100; i++)
        {
            double x = rand.Next(-radius, radius);
            double y = rand.Next(-radius, radius);
            ScreenPoint pos = new ScreenPoint(e.Position.X + x, e.Position.X);
            searchAndAdd(ref ss, pos);
        }
        foreach (var s in ss)
            s.StrokeThickness = 8;
        plotModel.InvalidatePlot(false);
    }
    void searchAndAdd(ref List<LineSeries> series, ScreenPoint pos)
    {
        var s = plotModel.GetSeriesFromPoint(pos, 10) as LineSeries;
        if (s != null && series.Contains(s) == false)
            series.Add(s);
    }

Note that radius determines how far you are going to search. Also note that you should call plotModel.InvalidatePlot(false); at the end.

rmojab63
  • 3,513
  • 1
  • 15
  • 28