netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
http://netboxlabs.com/oss/netbox/
Apache License 2.0
16.17k stars 2.59k forks source link

Change Text Color on "Aqua" background #8088

Closed mmfreitas closed 2 years ago

mmfreitas commented 2 years ago

NetBox version

v3.1.0

Feature type

Change to existing functionality

Proposed functionality

Change text color on aqua background.

From this: imageimage

To this: imageimage

Use case

To see the text on an "aqua" background more clearly.

Database changes

No response

External dependencies

No response

jeremystretch commented 2 years ago

So here's an interesting bit of trivia: There's a utility function in NetBox called foreground_color() which is used to determine the color of text over a colored background automatically. We use the RBG code 00ffff for aqua, which resolves to white for its corresponding foreground color.

>>> from utilities.utils import foreground_color
>>> foreground_color('00ffff')
'ffffff'

I do agree that black text is more legible, but I don't recall where the formula it uses came from originally and I'm hesitant to tweak it. Might need to do a bit more research.

hSaria commented 2 years ago

The source of the function appears to be a stackoverflow answer. The RGB multipliers, I believe, come from NTSC's RGB to YIQ conversion formula, where Y, the luma, is for black/white. Not quite sure where the threshold of >186 for black originates from.

hSaria commented 2 years ago

W3 has a page that uses a threshold of 150. On the same page is a slider you can play around with to see how well it works, it works significantly better with 150.

You can check out the source of the W3 page and look for isDark. The class w3color can be found here. It uses the same multipliers as RGB-to-YIQ, but with a 150 threshold on the W3 page.

jeremystretch commented 2 years ago

Reducing the dark threshold to 150 tweaks the text color for several colors, namely fuchsia, agua, light green, orange, and grey. They do seem more readable with this configuration.

Screenshot_2021-12-16 Home NetBox(1)

jeremystretch commented 2 years ago

Thanks for the pointers, @hSaria!