I have a (large) horizontally scrolling view, and a bunch of rectangles I'd like to position on it. Each rectangle has a desired horizontal position, but it can vary from that position by up to a certain amount (a constant, K) if needed. The rectangles must not overlap. The vertical position of the rectangles is arbitrary (constrained to the height of the view, of course).
Ideally I'd like to have the size of the rectangles being variable… I guess if that's not possible I can make the size vary in only one dimension.
Now, there will be impossibilities in this layout: since there is only a certain amount of vertical space, and they can only move K pixels away from their ideal horizontally, probably not all rectangles will be able to be drawn. To deal with this, each rectangle has a priority (P), and the lower priority ones should be omitted first. (You can assume that that is non-ambiguous, and that you can always tell which of any two rectangles has the higher priority.)
I'm after conceptual algorithm stuff, but if you need specifics, this will be run on an iPad, and there will be a few thousand (>1000 but <10,000) rectangles to consider. Ideally I'd like something quick enough to re-run every time the user changes the zoom level, but if that's not easy then I can cache the positions. The objects are photos on a timeline, and I want to get them approximately near when the event happened — I'm going for approximate so as to get more of them on there.
I've seen algorithms like this, that do the non-intersecting trick, but don't have the same idea about each item being only allowed to move by up to a certain amount. Obviously without the latter constraint, you can display all items, so I'll also need some way of knowing at what point no more rectangles can be displayed.
If solving the problem as described is too difficult, I'd welcome a suggestion of a more pragmatic idea. If all else fails, I could always do something where it goes through in priority order, renders each item in its desired place if it can, if not then tries shifting it vertically, if still not then shift it horizontally up to the allowable limit, before moving on to the next one. The priority ordering would mean that probably a sub-optimal solution would be found, but it would be weighted towards the most important items.