I need to show to user a table W x H of short strings.
(Update: The table content is not mutable, I can not move strings around, change them etc.)
For simplicity sake, let's say that:
- I'm visualizing the table using HTML;
- a string is a single word, picked by weighted (by word frequency) random from an English dictionary;
- W and H is in the range from 5 to 10;
- in average case there would be probably 10-15 different words at the same time;
- and in worst case all words in the table are different (that is up to 100 different strings).
To help visualization, I need to colorize backgrounds of the table cells. Cells with the same word should be of the same color.
The question is what is a good algorithm to assign colors to strings in this case?
Additional requirements and notes:
- I do not want to use a hardcoded table of 100 colors, that's not fun.
- Colors should be as visually distinguishable as possible (but with 100 colors that's hard to achieve).
- Alternatively — adjacent cell colors must be as visually distinguishable as possible (as long as they contain different words, of course). But that will complicate algorithm.
- I would like text in each cell to be in the same color (say, black) if possible. Again, this is hard to do with 100 colors. But at the very least, the text should be as readable as possible with any background color.
- Ideally, I would like to do everything in a single pass for simplicity sake and assign colors on the go — but this would harm the distinguishability. So, two passes, I guess.
- In general, performance does not matter, readability and algorithm simplicity do.