ComfyUI Node

Dynamic Diagram Node

The ComfyUI node that renders Mermaid and PlantUML — and won't draw you a picture

By inkbottle-9·Created 10 months ago·Updated 7 days ago· 3
Dynamic Diagram Node
  • code
  • image
  • text
◄engineauto►
◄formatpng►
◄layoutdot►
◄extra_args►

Dynamic Diagram Node is the odd one out in a diffusion tool: it takes text and turns it into a picture that isn't art. Give it Mermaid, PlantUML or Graphviz source and it shells out to the real rendering tool, drops the result into ComfyUI's temp folder, and shows it on the node.

Why would you want that inside ComfyUI? Same reason you keep a Note node around. The plumbing layer of ComfyUI exists to fight repetition and illegibility, and a diagram is the nuclear option for the second one. A 90-node workflow with four model branches explains itself better as a flowchart than as a comment box - and if that flowchart lives in the graph, it can't get separated from the workflow JSON when you share it. There's also the obvious non-art use: prompt pipelines, scheduler sketches, class diagrams of your LoRA stack, whatever you'd have drawn in Obsidian anyway.

How it works

There is no diagram engine inside this pack. It writes your source to a throwaway file in a mkdtemp folder and runs one of three external CLIs on it:

  • Graphviz - dot -K<layout> -Tpng source.gv -o out.png
  • Mermaid - mmdc -i source.mmd -o out.png (plus -b white -s 2 for PNG)
  • PlantUML - plantuml.jar (or the exe) with -charset UTF-8 -failfast2 -tpng -o <dir> source.uml

Each call has a 15-second timeout, and any failure - nonzero exit, timeout, tool not found - raises an exception and kills the run, printing the tool's stderr so you get the real syntax error instead of a shrug. Two details worth knowing: PlantUML runs with -failfast2 so bad code actually fails instead of silently rendering an error image, and Graphviz's transparent-background PNGs are composited onto white before becoming an IMAGE tensor (otherwise transparent regions turn black).

Inputs and outputs

Five inputs, and only two of them are usually "set and forget."

code is the important one - and it has no text box on the node. It's a socket. You wire a Multiline String (core PrimitiveStringMultiline) into it, or use this pack's own DynamicLoadTextFileNode, which reads a .mmd/.puml/.dot off disk and re-executes when the file's MD5 changes. That's the workflow you actually want: edit the diagram in VS Code, hit Queue, watch it update.

engine picks between auto, graphviz, mermaid, plantuml. Auto is a regex heuristic - @start* means PlantUML, Mermaid keywords (flowchart, sequenceDiagram, gantt…) mean Mermaid, digraph/graph means Graphviz. If nothing matches it warns and defaults to Mermaid, the loosest parser of the three. Set it explicitly if your source is exotic.

format is png or svg. In svg mode you still get a PNG render - SVG can't become an IMAGE tensor - so the PNG feeds the image output, the SVG source goes to text, and the on-node preview uses the vector version because it's sharper.

layout only matters for Graphviz: dot, neato, fdp, sfdp, circo, twopi, patchwork, osage. Other engines ignore it. extra_args appends raw CLI flags to whichever tool ran - handy, sharp-edged, more on that below.

Outputs are both lists, and the node is marked is_output_node, so it renders and previews even with nothing wired out of it. image (IMAGE) is one entry per diagram; text (STRING) is the SVG source per diagram in svg mode, empty strings in png mode. A PlantUML file with three @startuml blocks gives you three images - wire image into Preview Image or Save Image and you get the whole batch (same UI channel the built-in Preview Image uses). Wire text into a Save Text node if you want the SVG files on disk.

Install

Manager: search comfyui_dynamic, or do it by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/inkbottle-9/comfyui_dynamic.git

The pack itself needs psutil and pynvml - installed automatically, and pynvml only feeds the resource-monitor panel, not this node. This node needs neither. What it needs is the external tools, and only the one(s) you'll use:

# Debian/Ubuntu
apt install graphviz plantuml
# macOS
brew install graphviz
# Mermaid needs Node first
npm install -g @mermaid-js/mermaid-cli

Then open ComfyUI settings → Comfy Dynamic / Diagram and point Graphviz path, Mermaid path, PlantUML path, and (if you use the .jar) Java path at the executables or their directories. Leave them empty and the node looks on your system PATH, which is fine if the install put them there. Path changes take effect on the next execution, no restart.

One version note: the whole pack is written against ComfyUI's V3 node schema (io.ComfyNode, define_schema), so it wants a fairly recent ComfyUI - late 2025 onward. On an older install, check out de7b4914835994f91b5bb1863a65e384c648c932, the last commit on the old API.

Where people get burned

You can't type the diagram into the node. The code port is a forced input socket by design, so expect one extra Multiline String node in every setup. Fighting it is wasted effort.

Mermaid's 15-second timeout is tight on a cold start. mmdc launches headless Chromium on every call, and the first run after install can be slow enough to trip the timeout. If Mermaid fails once and then works, that's why. It also makes Mermaid by far the heaviest of the three for what it does - Graphviz and PlantUML are near-instant by comparison.

Named PlantUML blocks lose their output. @startuml myname writes to a custom filename that the node doesn't pick up, so you get nothing. Use plain @startuml. It's in the field's own tooltip and it still catches everyone once.

Very old PlantUML fails with a confusing argument error. The strict-error -failfast2 flag needs a reasonably recent PlantUML; ancient versions reject it and the error message has nothing to do with your diagram. Update PlantUML.

Don't fight the built-in arguments. Graphviz treats a repeated -T as "also output this format" rather than an override, so use the format port, not extra_args. Same for Mermaid's -i/-o - override those and the file lands outside ComfyUI's temp dir and the node can't read it back.

And one honest heads-up about the pack as a whole: its headline node is DynamicScriptNode, a Python code executor. Installing this pack gives you that too, and custom nodes run with full user-level OS access - there's no sandbox in ComfyUI, and the README itself tells you to review the code before running it. The diagram node is the harmless one; just know what else came in the box.

Categorydynamic/utils

Inputs (5)

NameTypeDefaultDescription
codeSTRING,ARRAYDiagram source code: a single string, or a list of strings. Each list item renders as an independent diagram group; non-string and blank items are ignored; an empty list renders nothing (the node outputs zero images without an error). With engine 'auto' the engine is detected from each item independently (@start* -> plantuml, mermaid keywords -> mermaid, digraph/graph -> graphviz), so items may mix engines. For PlantUML, do not use named @start blocks (e.g. '@startuml myname'): their outputs are written under custom file names and get lost; use a plain '@start*' instead.
engineCOMBOautoWhich rendering engine to use. 'auto' detects the engine from each code item independently with heuristics and defaults to mermaid when nothing matches.
formatCOMBOpngOutput format. In svg mode the SVG source code is additionally provided through the text output (a png render is still produced for the image output); in png mode the text output is an empty string.
layoutCOMBOdotGraphviz layout engine (ignored by other engines). The matching executable is resolved next to the configured graphviz tool at execution time; falls back to the configured executable with '-K<layout>', then to 'dot' on PATH.
extra_argsSTRINGCustom command-line arguments appended to the target rendering tool's command line, after the built-in arguments (repeated flags typically take the later value, e.g. graphviz's -K / -G / -N / -E). Exceptions: do not pass -T to graphviz (a repeated -T adds output formats instead of overriding; change the format via the format port), and do not override mermaid's -i / -o (products would no longer be written to ComfyUI's temp directory). Arguments are split with shell-like quoting rules; quote values that contain spaces. Leave empty to pass nothing. In plantuml.jar mode the arguments are consumed by PlantUML itself, not by the java launcher.

Outputs (2)

NameTypeDescription
imageIMAGEThe rendered diagrams (always png renders, also in svg mode); one entry per diagram.
textSTRINGSVG source code, one entry per diagram, in svg mode (all entries are empty strings when the svg render failed); empty strings in png mode.