Skip to content

Inconsistent MouseEventArgs OffestX and OffestY in Blazor #28051

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

Closed
Phexyaa opened this issue Nov 21, 2020 · 8 comments
Closed

Inconsistent MouseEventArgs OffestX and OffestY in Blazor #28051

Phexyaa opened this issue Nov 21, 2020 · 8 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved

Comments

@Phexyaa
Copy link

Phexyaa commented Nov 21, 2020

Describe the bug

When using MouseEventArgs.OffsetX and.OffsetY as endpoint coordinates when drawing a line inside of a svg element, the rendered line appears to "snap" to a seemingly random position. This does not happen when I account for the offset on my own.
Problem occurs specifically when moving the mouse towards the start position of the line element that is created on left button mouse click..

To Reproduce

I made a repo to demonstrate, and the only relevant file (as in modified from template) is Index.razor.
https://github.com/Phexyaa/BlazorMouseEventOffsetDemo

Exceptions (if any)

Further technical details

  • ASP.NET Core version
    5

  • Include the output of dotnet --info
    .NET SDK (reflecting any global.json):
    Version: 5.0.100
    Commit: 5044b93829

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19041
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.100\

Host (useful for support):
Version: 5.0.0
Commit: cf258a14b7

.NET SDKs installed:
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.604 [C:\Program Files\dotnet\sdk]
2.1.700 [C:\Program Files\dotnet\sdk]
2.2.102 [C:\Program Files\dotnet\sdk]
2.2.204 [C:\Program Files\dotnet\sdk]
2.2.300 [C:\Program Files\dotnet\sdk]
3.1.403 [C:\Program Files\dotnet\sdk]
5.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download

  • The IDE (VS / VS Code/ VS4Mac) you're running on, and it's version
    Visual Studio Community 2019 V16.8.1
@Phexyaa Phexyaa changed the title Inconsistent MouseEventArgs OffestX and OffestY Inconsistent MouseEventArgs OffestX and OffestY in Blazor Nov 21, 2020
@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label Nov 23, 2020
@mkArtakMSFT
Copy link
Contributor

Thanks for contacting us.
Would you mind seeing whether this is what you're observing: https://stackoverflow.com/questions/27047972/mousemove-offset-x-y-wrong-in-chrome-when-used-on-a-svg-text-element

@mkArtakMSFT
Copy link
Contributor

If so, then we don't think there is something we / Blazor can do.

@mkArtakMSFT mkArtakMSFT added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Nov 23, 2020
@Phexyaa
Copy link
Author

Phexyaa commented Nov 23, 2020

Thanks for contacting us.
Would you mind seeing whether this is what you're observing: https://stackoverflow.com/questions/27047972/mousemove-offset-x-y-wrong-in-chrome-when-used-on-a-svg-text-element

Thank you for the reply.
I do not think that is the issue, since I was testing using Firefox and that post seemed to be Chrome specific.
Is there anything you would like me to do to help debug further?

Like I had mentioned I can make a JS call within the event handler and calculate my own offset without any issue save for the added cost of making a JS call on each mouse move.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Nov 23, 2020
@Phexyaa
Copy link
Author

Phexyaa commented Nov 23, 2020

I just wanted to confirm that my question was clear, since I looked at that SO link again and realized it was from a few years ago. I am using the OffsetX and OffsetY that is built into MouseEventArgs I think this feature was merged in #20478 (hopefully I quoted that correctly) I am not using any other sort of offset given by the browser.

@Phexyaa
Copy link
Author

Phexyaa commented Nov 23, 2020

Update

So I found that everything works as expected when I don't modify the line element being drawn.
Also I find it odd that this problem seems directional.
It works just fine in all directions extending outward from the line's origin point. The issue only arises when I decrease the length of the line or in other words move towards the origin point.

I didn't intend this to turn into a request to debug my code, so with the above said if you feel that this is not an issue with Blazor or the new OffsetX and OffsetY that was added with merge #20478 then I will take it to a more appropriate forum.

@SteveSandersonMS
Copy link
Member

@Phexyaa Glad you were able to make progress.

In general, Blazor just passes through the offsetX/offsetY values supplied by the browser without being in control of how those values are determined. So it seems that we're not able to affect this. If you later come to believe that Blazor in particular is doing something wrong here, please let us know, otherwise I'll regard this as an external matter.

@Phexyaa
Copy link
Author

Phexyaa commented Nov 24, 2020

Thank you for the info, I have one more thing to ask regarding this before I go.
The issue only arises when i change the end point of the line (otherwise coordinates are as expected), which in turn causes the line to be re-rendered. (At least to my understanding)
Is there a chance this affects what element's offset gets passed through? Like, is there a chance the offset that is given is somehow becoming the offset of the line element instead of the svg behind the scenes?

@SteveSandersonMS SteveSandersonMS added ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Nov 24, 2020
@ghost ghost added the Status: Resolved label Nov 24, 2020
@SteveSandersonMS
Copy link
Member

@Phexyaa I'm afraid I don't know. This seems to be purely a question about the browser's internal behaviors. Sorry I can't give an authoritative answer!

@ghost ghost locked as resolved and limited conversation to collaborators Dec 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants