lizmat / App-Raku-Log

Cro application for presenting Raku IRC logs
Artistic License 2.0
3 stars 2 forks source link

Enforce minimum contrast and well-distributed perceptual dynamic colors #16

Open japhb opened 2 years ago

japhb commented 2 years ago

Currently the dynamic username coloring can choose colors that are very close to the background (light yellow on white, for instance). In addition, extremely dark or light colors are hard to distinguish from each other, as they effectively desaturate towards black or white respectively. (Desaturated colors with similar lightness are hard to distinguish in general, but I mention the light and dark cases because it's not always obvious that they are de facto desaturated.)

The color choices should be distributed such that they all have a minimum contrast to the background (choosing a maximum lightness if the background is bright, or minimum lightness if the background is dark), and otherwise distributed around color space in such a way that they are relatively well spaced perceptually.

Note that algorithms for this already exist (it's a really common problem), but many of them are unnecessarily complex for the username coloring use case, because they are trying to squeeze out the last bit of perceptual advantage for much more finicky use cases (such as reducing image palettes for compression).

lizmat commented 2 years ago

Yes, the nick coloring is still a bit hacky. This was partially also caused by the fact that we were still playing with the layout, and the background color. I guess now it's time to get a little more specific. Thanks for the report and the reminder :-)

Altai-man commented 2 years ago

https://www.w3.org/TR/2018/REC-WCAG21-20180605/#dfn-relative-luminance <- a formula to check contrast. https://github.com/Asqatasun/Contrast-Finder <- an example of a generator (in Java).

AlexDaniel commented 2 years ago

camelia is the worst offender in terms of colors :)

image

lizmat commented 2 years ago

Accepting PR's for the colorize-nick logic :-)

AlexDaniel commented 2 years ago

Just for the reference, maybe this would be helpful (and maybe not):

Altai-man commented 2 years ago

For a single page 100 is enough, but if it's a per-user colors saved...

Again, IMO the easiest solution is to write a contrast value checker and when deciding a color for the user, just roll the random against the checker until we get a contrast one. Any opinions why that'd be a bad idea?

lizmat commented 2 years ago

@Altai-man fine by me. PR's or code examples welcome!