1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #8088: Improve legibility of text in labels with light-colored backgrounds

This commit is contained in:
jeremystretch
2021-12-16 12:44:18 -05:00
parent fd785fc9a5
commit 7735a539e9
3 changed files with 4 additions and 2 deletions

View File

@ -53,9 +53,10 @@ def foreground_color(bg_color, dark='000000', light='ffffff'):
:param dark: RBG color code for dark text
:param light: RBG color code for light text
"""
THRESHOLD = 150
bg_color = bg_color.strip('#')
r, g, b = [int(bg_color[c:c + 2], 16) for c in (0, 2, 4)]
if r * 0.299 + g * 0.587 + b * 0.114 > 186:
if r * 0.299 + g * 0.587 + b * 0.114 > THRESHOLD:
return dark
else:
return light