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

[Bug]: Link's getBBox returns incorrect value #2820

Open
frnora opened this issue Dec 2, 2024 · 2 comments
Open

[Bug]: Link's getBBox returns incorrect value #2820

frnora opened this issue Dec 2, 2024 · 2 comments

Comments

@frnora
Copy link

frnora commented Dec 2, 2024

I need to use the bboxes of the links to be able to clip them.

I simply tried: link.getBBox() which seems to return an incorrect value.

Further investigation reveals that getPointFromConnectedLink always returns on this line if there is no port id: if (!portId || !this.hasPort(portId)) return center;

Why is the endDef not taken into account in this case and instead it takes the center of the element(s)?

Thanks.

Steps to reproduce

  1. Create two elements
  2. Link them
  3. Modify the anchor points of the link
  4. link.getBBox() returns incorrect values

Version

4.0.1 jointplus

bbox
@frnora frnora added the bug label Dec 2, 2024
@kumilingus
Copy link
Contributor

This behavior is intentional. The bounding box of the link model is only an approximation of the rendered bounding box.

The anchor, connectionPoint, connector, and router cannot be fully accounted for because they might depend on DOM measurements. The link model does not—and should not—have access to the view.

If your anchor relies solely on the model (e.g., modelCenter), you can extend the link class and override the getBBox() method to account for this.

Unless we introduce a new option in the paper to guarantee that no measurements rely on the DOM, or find a way to determine the size of DOM elements without rendering them (including text), this behavior cannot be changed.

@frnora
Copy link
Author

frnora commented Dec 2, 2024

I see, makes sense.
Sadly, it doesn't rely solely on modelCenter (the idea shortly flashed in my head, too).

What would give me the most accurate link bbox? paper.paperToLocalRect( linkView.getBBox() );?

And in that case - what would be the cleanest way to get the correctly sized bbox? Listening to render:done? Currently I am doing:
link target change listener : requireView -> measure bbox with the above line
-> this reports wrong size as the view is updated after the target change listener ran its course

Thanks again!

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

No branches or pull requests

2 participants