feat(dia): support HTML element bounding rect in getNodeBoundingRect#3258
feat(dia): support HTML element bounding rect in getNodeBoundingRect#3258Geliogabalus wants to merge 11 commits intoclientIO:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for measuring HTML magnets (e.g. inside <foreignObject>) in CellView#getNodeBoundingRect() so bounding rectangles can be computed for non-SVG nodes.
Changes:
- Updated
getNodeBoundingRect()to useHTMLElement#getBoundingClientRect()for visible HTML magnets and fall back to an SVG ancestor bbox for invisible ones. - Added QUnit tests covering SVG magnets,
measureNode, visible/invisible HTML magnets, and caching behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/joint-core/src/dia/CellView.mjs | Implements new HTML-element measurement logic in getNodeBoundingRect(). |
| packages/joint-core/test/jointjs/cellView.js | Adds test coverage for the new HTML measurement branches and caching. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Problem
Two related issues when using HTML element magnets (elements inside
<foreignObject>) with links:getNodeBoundingRectonHTMLElementusedV(magnet).getBBox(), which returns the SVG bounding box of theforeignObjectwrapper — not the actual HTML node. On rotated elements this inflates the dimensions incorrectly (the SVG bbox of a rotated rect is larger than the unrotated rect), causing wrong connection point calculations.rectangleIntersectionusedbboxWORotation.center()as the rotation pivot, which is the magnet's center. For port or HTML magnets that are not at the element's center, this is the wrong pivot — JointJS always rotates elements around their own model center.boundaryIntersectionfell back to returning the raw anchor point when the node was not anSVGGraphicsElement(e.g. anHTMLElement). This skipped intersection calculation entirely, attaching links at the anchor rather than on the element's boundary.Changes
dia/CellView.mjs—getNodeBoundingRectHTML supportHTMLElementmagnets and measures them viagetBoundingClientRect()+clientToLocalPoint()to get the center in local paper coordinatesoffsetWidth/offsetHeight(intrinsic, non-inflated dimensions) for width/height — avoiding the inflation that the SVG bbox incurs on rotated elementscheckVisibility()returns false), returns a zero rect and emits aconsole.warninstead of silently producing wrong geometryconnectionPoints/index.mjsrectangleIntersection: pivot fixed toview.model.getBBox().center()— the element's actual rotation origin — instead of the magnet's bbox centerboundaryIntersection: non-SVG (HTML) magnets now route throughrectangleIntersectioninstead of returning the raw anchor, giving a proper boundary connection pointexamples/foreign-object-magnet-jsforeignObject), exercising both the rotated HTML bbox measurement andrectangleIntersectionpivot fixTest plan
measureNodepaper option still takes precedence over built-in HTML measurementconnectionPoint: { name: 'rectangle' }on a rotated element with a port magnet connect to the correct side (rotation pivot fix)boundaryIntersectionon an HTML magnet produces a boundary intersection (not the raw anchor)🤖 Generated with Claude Code