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:
@ -16,6 +16,7 @@
|
|||||||
* [#8077](https://github.com/netbox-community/netbox/issues/8077) - Fix exception when attaching image to location, circuit, or power panel
|
* [#8077](https://github.com/netbox-community/netbox/issues/8077) - Fix exception when attaching image to location, circuit, or power panel
|
||||||
* [#8078](https://github.com/netbox-community/netbox/issues/8078) - Add missing wireless models to `lsmodels()` in `nbshell`
|
* [#8078](https://github.com/netbox-community/netbox/issues/8078) - Add missing wireless models to `lsmodels()` in `nbshell`
|
||||||
* [#8079](https://github.com/netbox-community/netbox/issues/8079) - Fix validation of LLDP neighbors when connected device has an asset tag
|
* [#8079](https://github.com/netbox-community/netbox/issues/8079) - Fix validation of LLDP neighbors when connected device has an asset tag
|
||||||
|
* [#8088](https://github.com/netbox-community/netbox/issues/8088) - Improve legibility of text in labels with light-colored backgrounds
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ def fgcolor(value):
|
|||||||
value = value.lower().strip('#')
|
value = value.lower().strip('#')
|
||||||
if not re.match('^[0-9a-f]{6}$', value):
|
if not re.match('^[0-9a-f]{6}$', value):
|
||||||
return ''
|
return ''
|
||||||
return '#{}'.format(foreground_color(value))
|
return f'#{foreground_color(value)}'
|
||||||
|
|
||||||
|
|
||||||
@register.filter()
|
@register.filter()
|
||||||
|
@ -53,9 +53,10 @@ def foreground_color(bg_color, dark='000000', light='ffffff'):
|
|||||||
:param dark: RBG color code for dark text
|
:param dark: RBG color code for dark text
|
||||||
:param light: RBG color code for light text
|
:param light: RBG color code for light text
|
||||||
"""
|
"""
|
||||||
|
THRESHOLD = 150
|
||||||
bg_color = bg_color.strip('#')
|
bg_color = bg_color.strip('#')
|
||||||
r, g, b = [int(bg_color[c:c + 2], 16) for c in (0, 2, 4)]
|
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
|
return dark
|
||||||
else:
|
else:
|
||||||
return light
|
return light
|
||||||
|
Reference in New Issue
Block a user