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

How to get exact coordinates of an element? #113

Open
andreypopov opened this issue Aug 2, 2022 · 1 comment
Open

How to get exact coordinates of an element? #113

andreypopov opened this issue Aug 2, 2022 · 1 comment

Comments

@andreypopov
Copy link
Contributor

I had confused, when I tried to determine elementId coordinates
2022-08-02_17-28-26

I place menu with:
$('.my_menu').show().css({top: msg.event.svgY, left: msg.event.svgX}).insertAfter("#noContextMenu");
But I want to get coordinates of my element and place menu bottom-middle (under red square)

I checked your code and there is some kind of koef which you use to calculate svgX/svgY
pt = pt.matrixTransform($scope.svg.getScreenCTM().inverse());
Maybe you should apply it to bbox?

@bartbutenaers
Copy link
Owner

At the time being we had a discussion about this on Discourse, to make sure all ui nodes had (some kind of) standardized output message format. As you can see here one of the results was to calculate the bbox via getBoundingClientRect instead of via getBBox.

Although that was more about the same order of the values (left-bottom-right-top), but it seems - see this Stackoverflow discussion - that getBoundingClientRect provides coordinates in screen space (= origin is the top left of the window), while getBBox uses the same coordinate space as the SVG elements (= origin is the top left of the SVG).

So it could be that we should use getBBox instead. However it is not clear to me (see here) whether transforms are included? So take transforms into account, your proposal might make mare sense.

And then there is also (see here) the getBoundingClientRect, which they claim takes into account transforms already.

I don't have enough free time these days to figure it all out on my own. So if you could do some comparisons in your drawing for these different methods, that would be welcome!

And if we find a solution, I am not sure whether we should fix the current bbox or not. Because I don't want to break existing flow. On the other hand if the bbox is incorrect, then perhaps nobody uses it. Not sure...

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

2 participants