-
Notifications
You must be signed in to change notification settings - Fork 981
Closed
Labels
Good First IssueThis issue has limited complexity and may be a good start for new contributorsThis issue has limited complexity and may be a good start for new contributorsHelp WantedScott won't do this soon, but PRs from the community are welcome!Scott won't do this soon, but PRs from the community are welcome!⚠️ HIGH PRIORITY
Description
ScottPlot5 demo "Show Value Under Mouse, Multiple Series" responds unintuitively
suggested fix
I added a line in the section where it is searching for the point which is nearest to the mouse position. This should fix the issue.
formsPlot1.MouseMove += (s, e) =>
{
// determine where the mouse is
Pixel mousePixel = new(e.Location.X, e.Location.Y);
Coordinates mouseLocation = formsPlot1.Plot.GetCoordinates(mousePixel);
// get the nearest point of each scatter
Dictionary<int, DataPoint> nearestPoints = new();
for (int i = 0; i < MyScatters.Count; i++)
{
DataPoint nearestPoint = MyScatters[i].Data.GetNearest(mouseLocation, formsPlot1.Plot.LastRender);
nearestPoints.Add(i, nearestPoint);
}
// determine which scatter's nearest point is nearest to the mouse
bool pointSelected = false;
int scatterIndex = -1;
double smallestDistance = double.MaxValue;
for (int i = 0; i < nearestPoints.Count; i++)
{
if (nearestPoints[i].IsReal)
{
// calculate the distance of the point to the mouse
double distance = nearestPoints[i].Coordinates.Distance(mouseLocation);
if (distance < smallestDistance)
{
// store the index
scatterIndex = i;
pointSelected = true;
smallestDistance = distance; //I added this line to update smallestDistance.
}
}
}
// place the crosshair, marker and text over the selected point
if (pointSelected)
{
ScottPlot.Plottables.Scatter scatter = MyScatters[scatterIndex];
DataPoint point = nearestPoints[scatterIndex];
MyCrosshair.IsVisible = true;
MyCrosshair.Position = point.Coordinates;
MyCrosshair.LineColor = scatter.MarkerStyle.Fill.Color;
MyHighlightMarker.IsVisible = true;
MyHighlightMarker.Location = point.Coordinates;
MyHighlightMarker.MarkerStyle.Outline.Color = scatter.MarkerStyle.Fill.Color;
MyHighlightText.IsVisible = true;
MyHighlightText.Location = point.Coordinates;
MyHighlightText.LabelText = $"{point.X:0.##}, {point.Y:0.##}";
MyHighlightText.LabelFontColor = scatter.MarkerStyle.Fill.Color;
formsPlot1.Refresh();
base.Text = $"Selected Scatter={scatter.Label}, Index={point.Index}, X={point.X:0.##}, Y={point.Y:0.##}";
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Good First IssueThis issue has limited complexity and may be a good start for new contributorsThis issue has limited complexity and may be a good start for new contributorsHelp WantedScott won't do this soon, but PRs from the community are welcome!Scott won't do this soon, but PRs from the community are welcome!⚠️ HIGH PRIORITY