Nodes Browser

ComfyDeploy: How auto nodes layout works in ComfyUI?

What is auto nodes layout?

A ComfyUI extension to apply better nodes layout algorithm to ComfyUI workflow (mostly for visualization purpose)

How to install it in ComfyDeploy?

Head over to the machine page

  1. Click on the "Create a new machine" button
  2. Select the Edit build steps
  3. Add a new step -> Custom Node
  4. Search for auto nodes layout and select it
  5. Close the build step dialig and then click on the "Save" button to rebuild the machine

ComfyUI auto nodes layout

a ComfyUI extension to apply better nodes layout algorithm to ComfyUI workflow (mostly for visualization purpose)

this repo is a working prototype of my proof-of-concept in comfyanonymous/ComfyUI#1547

short intro

there’s already an 1-click auto-arrange graph but it relies on default arrange() of LiteGraph.js (backbone of ComfyUI) which positions the nodes according to level of dependencies, it’s neat but imo the wires are very disorientated (for visualization purpose)

my ideal is to have all wires visible, in term of direction, flow and connection to nodes

from my very limited understanding, most if not all ComfyUI workflows can be qualified as directed acyclic graph, so we can apply better graph drawing algorithms, in particular here i focus on hierarchical graph drawing the most suitable for directed acyclic graph

credit: inspiration from this comment

disclaimer: personal preference, graph very much larger, not always guarantee a better layout for all use-cases

implementation details

the principle is use an external library to calculate all nodes position, then retrieve back to LiteGraph.js

recommend to remove reroute nodes:

  • directed acyclic graph has start & end nodes
  • the algorithms work by assigning ranks/depth to each node (hence “hierarchical” or “layered” in context of tree/upside-down graph)
  • reroute nodes mess up ranks/depth so should be removed
  • after applied layout u can re-add reroute nodes for any wires intercepted or partially hidden by nodes
  • side-note: since ComfyUI workflows are left-right hence no depth but column

requirements:

  • ComfyUI version later than PR comfyanonymous/ComfyUI#1273 or commit bc76b38

implemented algorithms:

undo/redo possible with https://github.com/bmad4ever/ComfyUI-Bmad-DirtyUndoRedo

2 options to control layout density:

  • spacing between ranks/depths/columns
  • spacing between nodes in same rank/depth/column

TODO:

  • ✅ refresh after apply layout (issues #1 #2)
  • ✅ add UI options to change density
  • ⬜ better UI than pop-up (?) for options to change density
  • ⬜ option to select layout strategy (see docs for each algo), maybe submenu

example

using noisy latent composition example

(the empty black rectangle box is browser viewport)

  • original workflow: Imgur remove groups coz nodes gonna be placed very differently

  • LiteGraph.js default auto-arrange: Imgur

  • Dagre.js layout: Imgur

  • ELK.js ‘layered’ layout: Imgur

extra

other possible graph layout in JS (but unsatisfying to me nor for DAG):