Skip to content

Conversation

@dimitri-yatsenko
Copy link
Member

@dimitri-yatsenko dimitri-yatsenko commented Jan 23, 2026

Summary

Comprehensive improvements to dj.Diagram including bug fixes, new features, and better visualization.

Bug Fixes

  • Fix isdigit() missing parentheses (line 289)
  • Fix nested list instead of flat list (line 295)
  • Remove dead code graph.nodes() call (line 335)
  • Fix invalid color code for Part tier (7 → 8 digits)
  • Replace eval() with safe _resolve_class() method
  • Reset alias node counter on dependencies.clear() to prevent duplicate orange dots
  • Fix collapse chaining: A.collapse() + B.collapse() + C.collapse() now works correctly

New 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:

# Show acquisition expanded, processing and analysis collapsed
dj.Diagram(acquisition) + dj.Diagram(processing).collapse() + dj.Diagram(analysis).collapse()

# Or collapse everything then expand specific tables
(dj.Diagram(schema1) + dj.Diagram(schema2)).collapse() + dj.Diagram(ImportantTable)
  • "Expanded wins" rule: if a node is expanded in any operand, it stays expanded
  • Collapsed nodes show as 3D boxes with "(N tables)" label inside their schema cluster

Layout Direction

Default changed from TB (top-to-bottom) to LR (left-to-right). Configurable via:

dj.config.display.diagram_direction = "TB"  # or "LR", "BT", "RL"

Mermaid Output

Web-friendly diagram format for documentation:

print(dj.Diagram(schema).make_mermaid())
dj.Diagram(schema).save("pipeline.mmd")

Internal Improvements

  • Simplified collapse logic: single _expanded_nodes set instead of _explicit_nodes + _is_collapsed
  • Fresh diagrams start with all nodes expanded
  • collapse() clears expanded nodes
  • + operator unions expanded nodes (expanded wins)

Test Plan

  • All 21 documentation notebooks pass against PostgreSQL
  • Manual testing of collapse combinations
  • Mermaid output renders correctly at mermaid.live

🤖 Generated with Claude Code

@github-actions github-actions bot added enhancement Indicates new improvements feature Indicates new features labels Jan 23, 2026
@dimitri-yatsenko dimitri-yatsenko changed the base branch from master to pre/v2.1 January 23, 2026 18:37
@dimitri-yatsenko dimitri-yatsenko force-pushed the feat/diagram-improvements branch 2 times, most recently from ea443f4 to 828f70e Compare January 23, 2026 19:21
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>
@dimitri-yatsenko dimitri-yatsenko force-pushed the feat/diagram-improvements branch from 828f70e to f98cdbf Compare January 23, 2026 19:29
dimitri-yatsenko and others added 14 commits January 23, 2026 13:47
- 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>
@dimitri-yatsenko dimitri-yatsenko changed the title WIP: feat(diagram): add direction, Mermaid output, and schema grouping feat(diagram): schema grouping, collapse, Mermaid output, and bug fixes Jan 23, 2026
@dimitri-yatsenko dimitri-yatsenko marked this pull request as ready for review January 23, 2026 23:57
@dimitri-yatsenko dimitri-yatsenko requested review from MilagrosMarin and esutlie and removed request for A-Baji, esutlie and guzman-raphael January 23, 2026 23:57
dimitri-yatsenko and others added 2 commits January 23, 2026 21:49
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@MilagrosMarin MilagrosMarin merged commit a8b0734 into pre/v2.1 Jan 24, 2026
7 of 8 checks passed
@MilagrosMarin MilagrosMarin deleted the feat/diagram-improvements branch January 24, 2026 03:52
@dimitri-yatsenko dimitri-yatsenko added this to the DataJoint 2.1 milestone Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Indicates new improvements feature Indicates new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants