Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve mouse interactions in controls #999

Closed
3 tasks done
kirsan31 opened this issue Apr 29, 2021 · 7 comments
Closed
3 tasks done

Improve mouse interactions in controls #999

kirsan31 opened this issue Apr 29, 2021 · 7 comments

Comments

@kirsan31
Copy link

kirsan31 commented Apr 29, 2021

Tasks

This section was added by @swharden

Original Question

Your Environment

  • ScottPlot Version: 4.1.12 beta
  • Operating System: Win10 20H2
  • Is it a GUI app? What platform? WinForms
  • .Net: net472 and net5.0-windows was checked.

Simple Mdi Winforms app. Child form with only formsPlot1 on it. MouseLeave and MouseEnter not working, MouseMove is working.

This is critical to implement some info on MouseMove (to hide it after we leave the plot).

P.s. Related question:
How to properly implement axes cursor on MouseMove with ScottPlot?
image

I was tring something like this:

private void formsPlot1_MouseMove(object sender, MouseEventArgs e)
{
    (double x, double y) = formsPlot1.GetMouseCoordinates();
    _HLine.Y = y;
    _HLine.IsVisible = true;
    _VLine.X = x;
    _VLine.IsVisible = true;
    formsPlot1.Render(skipIfCurrentlyRendering: true);
}

And it's worked BUT. Because of _HLine and _VLine are plots, ScottPlot autozoom and autoaxes always trying to consider their values. And this lead to whole wrong behavior. For example:

sp.mp4

Cursors must be completely excluded from plotting logic.

Also, is it possible to display Cursor coordinates on the axes (red circles on screen above)?

@kirsan31 kirsan31 added the BUG unexpected behavior label Apr 29, 2021
@StendProg
Copy link
Contributor

StendProg commented Apr 29, 2021

Hi @kirsan31,

  1. FormsPlot: forward all PictureBox mouse events #892 is related issue. But it doesn't solve your specific problem.
    I think the whole point is that the PictureBox rises all events correctly, including MouseLeave and MouseEnter, but they are not redirected to the Control in any way. And PictureBox is private.
    The solution would be either to provide the user with access to the PictureBox, or to redirect all his events to the control (the problem is that there are too many of them).

  2. The problem of calculating limits for Lines has already been discussed, you can try the solution described in Auto scaling axes are misguided by mouse tracker (crosshair) #643 (comment)
    and adopted to 4.1 Automatic axis limit detection considers values of vertical and horizontal axis lines #957 (comment)

  3. Also, is it possible to display Cursor coordinates on the axes (red circles on screen above)?

At the moment this is impossible, but the idea is good, of course there will be problems with circles, but we can make something like notches directly on the axes.

@kirsan31
Copy link
Author

kirsan31 commented Apr 29, 2021

@StendProg
Thank you for your answer.

  1. I think we need redirect all mouse events at least?

  2. Nice work around, thanks.

  3. of course there will be problems with circles.

    No no, this circles there only to point the place where coordinates must appear.

Overall, for now 1. is the main bloker to implement cursors (hiding on mouse leave) on ScottPlot.

@breakwinz
Copy link

breakwinz commented Apr 30, 2021

@kirsan31 I am not sure if this is related. I am using same version and setup. I just use the "Enter" and "Leave" events and it works great. I am not using Mouse_Enter and Mouse_Leave. However as far as I know. Enter and Leave do the same thing as the mouse events

@kirsan31
Copy link
Author

@breakwinz As I remember Enter and Leave are focus related events, so they are not firing if control never got focused.

@swharden
Copy link
Member

MouseEnter and MouseLeave

MouseLeave and MouseEnter not working

These probably are worth forwarding. I'll try to implement these in the next few days, with a demo. Hiding the crosshairs when the mouse exits the plot seems like a good demo.

Keep in mind that for extreme custom mouse interaction is probably just for the programmer to make their own control and implement the features they want. The controls aren't very complicated, and it's much easier to start with the source code and modify it to meet your needs than to try to adapt the standard controls to meet every use case. https://github.com/ScottPlot/ScottPlot/blob/master/src/controls/ScottPlot.WinForms/FormsPlot.cs

Option to ignore axis lines when calling AxisAuto()

The video demonstrates this problem well. Thanks for sharing it! As @StendProg pointed out this question has been raised before. I can add a public field to axis lines so they are ignored when axis limits are determined automatically, which may be a simpler solution.

Labeling crosshair coordinates on the axes

Right now this is not possible, but it should be easy to create a special plot type that does this. I'll put this idea on the triage list (#1028). This type of behavior would be especially useful for financial charts, similar to https://www.tradingview.com/chart

image

swharden added a commit that referenced this issue May 19, 2021
swharden added a commit that referenced this issue May 19, 2021
swharden added a commit that referenced this issue May 19, 2021
@swharden swharden changed the title WInForm MouseEnter and MouseLeave not firing Improve mouse interactions in controls May 19, 2021
@swharden swharden removed the BUG unexpected behavior label May 19, 2021
@swharden
Copy link
Member

All 3 controls now forward enter/leave events and the mouse tracker demos were updated to demonstrate how to use these events. It seems to work no matter what is in focus. This functionality will be in the next release on NuGet, hopefully in a few days 👍

@bclehmann I noticed in the Avalonia control that OnMouseMove is commented-out. Should this be uncommented or deleted?

private void OnMouseMove(object sender, PointerEventArgs e) { Backend.MouseMove(GetInputState(e)); /*base.OnMouseMove(e);*/ }

I'll leave this issue open while I work on the remaining tasks

@bclehmann
Copy link
Member

I noticed in the Avalonia control that OnMouseMove is commented-out. Should this be uncommented or deleted?

It should be replaced with base.OnPointerMoved(e) and uncommented. I did that in #1040

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants