D2, a diagram scripting language that turns text to diagrams, is now open source
github.com
github.com
We also put up a site for you to compare D2 with MermaidJS, Graphviz, and PlantUML: https://text-to-diagram.com.
Full disclosure, we're a for-profit company. The open-core part is that we make an alternative layout engine which we sell (Jetbrains model, i.e. your copy is your's forever if you've paid for 12+ months). It's not packaged with D2, so you won't see it if you don't want it. D2 is perfectly usable without it, and integrates with multiple free open source layout engines (e.g. the one that Mermaid uses, "dagre", is D2's default). If you want to read more about our plans for D2: https://d2lang.com/tour/future.
Hope you can check it out! It's got an easy install (and uninstall) process.
Any examples of larger diagrams (1000+s of nodes) and how does that perform in layout?
I also love graphviz but had a project to create an app for legible quality management, and it was a headache to shoehorn some concepts into "nodes in an edge connected graph" way of thinking (ended up programatically scripting LaTeX).
With so many visualisation concepts there's room for niche approaches (same in plotting; Matlab/Octave vs Gnuplot vs Pyplot vs R and so on)
The overlap is real however, so a lot of room for teams to learn. Ex: We're the easiest graph tool for jupyter/databricks/streamlit etc teams who use dataframes, and I can imagine those tools learning from us here. In the reverse direction, our work more in terms of quickly configurable global data<>viz data bindings ("using the UI or API, bind each event's score to a hot-and-cold coloring palette and use a warning icon on all type=alert events"), but we have a ways to go to support the more manual artisinal effects of diagramming tools like Figma, where each element might have a super fancy & unique border style.
It's an ~100 node DAG. Graphviz struggles a bit with it, particularly with edge layout.
(Though really, the layout I want for it is a Gnatt chart style layout.)
In my experience graphviz handles up to thousands of nodes and tens of thousands of edges without really breaking a sweat.
edit: I've done the same thing with extracting AWS diagrams from aws describe* calls, with good results.
[1] https://www.rw.cdl.uni-saarland.de/people/sander/private/htm...
Then there's generally the problem of larger graphs, which tend to devolve into a tangled mess and hairballs, simply because they often tend to be well-connected. If there's no way of pruning them beforehand, or perhaps grouping, aggregating or clustering (in a way that makes sense to the viewer, not necessarily only structurally), then it can be hard to get good result.
edit: guessing URL found https://d2lang.com/tour/intro/ which covers it, perhaps worth linking to there from the GitHub page
edit2: ok it is linked, just above the section I was looking at:
Reference
A more formal reference specification is in the works.
I really like the comparison site that you have created - it's great for learning these languages. I would love to see a plugin for Obsidian for the times where I need to add a custom drawing to my notes. It looks like there already are plugins for PlantUML[1] and graphviz[2] today.
(created a Github Discussion to track. https://github.com/terrastruct/d2/discussions/138 . if there's enough demand, we'll do it ourselves)
As an example your tree is laid or left-to-right. The GraphViz one in comparison is top down. It’s not clear to me as a user if that’s forced or a choice (in either case).
Are you able to clarify that sort of difference by either making the diagrams similarly laid out or adding a note if something isn’t possible?
The folks at ELK are doing fantastic work in public as an academic team out of Germany.
https://www.eclipse.org/elk/documentation/algorithmdeveloper... https://www.rtsys.informatik.uni-kiel.de/en/team/soren-domro...
Graphviz's papers are also must-reads (for hierarchical layouts): https://graphviz.org/theory/
In general they are surprisingly readable even without an academic background. Sometimes they go into proofs of correctness like method X really results in minimal edge crossings, and those are gnarly math, but skippable. The bad part is that a lot of these research papers have code that's just broken or wrong, or is NP-hard.
Can't wait for an Obsidian plugin! :D
The project looks to be deprecated: https://github.com/dagrejs/dagre
The comparison website is neat. I don't like to draw the architectural diagrams which graphical tools for my Open-source projects, I'll try D2 for my next project.
Mermaid is quite basic; it lacks functionalities that for me were necessary; for example, direct connection between attributes of different classes.
All in all, PlantUML seems superior to Mermaid, at no cost (both languages are relatively simple to learn).
Mermaid is supported by Github, which may be a necessary requirement for some. On the other hand, among the many functionalities, PlantUML's JSON is unusually good looking out of the box, and if one required the diagram it outputs, it's a great feature, because it requires no syntax knowledge.
Both PlantUML and Mermaid mostly produce (Mermaid more) ugly-looking diagrams (dated, to say the least). In PlantUML, this problem is compounded by the explicit lack of layout, by design.
Other warts: both (PlantUML and Mermaid) languages have limited comment support - they are only supported in specific locations of the diagram declarations.
D2 could be a very welcome "next gen" diagramming language. However, the devil is in the details - text-to-diagram.com show a very basic functionality, so one must carefully check the requirements.
Regarding text-to-diagram.com:
- there's a mistake - PlantUML does support rich text (although "rich" is a fuzzy definition)
- class diagrams are an important use case, which is currently missing
EDIT: clarification about the comment limitations.
i've added a TODO for the class diagrams, will be included this week. https://github.com/terrastruct/text-to-diagram-site/issues/2...
AFAIK they all have comments (see the "Chess" example). what is the limitation of comments you're referring to?
class TestClass {
""Monospaced""
<color:green>Colored
}
See here: https://plantuml.com/creole.Regarding the comments, here's a PlantUML example:
class TestClass {
""Monospaced"" ' comment not supported; displayed
<color:green>Colored
}
class TestClass2 {
' comment supported
Type varname ' comment not supported; displayed
}
' comment supported
foo::bar --> baz ' comment not supported; breaks diagram (!)I've tried to do similar things in graphviz but pulling out individual subgraphs or subsets of nodes + edges isn't easy and I always end up with multiple files for each view that I want to show and they get out of sync.
The Desktop version can also export diagrams when called via CLI, though that is less suitable for CI/CD.
D2 looks like a nice upgrade, but to be as useful as e.g. Mermaid a bunch of plugins will need to be written.
It's fantastic for making diagrams when you want more control over the layout than graphviz or mermaidjs but are looking for a similar type of tool. It's also clean C so easy to embed, and there's a WASM build for browser use.
It is fairly simple in any general purpose language to output pikchr code - I've done this previously for producing autogenerated packet diagrams in documentation.
You can see the results at https://zellyn.com/2022/02/cs-ramble/
I just wanted to drop a reference to Burnt Sushi's ERD tool [0]. It only does one diagram type: Entity Relationship Diagram. It's wonderful. Human-first syntax, code comments, and some simple formatting settings like colors and font sizes that help make more complex diagram pleasing and informative.
Otherwise, the shown workflow seems nice. I'll check out the syntax to see what it brings in comparison to DOT. Thank you.
and if you want to see a fuller static text and rendering: https://text-to-diagram.com/?example=wiiu
I saw a no border version (why was it recorded with a border in the first place?), but still the left part could be easily half the size, it would integrate nicely in the GH page. If you increase the notes font than it would be (probably) legible even on GH.
I think it's a classical example of 'works for me'.
But anyway, is there are plans for Win* release?
yep. should be in a week or so, along with other installation stuff: https://github.com/terrastruct/d2/blob/master/docs/INSTALL.m...
Plus controls. This is a separate rant, but for incomprehensible reasons, Chrome removed the ability to even enable controls for animated GIFs.
So if I miss some detail I was interested in, I can't rewind. I have to wait for it to loop around again. And when it does come back up, I can't pause there; instead, I have to frantically try to memorize what I saw.
Also, I don't know the length, so I don't know if it's worth my time investment to wait for it to loop.
For now, we zoomed the gif in so you can see it better. And we added a syntax example front and center.
https://text-to-diagram.com/ says the sequence diagrams aren't supported, but your github description says
> D2 intends to integrate with a variety of layout engines, e.g. dot, as well as single-purpose layout types like sequence diagrams. You can choose whichever layout engine you like and works best for the diagram you're making.
Can you explain a bit more about this, if I wanted to create a sequence diagram with D2 today is there a simple path to follow to do this?
Thanks for the work on the project!
The syntax is much friendlier than any other tool of this sort, and being programmable and extensible from Go is a great plus. I think you should add this aspect to your comparison on https://text-to-diagram.com/ (also a nice touch!), as I don't remember this being possible with others, though I might be wrong.
I'm looking forward to this having sequence diagram support, and it might just become my go-to next time. Definitely keeping an eye on this project.
I live well with your install.sh not beeing able to reckognize that I'm on Debian and have a slightly different layout than generic Linux. On the other hand, getting installations from outside repos into /usr/local/bin, isn't a bad choice over all.
Me not beeing used to using curl, I didn't realize that the dry run parameter to go at the end of install command. I guess most people who downloads from github gets that. A line or two on how you do a dry run, with the command line fully spelled out wouldn't hurt though.
Now that all the sour critique is out of the way, I want to repeat my thank you's, the comparative site was great, and so were the examples, and it came just in time!
I'm going to use this for small simple diagrams, and some views of ER models, I'm not into the call graph, or drawing 1000's of nodes thing at the moment, it will probably work well for that too.
My point is, that your graphs are actually simpler to define than using groff's pic macro package, or the stand-alone pic2graph utility.
So. Thank you!!
https://mermaid.live/edit#pako:eNpVkEFrwzAMhf-K0GmD5A_kMFiTr...
https://www.planttext.com/?text=SoWkIImgAStDuU9ooazIqBLJSCp9...
VS Code extension, too: https://github.com/terrastruct/d2-vscode
Basically the choices were down to:
1. Graphics tools (Google Drawings / Draw.io) - which were a pain for complex charts and maintenance.
2. Code-based tools such as plantUML which was mature and solid, but required Java :|
2. Any plans for native C4 model support, or examples how to emulate it?
3. What about layout control? By default D2 generate way nicer layout, but it is synthetic. How I can tune it, give some hints, etc?
2. with any integration, if there's enough demand, we'll do it. Once we add interactivity to diagrams, it should be trivial to emulate. However I should mention that Simon Brown (the creator of C4) has his own DSL for C4 https://github.com/structurizr/dsl)! We have no intention of competing with it.
3. Currently the options to tune are limited. The Terrastruct app has granular layout control via drag-and-drop, and we're working to bring some of that to native/open-source.
I guess for now I can use d2 and then insert the generated svg but I would like sth closer to that holy grail of version-controlled documentation where you type and everything is magically done in one step and you store no data in the repo.
1) Accept an SQL schema and automatically diagram all tables that interconnect via PK/FK references (including many-to-many).
2) Starting from main(), reflect a compiled code base (or use source files' parse results from https://pkg.go.dev/go/parser) and diagram it down to some level.
i wasn't aware you could selectively choose characters for fonts, but that'd be ideal
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";See https://github.com/terrastruct/d2/issues/96
See https://github.com/terrastruct/d2/blob/master/docs/INSTALL.m...
made an issue to track: https://github.com/terrastruct/d2/issues/134
dyld: cannot load 'd2' (load command 0x80000033 is unknown)
Abort trap: 6If you're subsantially older, you'll probably have to install from source due to the c dependencies.
See https://github.com/terrastruct/d2/blob/master/docs/INSTALL.m...
Through certain configurations, the arrows will end up going directly through unrelated objects.
A crappy example here. The line from x -> cont3.y goes through the cont2 container:
x -> cont.y -> z
x -> cont2.y
x -> cont3.y
cont {
x -> y -> z
}
cont2 {
x -> y -> z
}
cont3 {
x -> y -> z
}
It's buried in the FAQ but it was an interesting comparison
Paper: https://dl.acm.org/doi/10.1145/872730.806459
Mention in troff doc: https://www.troff.org/prog.html#pic
Wikipedia page: https://en.wikipedia.org/wiki/PIC_(markup_language)
https://code.tutsplus.com/tutorials/how-to-draw-a-pie-chart-...
On a side note, one of the Diablo 2 creators posts here from time to time.
I don't think anyone expects short acronyms to be globally unique
Also, and I may be showing my age here, who refers to Destiny 2 as D2 without any context?
Supposedly naming things is one of the problems in programming.