The problem is, I have a bunch of rectangles (about 50 in total) which represent linear chains of events, and I need to distribute these rectangles around a (limitless) 2D plane in the most optimal way. The rectangles are all of the same width, but of different heights. Furthermore, the chains of rectangles are occasionally inter-linked. There might be a "junction" rectangle which is linked to three, four, even five other rectangles. This is what has me completely stumped: how to distribute all of the rectangles such that the linkages are concentrated geographically, and don't sprawl all over the canvas? In other words: how to keep it tidy, and elegant?
Here is a mock-up of how the end result should look. The only difference is that the rectangles' heights will vary slightly. Note that there is a right-ward "drift", because the rectangles are prequels/sequels of each other.

I am not a mathematical guy, and it's a mystery to me that, in so many of my creative projects, I somehow end up needing mathematics and geometry. I wish it didn't happen, because I hate having to ask for help as a complete "maths newbie" like this. Anyway, if anyone can think of a way to approach this problem, or a forum where I'd be best asking, please let me know.

