I’m not sure it is a bad idea, but I’d be skeptical of making it truly random. Instead I’d create a safe list of background and foreground colors (so you don’t end up with horrible contrast) and then randomly select a set for each category. Maybe come up with 10-20 combinations and if someone has more categories than that, they will just have to get used to it repeating colors.
That’s pretty much what I was thinking, though I think I might rather just pull from the default suggested categories, if only I knew where to look for them. I know enough about Rails to know that they are exactly where they should be, but not enough to know where to look.
Agreed. Rather than random, this function chooses a random value from the set of category colors in site settings.
def random_category_color
colors = SiteSetting.category_colors.split('|')
colors[rand(colors.count)]
end
@gerhard, if I submit this as a PR in base.rb, should it just replace the boring, ugly, default brown, or have some kind of switch to enable the random color and leave brown as the default?
Random category colors still looked like most of the time, so I changed your code snippet a little bit. It now uses the colors in the order defined in site settings. That looks a lot better.