-
Notifications
You must be signed in to change notification settings - Fork 981
Closed
Description
Hi,
I have an issue that visually it appears that the mouse is closer to a point but is highlighting another point because of the way the calculation is made and doesn't take into account the axis scale. Looking into the method HighlightPointNearest the formula is only looking at the actual coordinates of the points (x1 - x) * (x1 - x) + (y1 - y) * (y1 - y) and not looking how the points are drawn on the screen.
Note how visually the mouse appears closure to (2, 200) point

As I move the mouse vertically the highlighted point eventually moves from (1, 100) to (2, 200)

Is there way to factor in the pixel location or the scale of the X and Y axis when different so that the point is highlighting correctly?
Sample Project
MainWindow.xaml.cs
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
ScottPlot.PlottableScatterHighlight sphTest;
PlottableVLine vLine;
PlottableHLine hLine;
public MainWindow()
{
InitializeComponent();
double[] xs = new double[] { 1, 2 };
double[] ys = new double[] { 100, 200 };
sphTest = pltTest.plt.PlotScatterHighlight(xs, ys, lineWidth: 0, color: System.Drawing.Color.Blue, markerSize: 10);
vLine = pltTest.plt.PlotVLine(1, color: System.Drawing.Color.Red, lineStyle: LineStyle.Dash);
hLine = pltTest.plt.PlotHLine(100, color: System.Drawing.Color.Red, lineStyle: LineStyle.Dash);
pltTest.Render();
}
private void pltTest_MouseMove(object sender, MouseEventArgs e)
{
(double mouseX, double mouseY) = pltTest.GetMouseCoordinates();
sphTest.HighlightClear();
var (x, y, index) = sphTest.HighlightPointNearest(mouseX, mouseY);
int pixelX = (int)e.MouseDevice.GetPosition(pltTest).X;
int pixelY = (int)e.MouseDevice.GetPosition(pltTest).Y;
(double coordinateX, double coordinateY) = pltTest.GetMouseCoordinates();
XPixelLabel.Content = $"{pixelX:0.000}";
YPixelLabel.Content = $"{pixelY:0.000}";
XCoordinateLabel.Content = $"{coordinateX:0.00000000}";
YCoordinateLabel.Content = $"{coordinateY:0.00000000}";
vLine.position = coordinateX;
hLine.position = coordinateY;
pltTest.Render(skipIfCurrentlyRendering: true);
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels