What are your favorite drawing libraries?
21 points by knl
21 points by knl
To scratch an itch, I’m about to work on a layouting/diagraming tool like d2lang and Graph::Easy, but with a really narrow scope. So I’m looking for good libraries that would make it pleasurable to draw shapes and connecting lines (never did UI work in my life), with easy exporting to SVG. I’m curious to hear about your favorite, go-to libraries for these kinds of tasks, and what makes them special.
TikZ all the way: https://texample.net/signpost/
Unfortunately I don‘t use it anymore, because I rarely need print quality diagrams. If there would be a job opening of creating TikZ figures all day I might think about applying although AI probably steals all the fun nowadays. D3.js is also nice, but I never really got the hang of it.
I've found https://mermaid.js.org/ do more or less all my heavy lifting now-a-days. It works on GitHub/Obsidian and makes it pretty enough for my boxes lines diagrams without too much overhead.
Use SVG directly! It's a very small language supported by most OSs, browsers and editors. It has its quirks but it's super stable. If necessary you can always use imagemagick or any other tool to rasterize it.
I’ve always been a fan of pict, which provides higher order operations for drawing and composition of pictures. As an example, you can call stuff like (beside x y) and it will create a new picture with x and y next to each other horizontally. For drawing diagrams, this model might be very helpful for you!
If you don't mind using an old school DSL there's PIC (and more recently, there's pikchr. They have been around forever and will probably run on any UNIXen with support for troff/groff and maybe even on Windows under WSL.
I'd written up a blog entry about it a while back (just skip the part that turned into a rant at ChatGPT and Google midway through the blog - since they can't seem to surface these tools anymore)
Two.js has warts but it's done the thing that I want it to do. Everything else either brings in a huge mental model with it or is more for specialized tasks that I'm trying to contort to do what I want. I've resigned myself to using "lower level" API calls to draw what I actually want.
For more interactive 2d work, I've used Pixi.js but this doesn't have good SVG export capability.
I've given up on 3d drawing libraries that export to SVG, not that that's a well defined problem to begin with.
The venerable https://plantuml.com/ has support for plenty of drawing DSLs.
Last time I looked at the PlantUML website about a year ago it seemed to have been taken over by malware and spam. It appears to be more benign now (apart from the Google spyware) but I no longer trust it.
That's a bummer, I have used it quite a bit to generate diagrams inside org-mode and it also supports exports to LaTeX for some diagrams; I haven't had issues with the program at least.
These are likely very low level but I’ve enjoyed using Cairo. It’s fairly straightforward but it can also be somewhat limited. I’ve also used Luxor.jl and that was quite enjoyable too! A bit more complete and with more features than Cairo. As you can see, in both cases those provide mostly only primitives but they where quite sufficient for my use of drawing charts. Good luck!