Hacker News new | ask | show | jobs
by throw345hn 1945 days ago
Can I ask - how did you find working with graphviz. Was this your first time working with it, how long did it take you to figure out how to place things and draw?

I am working with drawing graphs at the moment and evaluating what library to use, its coincidentally nice to see what you built but it also seems like it was thoughtfully laid out (less edge crossings etc). I am trying to do something more dynamic so it may not be as applicable for me.

I am looking at your code as well, thanks for providing that

2 comments

Not the first time, but possibly the biggest thing I've drawn in it...

There definitely are some weird things when you try to plot complicated things, fighting with weird placement, clusters etc. But not sure if it's me or Graphviz to blame for this. But I don't really know a better tool. If I knew how the diagram would look in hindsight I might have drawn in manually in inkscape or something, but when I started I didn't know what I would end up with, so needed to be an automatic tool :)

To minimize the manual work, I ended up with a mix of DSL in python and raw graphviz commands: https://github.com/karlicoss/myinfra/blob/fc6345c31c4e49b534...

Depending on the things you want to represent a better fit might be force layout, for example something like https://observablehq.com/@morvasaaty/d3-force-notes

Working with graphs, I realized its hard to generate dynamic ones and you inevitably end up with domain specific layouts. I guess thats the nature of graph drawing algorithms, its usually specific to the problem.

Thanks for the code, taking at look at that.

Probably too messy to understand what's exactly happening -- but my main takeaway is that if you implement your own DSL (for Graphviz at least), implement in such a way that you can freely mix DSL and raw bits. That way it's very easy to experiment or tweak minor bits without rewriting half of the code.
If you need to be able to diff the code for graphs, graphviz (dot language) is great.

If you need auto-layout, it's hard to do much better than graphviz. The creators of graphviz have some good papers on what it takes to do that right. They'll discourage you from wanting to re-invent that particular wheel, if you read them. Tricky bit here is, depending on your exact graph and constraints, it's not exactly fully solvable in the general case, if you want to have no overlap or no crossing lines under any circumstances whatsoever. Still, you'll struggle to do better, and there aren't actually a ton of implementations out there other than Graphviz that are anywhere near as good (at least, as of a couple years ago).

Templating or building programmatically? Great, it's just text. Generating on demand? Decent, it's fairly fast.

If you need pretty, and I mean really pretty, and especially pretty and interactive... well it's less enjoyable for that, but then nothing that is enjoyable for that purpose is much good at the other points above.

Thanks for that, will try out graphviz. I was doing some custom implementation for minimizing edge crossings and it seems to work fine for me but thats mostly for 2-layered graphs. If I am to expand to multi-layer graphs, its going to be fairly more complicated to figure out how to do that and I dont know if it will work well.

Graphviz seems to be great for getting you a mostly-useful auto layout majority of the time.

I have a requirement to be able to mix fixed-positioned nodes along with dynamically changing nodes, I havent used graphviz to know if it could do that. A library like cytoscape works ok or maybe d3 (I am still evaluating these)

Honestly coming into this, I thought graph drawing would be fairly easy and I could look up online for examples - but it seems to be quite opposite, its really complicated to get graphs that are both dynamically generated with the nodes positioned at the same place in case there are similar nodes