-
Notifications
You must be signed in to change notification settings - Fork 882
feat(dia): support HTML element bounding rect in getNodeBoundingRect #3258
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e41498c
fix
Geliogabalus b2b9465
tests
Geliogabalus 9ee94c0
updates
Geliogabalus f8305b5
fix
Geliogabalus f0466ce
update
Geliogabalus 7e0aa5f
yarn lock
Geliogabalus 073a964
yarn lock fix
Geliogabalus 781839a
wip
Geliogabalus a1e3d59
fix test
Geliogabalus 12915e9
fix
Geliogabalus fb51601
tests
Geliogabalus f209d70
example cleaning
Geliogabalus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
|
|
||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <meta name="description" content="Two shapes with foreignObject HTML div rectangles positioned on their borders."> | ||
| <title>JointJS: ForeignObject Magnets</title> | ||
| </head> | ||
|
|
||
| <body id="app"> | ||
| <div id="paper-container"></div> | ||
| <!-- Application files: --> | ||
| <script type="module" src="/src/main.js"></script> | ||
| </body> | ||
|
|
||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "name": "@joint/demo-foreign-object-magnet-js", | ||
| "private": true, | ||
| "version": "0.0.0", | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "vite", | ||
| "build": "tsc && vite build", | ||
| "preview": "vite preview" | ||
| }, | ||
| "devDependencies": { | ||
| "vite": "^7.3.1" | ||
| }, | ||
| "dependencies": { | ||
| "@joint/core": "workspace:^" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| import { dia, shapes } from '@joint/core'; | ||
| import './styles.css'; | ||
|
|
||
| // Shared badge style (position set per-badge below) | ||
| const BASE_BADGE_STYLE = { | ||
| position: 'absolute', | ||
| width: '84px', | ||
| height: '28px', | ||
| borderRadius: '5px', | ||
| color: '#fff', | ||
| fontSize: '11px', | ||
| fontWeight: 'bold', | ||
| fontFamily: 'sans-serif', | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| boxShadow: '0 2px 4px rgba(0,0,0,.25)', | ||
| letterSpacing: '.5px', | ||
| textTransform: 'uppercase', | ||
| userSelect: 'none', | ||
| pointerEvents: 'none' | ||
| }; | ||
|
|
||
| // CSS positions for each border edge (centered via transform) | ||
| const BADGE_POSITIONS = { | ||
| top: { top: '0', left: '50%', transform: 'translate(-50%, -50%)' }, | ||
| right: { top: '50%', right: '0', transform: 'translate(50%, -50%)' }, | ||
| bottom: { bottom: '0', left: '50%', transform: 'translate(-50%, 50%)' }, | ||
| left: { top: '50%', left: '0', transform: 'translate(-50%, -50%)' } | ||
| }; | ||
|
|
||
| // Single foreignObject containing all 4 badge divs as direct children. | ||
| // Each badge div gets a `selector` which JointJS serialises as the | ||
| // `joint-selector` attribute on the DOM element. | ||
| const borderBadgeMarkup = [ | ||
| { tagName: 'rect', selector: 'body' }, | ||
| { tagName: 'text', selector: 'label' }, | ||
| { | ||
| tagName: 'foreignObject', | ||
| selector: 'badgesFO', | ||
| children: [ | ||
| { tagName: 'div', namespaceURI: 'http://www.w3.org/1999/xhtml', selector: 'topBadge' }, | ||
| { tagName: 'div', namespaceURI: 'http://www.w3.org/1999/xhtml', selector: 'rightBadge' }, | ||
| { tagName: 'div', namespaceURI: 'http://www.w3.org/1999/xhtml', selector: 'bottomBadge' }, | ||
| { tagName: 'div', namespaceURI: 'http://www.w3.org/1999/xhtml', selector: 'leftBadge' } | ||
| ] | ||
| }, | ||
| ]; | ||
|
|
||
| // Base attrs: foreignObject covers the full shape; badges are absolutely | ||
| // positioned relative to the foreignObject's implicit HTML viewport. | ||
| const BASE_ATTRS = { | ||
| body: { | ||
| width: 'calc(w)', | ||
| height: 'calc(h)', | ||
| rx: 10, | ||
| ry: 10, | ||
| strokeWidth: 2, | ||
| stroke: '#7b8cde', | ||
| fill: '#eef0fb' | ||
| }, | ||
| label: { | ||
| text: 'Shape', | ||
| textVerticalAnchor: 'middle', | ||
| textAnchor: 'middle', | ||
| x: 'calc(w/2)', | ||
| y: 'calc(h/2)', | ||
| fontSize: 15, | ||
| fontFamily: 'sans-serif', | ||
| fill: '#3d4a7a' | ||
| }, | ||
| badgesFO: { | ||
| x: 0, | ||
| y: 0, | ||
| width: 'calc(w)', | ||
| height: 'calc(h)', | ||
| overflow: 'visible' | ||
| }, | ||
| topBadge: { style: { ...BASE_BADGE_STYLE, ...BADGE_POSITIONS.top } }, | ||
| rightBadge: { style: { ...BASE_BADGE_STYLE, ...BADGE_POSITIONS.right } }, | ||
| bottomBadge: { style: { ...BASE_BADGE_STYLE, ...BADGE_POSITIONS.bottom } }, | ||
| leftBadge: { style: { ...BASE_BADGE_STYLE, ...BADGE_POSITIONS.left } } | ||
| }; | ||
|
|
||
| const BorderBadgeElement = dia.Element.define( | ||
| 'custom.BorderBadgeElement', | ||
| { size: { width: 200, height: 120 }, attrs: BASE_ATTRS }, | ||
| { markup: borderBadgeMarkup } | ||
| ); | ||
|
|
||
| // --- Paper & Graph --- | ||
|
|
||
| const namespace = { ...shapes, custom: { BorderBadgeElement } }; | ||
|
|
||
| const graph = new dia.Graph({}, { cellNamespace: namespace }); | ||
|
|
||
| const paper = new dia.Paper({ | ||
| el: document.getElementById('paper-container'), | ||
| model: graph, | ||
| width: '100%', | ||
| height: '100%', | ||
| gridSize: 20, | ||
| async: false, | ||
| sorting: dia.Paper.sorting.APPROX, | ||
| background: { color: '#F3F7F6' }, | ||
| cellViewNamespace: namespace | ||
| }); | ||
|
|
||
| paper.setGrid('mesh'); | ||
|
|
||
| paper.scale(1.5, 1.5); | ||
| paper.translate(100, 0); | ||
|
|
||
| // --- Shape 1: Process Node --- | ||
|
|
||
| const shape1 = new BorderBadgeElement({ | ||
| position: { x: 140, y: 160 }, | ||
| attrs: { | ||
| body: { stroke: '#2980b9', fill: '#ebf5fb' }, | ||
| label: { text: 'Process Node', fill: '#1a5276' }, | ||
| topBadge: { html: 'In: 3', style: { backgroundColor: '#2980b9' } }, | ||
| rightBadge: { html: 'Out: 2', style: { backgroundColor: '#27ae60' } }, | ||
| bottomBadge: { html: 'Status: OK', style: { backgroundColor: '#16a085' } }, | ||
| leftBadge: { html: 'ID: A1', style: { backgroundColor: '#8e44ad' } } | ||
| } | ||
| }); | ||
|
|
||
| shape1.addTo(graph); | ||
|
|
||
| shape1.rotate(30); | ||
|
|
||
| // --- Shape 2: Data Store --- | ||
|
|
||
| const shape2 = new BorderBadgeElement({ | ||
| position: { x: 520, y: 160 }, | ||
| attrs: { | ||
| body: { stroke: '#c0392b', fill: '#fdedec' }, | ||
| label: { text: 'Data Store', fill: '#78281f' }, | ||
| topBadge: { html: 'Read', style: { backgroundColor: '#e74c3c' } }, | ||
| rightBadge: { html: 'Write', style: { backgroundColor: '#e67e22' } }, | ||
| bottomBadge: { html: 'Cache', style: { backgroundColor: '#d35400' } }, | ||
| leftBadge: { html: 'Index', style: { backgroundColor: '#c0392b' } } | ||
| } | ||
| }); | ||
|
|
||
| shape2.addTo(graph); | ||
|
|
||
| // --- Link --- | ||
|
|
||
| const link = new shapes.standard.Link({ | ||
| source: { | ||
| id: shape1.id, | ||
| magnet: 'rightBadge', | ||
| connectionPoint: { name: 'rectangle' } | ||
| }, | ||
| target: { | ||
| id: shape2.id, | ||
| magnet: 'leftBadge' | ||
| }, | ||
| attrs: { | ||
| line: { | ||
| stroke: '#999', | ||
| strokeWidth: 2 | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| link.addTo(graph); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| * { | ||
| box-sizing: border-box; | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
|
|
||
| body { | ||
| font-family: sans-serif; | ||
| background-color: #F3F7F6; | ||
| width: 100%; | ||
| height: 100vh; | ||
| } | ||
|
|
||
| #paper-container { | ||
| position: absolute; | ||
| inset: 0; | ||
| overflow: hidden; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.