-
Notifications
You must be signed in to change notification settings - Fork 879
feat(dia.Graph): add GraphHierarchyIndex for cell embedding #3155
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
feat(dia.Graph): add GraphHierarchyIndex for cell embedding #3155
Conversation
cfa03ed to
1bfd33d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a new GraphHierarchyIndex that maintains an in-memory index of parent-child cell relationships based on the parent attribute. This enables querying embedded cells without reading the embeds attribute directly. Additionally, a new config.storeEmbeds option allows disabling storage of the redundant embeds attribute while maintaining full embedding functionality through the index.
Changes:
- New
GraphHierarchyIndexclass that tracks parent-child relationships using Maps and Sets for O(1) lookups - Updated
Cell.getEmbeddedCells()to use the hierarchy index instead of theembedsattribute - New
config.storeEmbedsconfiguration option (defaults totruefor backwards compatibility)
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/joint-core/src/dia/GraphHierarchyIndex.mjs | New index class that maintains parent-child relationships by listening to cell add/remove and parent change events |
| packages/joint-core/src/dia/Graph.mjs | Instantiates the hierarchyIndex alongside the existing topologyIndex |
| packages/joint-core/src/dia/Cell.mjs | Updates getEmbeddedCells to read from hierarchy index; conditionally sets embeds attribute based on config |
| packages/joint-core/src/config/index.mjs | Adds storeEmbeds configuration option with documentation |
| packages/joint-core/types/joint.d.ts | Adds TypeScript definitions for GraphHierarchyIndex class and hierarchyIndex property |
| packages/joint-core/test/jointjs/graph.js | Comprehensive test coverage for hierarchy index and storeEmbeds configuration |
| packages/joint-react/src/components/paper/tests/snapshots/paper.test.tsx.snap | Updates snapshot test (pattern ID change) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/joint-react/src/components/paper/__tests__/__snapshots__/paper.test.tsx.snap
Show resolved
Hide resolved
Add a new GraphHierarchyIndex that tracks parent-child relationships based on the `parent` attribute. This allows querying embedded cells without reading the redundant `embeds` attribute. Changes: - Add GraphHierarchyIndex class (similar to GraphTopologyIndex) - Update Cell.getEmbeddedCells() to read from index instead of `embeds` - Add config.storeEmbeds option to disable storing `embeds` attribute - Add TypeScript definitions for GraphHierarchyIndex When config.storeEmbeds is false: - The `embeds` attribute is not set on cells - The `change:embeds` events do not fire - Cell.getEmbeddedCells() still works via the hierarchy index Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Use separate Maps for link and element children (links first ordering) - Use Sets for O(1) add/remove operations - Correctly distinguish numeric vs string IDs (1 !== "1") - Add test for numeric/string ID handling Co-Authored-By: Claude Opus 4.5 <[email protected]>
The hierarchy index is always in sync with the graph, so filtering out undefined values is unnecessary and could hide bugs. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Co-Authored-By: Claude Opus 4.5 <[email protected]>
1bfd33d to
f6d033c
Compare
…eaks Remove Map entries when their Set becomes empty after child removal. This prevents accumulation of empty Set objects in long-running apps. Co-Authored-By: Claude Opus 4.5 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Add a new
GraphHierarchyIndexthat tracks parent-child relationships based on theparentattribute. This allows querying embedded cells without reading the redundantembedsattribute.Changes
GraphHierarchyIndexclass (similar toGraphTopologyIndex)Cell.getEmbeddedCells()to read from index instead ofembedsattributeconfig.storeEmbedsoption to disable storingembedsattributeGraphHierarchyIndexBehavior
Default (
config.storeEmbeds: true):embedsattribute is set,change:embedsevents fireWith
config.storeEmbeds = false:embedsattribute is not set on cellschange:embedsevents do not fireCell.getEmbeddedCells()still works via the hierarchy indexBenefits
parentattribute on child cells. The hierarchy index automatically builds the parent-child relationships without requiring theembedsarray on parent cells. This eliminates the risk of invalid states from mismatchedparent/embedsdata.Test plan
graph.hierarchyIndexconfig.storeEmbedsoption🤖 Generated with Claude Code