Automatic node column organization and link routing for ComfyUI workflows.
Automatically arranges your workflow nodes into clean, organized columns based on their connections:
- Selected Nodes Support: Organize only selected nodes while leaving others unchanged
- Smart Positioning: Selected nodes maintain their position; full workflows start at [0, 0]
- Size Normalization: Automatically rounds node sizes to nearest 10 units for grid alignment
- Chain Detection: Identifies linear node chains and organizes them horizontally
- Column Layout: Groups nodes into vertical columns based on their depth in the graph
- Leftward Connection Prevention: Automatically detects and corrects backward-flowing connections
- Uniform Spacing: Maintains consistent 100px spacing between columns
- Consistent Sizing: Nodes in the same column are sized to match the widest node
- Smart Spacing: Maintains consistent spacing between nodes vertically
- Preserved Connections: All links remain intact during reorganization
- Conditional ID Cleanup: Reindexes IDs for full workflows; preserves IDs for selected nodes
Automatically detects and fixes overlapping links:
- Overlap Detection: Identifies links that pass through other nodes
- Intelligent Routing: Chooses the most efficient path (above, below, or between nodes)
- Gap Detection: Finds and uses horizontal gaps between nodes within columns
- Path Optimization: Selects routes with shortest total vertical distance
- Auto-Reroute: Creates reroute points to route links cleanly
- Clean Workflows: Results in more readable and maintainable workflows
-
Navigate to your ComfyUI custom nodes directory:
cd ComfyUI/custom_nodes/ -
Clone this repository:
git clone https://github.com/Malkalypse/ComfyUI-Tabularize.git
-
Restart ComfyUI
Organize All Nodes:
- Right-click on the canvas background (with no nodes selected)
- Select 🔲 Tabularize - Organize Columns from the context menu
- All workflow nodes will be reorganized into columns starting at position [0, 0]
- Node and link IDs will be reindexed sequentially
- Links will automatically be rerouted to avoid overlaps
Organize Selected Nodes:
- Select one or more nodes you want to organize
- Right-click on the canvas background
- Select 🔲 Tabularize - Organize Columns from the context menu
- Only the selected nodes will be reorganized, maintaining their original top-left position
- Node and link IDs are preserved
- Unselected nodes remain unchanged
- Right-click on the canvas background
- Select 🔗 Tabularize - Reroute Links from the context menu
- The extension will detect any links passing through nodes
- Reroute points will be automatically added to route links cleanly
The extension uses a hybrid JavaScript/Python architecture:
-
JavaScript (tabularize.js)
- Collects graph data from the ComfyUI canvas
- Sends data to Python backend via HTTP API
- Applies position changes and creates reroute nodes
- Adds context menu items to the canvas
-
Python (tabularize.py)
- Analyzes node graph structure
- Calculates optimal column-based positions
- Detects link-node intersections
- Computes reroute point positions
-
API Layer (api.py)
- Unified HTTP endpoint for all actions
- Action-based dispatch with metadata
- Error handling and logging
- Check Selection: Detects if any nodes are selected to determine organization scope
- Normalize Sizes: Rounds all node dimensions up to the nearest 10 units
- Filter Nodes: If nodes are selected, filters to only those nodes and their interconnections
- Build Graph: Creates parent/child relationship mapping from node connections
- Find Chains: Identifies linear sequences of connected nodes
- Assign Columns: Groups nodes by their depth in the dependency graph
- Fix Leftward Connections: Iteratively detects and corrects backward-flowing links
- Analyzes all connections to find those flowing leftward
- Moves target nodes to columns after their origins
- Recalculates column widths after each adjustment
- Runs up to 20 iterations to resolve complex dependencies
- Rebuild Columns: Removes empty columns and recalculates widths
- Match Widths: Resizes nodes to match their column's maximum width
- Apply Uniform Spacing: Positions columns with consistent 100px gaps
- Vertical Sort: Arranges nodes within columns based on port connections
- Apply Position Offset: Aligns organized nodes to target position
- Selected nodes: Maintains original top-left corner position
- All nodes: Aligns workflow to visual position [0, 0]
- Apply Layout: Updates node positions on the canvas
- Reroute Links: Automatically detects and fixes overlapping links
- Reindex Node IDs (full workflow only): Sequentially renumbers nodes (1, 2, 3, ...) based on position
- Sorts left-to-right by column, top-to-bottom within columns
- Uses two-pass algorithm to prevent ID conflicts
- Skipped when organizing selected nodes to preserve references
- Reindex Link IDs (full workflow only): Sequentially renumbers links (1, 2, 3, ...) based on connections
- Sorts by origin node, origin slot, target node, target slot
- Maintains all node input/output references
- Skipped when organizing selected nodes to preserve references
- Collect Links: Gathers all connections between nodes
- Detect Overlaps: Checks which links pass through node bounding boxes
- Find Horizontal Gaps: Identifies clear vertical gaps between nodes in each column
- Detects gaps of 20px or larger between consecutive nodes
- Verifies horizontal paths are clear across all intervening columns
- Calculates vertical midpoint of each viable gap
- Compare Routing Options: Evaluates three routing strategies for each overlapping link
- Route above: Total vertical distance to top of highest node
- Route below: Total vertical distance to bottom of lowest node
- Route through gap: Total vertical distance to gap midpoint
- Select Optimal Route: Chooses the option with shortest combined vertical distance
- Considers distance from both origin and target endpoints
- Prefers gaps when they provide shorter paths than going around
- Calculate Points: Determines reroute positions based on selected routing strategy
- Create Reroutes: Adds LiteGraph reroute nodes at calculated positions
ComfyUI-Tabularize/
├── __init__.py # Package initialization, loads API routes
├── api.py # HTTP API handlers with action dispatch
├── tabularize.py # Core organization and routing algorithms
├── utils.py # Python utility functions (debug logging)
├── LICENSE # MPL-2.0 license
├── CHANGELOG.md # Version history
├── README.md # This file
├── pyproject.toml # Project metadata
└── web/
├── tabularize.js # Frontend extension and UI integration
└── utils.js # JavaScript utility functions (logging, debug)
Log Action
{
"action": "log",
"message": "Your log message"
}Organize Action
{
"action": "organize",
"graph": {
"nodes": [...],
"links": [...]
}
}Reroute Action
{
"action": "reroute",
"graph": {
"nodes": [...],
"links": [...]
}
}Contributions are welcome! Please feel free to submit a Pull Request.
MPL-2.0 License - See LICENSE file for details
Created for the ComfyUI community to help manage complex workflow layouts.