-
Notifications
You must be signed in to change notification settings - Fork 93
feat(diagram): schema grouping, collapse, Mermaid output, and bug fixes #1345
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
Conversation
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
ea443f4 to
828f70e
Compare
Bug fixes:
- Fix isdigit() missing parentheses in _make_graph
- Fix nested list creation in _make_graph
- Remove dead code in make_dot
- Fix invalid color code for Part tier
- Replace eval() with safe _resolve_class() method
New features:
- Add direction parameter ("TB", "LR", "BT", "RL") for layout control
- Add make_mermaid() method for web-friendly diagram output
- Add group_by_schema parameter to cluster nodes by database schema
- Update save() to support .mmd/.mermaid file extensions
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
828f70e to
f98cdbf
Compare
- Remove group_by_schema parameter (always enabled) - Show Python module name as cluster label when available - Assign alias nodes (orange dots) to child table's schema - Add schema grouping (subgraphs) to Mermaid output Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Collect all module names per schema, not just the first - Use Python module name as label if 1:1 mapping with schema - Fall back to database schema name if multiple modules - Strip module prefix from class names when it matches cluster label Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add collapse() method to mark diagrams for collapsing when combined
- Collapsed schemas appear as single nodes showing table count
- "Expanded wins" - nodes in non-collapsed diagrams stay expanded
- Works with both Graphviz and Mermaid output
- Use box3d shape for collapsed nodes in Graphviz
Example:
dj.Diagram(schema1) + dj.Diagram(schema2).collapse()
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When combining diagrams from different schemas using +, the underlying networkx graphs and contexts are now properly merged. This fixes issues where cross-schema references would fail to render. Changes: - __add__: Merge nodes, edges, and contexts from both diagrams - _make_graph: Filter nodes_to_show to only include valid nodes - _apply_collapse: Use validated node sets to prevent KeyError Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Disambiguate cluster labels when multiple schemas share same module name (e.g., all defined in __main__) - adds schema name to label - Fix Computed node shape to use same size as Imported (ellipse, not small circle) - Merge nodes, edges, and contexts when combining diagrams from different schemas Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Fixed bug where A.collapse() + B.collapse() + C.collapse() only collapsed the last diagram. The issue was: 1. _apply_collapse returned early when _explicit_nodes was empty 2. Combined diagrams lost track of which nodes came from collapsed sources Changes: - Remove early return when _explicit_nodes is empty - Track explicit nodes properly through chained + operations - Fresh non-collapsed diagrams add all nodes to explicit - Combined diagrams only add their existing explicit nodes Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Fixed bug where combining diagrams created duplicate alias nodes (orange dots for renamed FKs). The issue was that _node_alias_count wasn't reset when clear() was called, so each load() created new IDs. Now Person + Marriage shows 2 alias nodes instead of 4. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
A fresh dj.Diagram(schema) was incorrectly collapsing because _explicit_nodes was empty. Now we check both _explicit_nodes and _is_collapsed to determine if collapse should be applied: - Fresh diagram (_explicit_nodes empty, _is_collapsed=False): no collapse - Combined collapsed (_explicit_nodes empty, _is_collapsed=True): collapse all - Mixed combination: collapse only non-explicit nodes Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…guous When multiple schemas share the same Python module name (e.g., __main__ in notebooks), collapsed nodes now use the database schema name instead. This makes it clear which schema is collapsed when tables from different schemas are mixed in the same diagram. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Collapsed nodes now include schema_name attribute and are added to schema_map so they appear inside the cluster with other tables from the same schema. This fixes the visual layout so collapsed middle layers appear between top and bottom tables, maintaining DAG flow. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Left-to-right layout is more natural for pipeline visualization, matching the typical data flow representation in documentation. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Since collapsed nodes are now inside clusters that display the schema/module name, the node label only needs to show "(N tables)". Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace complex _explicit_nodes + _is_collapsed with simpler design: - Fresh diagrams: all nodes expanded - collapse(): clears _expanded_nodes - + operator: union of _expanded_nodes (expanded wins) Bump version to 2.1.0a7 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
MilagrosMarin
approved these changes
Jan 24, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Comprehensive improvements to
dj.Diagramincluding bug fixes, new features, and better visualization.Bug Fixes
isdigit()missing parentheses (line 289)graph.nodes()call (line 335)eval()with safe_resolve_class()methoddependencies.clear()to prevent duplicate orange dotsA.collapse() + B.collapse() + C.collapse()now works correctlyNew Features
Schema Grouping (always on)
Tables are automatically grouped by database schema in dashed clusters. The cluster label shows the Python module name when there's a 1:1 mapping, otherwise the database schema name.
Collapse Feature
High-level pipeline views by collapsing schemas into single nodes:
Layout Direction
Default changed from
TB(top-to-bottom) toLR(left-to-right). Configurable via:Mermaid Output
Web-friendly diagram format for documentation:
Internal Improvements
_expanded_nodesset instead of_explicit_nodes+_is_collapsedcollapse()clears expanded nodes+operator unions expanded nodes (expanded wins)Test Plan
🤖 Generated with Claude Code