I’m working on visualizing a hierarchy. There will be clusters of objects, each cluster containing rectangles of fixed width but variable height. I’d like to arrange these within a rectangular space so as to have equal visual spacing between them, something like this:
Before I spend a day inventing the wheel, are there standard algorithms for this kind of distribution and space-filling? If the objects were all the same size, I’d just use a grid.
I’ll be using this algorithm at two levels: once to lay out the clusters, and again to lay out the objects within each cluster. The latter would look best if they were arranged within a roughly circular space, but if that complicates things excessively I’m OK with rectangular.
I won’t be showing relationships between these objects, so distance minimization is not necessary.
There’s a similar question (https://ux.stackexchange.com/questions/29220/what-would-be-the-best-way-to-fill-space-in-an-user-interface-for-irregular-im) about laying out rectangular images while eliminating or minimizing white space. In my case, I want to equalize white space, clusters will be circular, and some clusters will be much larger than others.
5
This is called in mathematics the bin packing problem. There is some example code of the application of the first fit algorithm. Tackling the distribution of white space as required in the second half of your post might be implemented by introducing the concept of elastic “glue” as it is used in the famous typesetting program TeX written by Donald E. Knuth.
I’ve tackled a similar problem by randomising the positions of each object, then measuring the distance and angle (or normalised gradient) to each other object and nudging them a small amount towards or away from each other based on their relationship to the other object (related=close, unrelated=far), then repeating until the distances start to fall within an acceptable range of what you want.
Depending on the size of the data set it can take a while but gives good final results and can look cool in the process! 🙂
1