Skip to content

Commit de00340

Browse files
fix: place collapsed nodes inside schema clusters for proper layout
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>
1 parent 77ebfb5 commit de00340

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/datajoint/diagram.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,14 +514,19 @@ def _apply_collapse(self, graph: nx.DiGraph) -> tuple[nx.DiGraph, dict[str, str]
514514
continue
515515
node_mapping[node] = node
516516

517+
# Build reverse mapping: label -> schema_name
518+
label_to_schema = {label: schema for schema, label in collapsed_labels.items()}
519+
517520
# Add nodes
518521
added_collapsed = set()
519522
for old_node, new_node in node_mapping.items():
520523
if new_node in collapsed_counts:
521524
# This is a collapsed schema node
522525
if new_node not in added_collapsed:
526+
schema_name = label_to_schema.get(new_node, new_node)
523527
new_graph.add_node(new_node, node_type=None, collapsed=True,
524-
table_count=collapsed_counts[new_node])
528+
table_count=collapsed_counts[new_node],
529+
schema_name=schema_name)
525530
added_collapsed.add(new_node)
526531
else:
527532
new_graph.add_node(new_node, **graph.nodes[old_node])
@@ -660,6 +665,11 @@ def make_dot(self):
660665
if successors and successors[0] in schema_map:
661666
schema_map[node] = schema_map[successors[0]]
662667

668+
# Assign collapsed nodes to their schema so they appear in the cluster
669+
for node, data in graph.nodes(data=True):
670+
if data.get("collapsed") and data.get("schema_name"):
671+
schema_map[node] = data["schema_name"]
672+
663673
scale = 1.2 # scaling factor for fonts and boxes
664674
label_props = { # http://matplotlib.org/examples/color/named_colors.html
665675
None: dict(

0 commit comments

Comments
 (0)