Aspect ratio with neato or fdp

Is it possible to adjust aspect ratios (via ratio graph attribute) for neato or fdp layout engines? It seems not - any recommendation for how to accomplish that? Thank you!

Edit - This (truncated) file will layout with given aspect ratio in dot, but not neato

strict graph "" {
        graph [ratio=2.5];
        0       [element=8];
        1       [element=6];
        0 -- 1;
        2       [element=6];
        1 -- 2;
        7       [element=6];
        1 -- 7;
        3       [element=6];

Haven’t found any way, yet. Can you share your input file (or part).

Added example to original post

Well, it’s supposed to work in neato. See lib/neatogen/neatosplines.c · main · graphviz / graphviz · GitLab

I don’t see any code in fdpgen for that. One wonders a little about whether it would have made sense to perform this transformation externally (e.g. in lib/common). This would probably entail resampling the edge splines to perform this transformation in an appropriately controlled way. I’m sorry it’s been so long, I can’t remember if there are reasons we didn’t attempt this. It would be a good intermediate level project for someone who wants to work on the code.

1 Like

Thanks! Yes, I looked over the code. Looks a bit too advanced for my level of knowledge of graphviz.

[sorry if this gets too far in the weeds]
[this conversation started on twitter, look here https://twitter.com/andrewwhite01/status/1543039727821115392 to see the graph]

I can interpret “Aspect Ratio” in two ways:

  1. OK to change X or Y scale after laying out the graph.
    This is what the ratio attribute does - for every engine except neato. Neato seems to just ignore ratio.
    The downside is that transforming one dimension starts to look like a “funhouse mirror” effect - squished or stretched. Sometimes no big deal, but maybe not in this graph.
    By the way, neato will honor the ratio attribute if you put it in a pipeline with itself!? Like so,
    neato -Tdot myfile.gv |neato -n2 -Tpng >myfile.png (Possible solution 1)
    Go figure! (Just a wild guess on my part)
  2. Layout the graph honoring non-square boundaries. (Keep it simple, OK with rectangular boundaries, at least to start). Keep X and Y scales identical.
    Neither neato nor fdp seem to support this directly, and hardly indirectly.
  • There do not seem to be any attributes that adjust the bounding-box of the layout
  • There does not seem to be any way to explicitly place “filler nodes” in a graph to fill-in a space. Pinned nodes act as an overlay, and do not seem to affect the rest of the graph placement. The pinned nodes just splat on-top-of the graph. Dang.
  • Clusters just create subsets of the graph, each in its own square space. You could create lots of clusters and then arrange them like building blocks, but this requires a chunk of cluster-moving code. Doable, but questionable. (Possible solution 2)
  • The pack attribute easily allows definition of a non-square (rectangular) layout
    e.g. graph [packmode="array_c4"] (Possible solution 3) Note that graph-level packing is not as dense as the default (node-level). Maybe OK and maybe not.
  • Finally, if all the disconnected graphs are smallish, you could produce a “regular” (squarish) resultant graph, and the carve a slice off of one side. (Remove each disconnected graph that contains any node with X (or Y) outside the new boundary). This require a bit of post-processing and you would actually lose content! (hey, whats losing a few dozen molecules among friends?) In the case of 500 molecules, it might be acceptable. (Possible solution 4)