How to generate non-square patchwork (treemap) output?

Here it says that “patchwork” output has always a square shape: patchwork | Graphviz But to me at least it strongly seems that rectangular shapes with other aspect ratios would be way more general. So I wonder if there are any known workarounds to achive this?

Thanks in advance!

I don’t know of any. I suppose you could render to a vector and then resize to achieve a Rectangle ?

This is an interesting and apparently difficult problem.

Someone asked a similar question in StackOverflow in 2011: algorithm - Treemapping with a given aspect ratio - Stack Overflow
in which it is claimed a general solution does not exist. But we’re just interested in good results, not necessarily optimal or “perfect.”

There was some theoretical progress “Treemaps with bounded aspect ratio” 2014 https://www.sciencedirect.com/science/article/pii/S0925772113001764 but doesn’t look like a solution we would use.

Behroozi, Mohammadi and Dunne 2022 did some interesting work and might even have code that can be grafted into Graphviz if someone wants to do the work. https://arxiv.org/pdf/2308.16855.pdf. They state, “Our optimization model is able to generate superior treemaps that could serve as a benchmark for comparing the quality of more computationally efficient algorithms” which suggests maybe their approach is not that fast, but maybe it’s fast enough. The abstract says they propose 5 algorithms. They all seem to be $O(N log N)$ so not sure if the constants are large, or what.