Skip to content

Conversation

@kumilingus
Copy link
Contributor

@kumilingus kumilingus commented Jan 29, 2026

Summary

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 attribute
  • Add config.storeEmbeds option to disable storing embeds attribute
  • Add TypeScript definitions for GraphHierarchyIndex

Behavior

Default (config.storeEmbeds: true):

  • Same as before - embeds attribute is set, change:embeds events fire

With config.storeEmbeds = false:

  • The embeds attribute is not set on cells
  • The change:embeds events do not fire
  • Cell.getEmbeddedCells() still works via the hierarchy index

Benefits

  • Simplified JSON import: When creating a graph from JSON, you only need to specify the parent attribute on child cells. The hierarchy index automatically builds the parent-child relationships without requiring the embeds array on parent cells. This eliminates the risk of invalid states from mismatched parent/embeds data.

Test plan

  • Added tests for graph.hierarchyIndex
  • Added tests for config.storeEmbeds option
  • Existing embedding tests pass
  • TypeScript definitions compile

🤖 Generated with Claude Code

Copy link

Copilot AI left a 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 GraphHierarchyIndex class that tracks parent-child relationships using Maps and Sets for O(1) lookups
  • Updated Cell.getEmbeddedCells() to use the hierarchy index instead of the embeds attribute
  • New config.storeEmbeds configuration option (defaults to true for 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.

kumilingus and others added 4 commits January 30, 2026 13:55
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]>
@kumilingus kumilingus force-pushed the feat/graph-hierarchy-index branch from 1bfd33d to f6d033c Compare January 30, 2026 12:55
…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]>
Copy link

Copilot AI left a 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.

@zbynekstara zbynekstara merged commit de2357e into clientIO:master Jan 30, 2026
3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants