D2: Diagram Scripting Language
11 comments
·October 25, 2025rtpg
I have been looking at things like D2 and Penrose, trying to wrap Python around them to make it a bit easier to script up diagrams based on data.
Working through the problem I realize I probably would have a better time with something like Haskell but I do think the lower the barrier to entry is for drawing up stuff with these tools the more people will reach for programmatic diagramming to help debug and explain things.
The biggest problem with most of the declarative tools like D2,dot,mermaid etc is that they tend to not really offer "declare, then tweak" workflows. You can of course generate some SVG and then tweak it in Inkscape, but sometimes you just want to move something a bit after layout, constraints be damned.
Penrose makes that easier, at the cost of ... I guess everything else being weirder and randomized.
alixanderwang
D2 does allow custom layout tweaking in the proprietary layout engine. Sadly it's not possible in the open-source ones.
viraptor
It's got a sketch mode included! https://d2lang.com/tour/sketch/
And tool tips / links: https://d2lang.com/tour/interactive/
Those two make a huge difference for me.
bargainbin
D2 has a lot of merits but there’s little that sells it over PlantUML or Mermaid - I do feel like diagrams-as-code is still waiting for a killer program that makes everything else obsolete.
I’m forever chasing that dragon. In the meantime I still recommend D2 if PUML is feeling a bit stale.
benzguo
D2 has been around for a while (and has been posted here before) but still surprisingly unknown. It's so much better than mermaid – giving them a boost with this post!
0x696C6961
I like d2 better than mermaid, but mermaid is natively supported in so many places making it the pragmatic choice.
benzguo
true, unfortunately not supported in most markdown renderers... generally i've chosen d2 when i want a more intricate/custom diagram
benzguo
I chose D2 as for our AI's "generate diagram" tool in https://zo.computer and it works quite well. I think the fact that D2 is more expressive than Mermaid is a useful property when doing AI-aided diagram generation.
dalanmiller
Hi Ben! Thank you for making LinkedIn/X bearable!
teleforce
Recent post on D2 (73 comments):
[1] D2 (text to diagram tool) now supports ASCII renders:
Coauthor of D2 here. Lately I've been noodling on the idea of expanding the animation capabilities. I think out loud a bit here, and if you have thoughts, would love to hear them:
https://github.com/terrastruct/d2/discussions/2677