Skip to content

Commit 7735a53

Browse files
committed
Fixes #8088: Improve legibility of text in labels with light-colored backgrounds
1 parent fd785fc commit 7735a53

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

docs/release-notes/version-3.1.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* [#8077](https://github.com/netbox-community/netbox/issues/8077) - Fix exception when attaching image to location, circuit, or power panel
1717
* [#8078](https://github.com/netbox-community/netbox/issues/8078) - Add missing wireless models to `lsmodels()` in `nbshell`
1818
* [#8079](https://github.com/netbox-community/netbox/issues/8079) - Fix validation of LLDP neighbors when connected device has an asset tag
19+
* [#8088](https://github.com/netbox-community/netbox/issues/8088) - Improve legibility of text in labels with light-colored backgrounds
1920

2021
---
2122

netbox/utilities/templatetags/helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def fgcolor(value):
233233
value = value.lower().strip('#')
234234
if not re.match('^[0-9a-f]{6}$', value):
235235
return ''
236-
return '#{}'.format(foreground_color(value))
236+
return f'#{foreground_color(value)}'
237237

238238

239239
@register.filter()

netbox/utilities/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ def foreground_color(bg_color, dark='000000', light='ffffff'):
5353
:param dark: RBG color code for dark text
5454
:param light: RBG color code for light text
5555
"""
56+
THRESHOLD = 150
5657
bg_color = bg_color.strip('#')
5758
r, g, b = [int(bg_color[c:c + 2], 16) for c in (0, 2, 4)]
58-
if r * 0.299 + g * 0.587 + b * 0.114 > 186:
59+
if r * 0.299 + g * 0.587 + b * 0.114 > THRESHOLD:
5960
return dark
6061
else:
6162
return light

0 commit comments

Comments
 (0)