You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEATURE]: Add automatic contrast for secondary hover labels #8149
Secondary hover labels inherit their text color from the trace color. However, light or low contrast trace colors can make the text difficult to read against the label background.
I propose using Color.wcagContrast() with a 4.5:1 threshold to automatically select a more readable text color.
I've been thinking about this one and how to avoid making the label just "black". It would be nice to have both the colour coding AND the contrast requirements.
So, could we compare the label colour against the background colour and darken/lighten the label until it contrasts enough? In your screenshot, I envision the "Yellow Trace" label being a darker shade of yellow rather than black.
I'd also want to ensure that we respect a user-supplied namecolor - even if it doesn't have good contrast.
So, could we compare the label colour against the background colour and darken/lighten the label until it contrasts enough? In your screenshot, I envision the "Yellow Trace" label being a darker shade of yellow rather than black.
I think this is feasible. We could maybe use a fixed-iteration binary search (perhaps just <= 5 iterations) to find a lighter or darker shade that meets the contrast while preserving the original hue.
for(vari=0;i<5;i++){// Binary search}
My only concern is the potential performance impact, since this calculation would run during hover rendering.
I'd also want to ensure that we respect a user-supplied namecolor - even if it doesn't have good contrast.
Agreed! This was already the behavior in my original PR #8115. The automatic contrast adjustment only applies when namecolor is not explicitly specified, so user-supplied color is always respected.
Activity
camdecoster commentedon Oct 27, 2026
Thanks for opening this. @KoolADE85 will follow up with you on this.
KoolADE85 commentedon Oct 27, 2026
I've been thinking about this one and how to avoid making the label just "black". It would be nice to have both the colour coding AND the contrast requirements.
So, could we compare the label colour against the background colour and darken/lighten the label until it contrasts enough? In your screenshot, I envision the "Yellow Trace" label being a darker shade of yellow rather than black.
I'd also want to ensure that we respect a user-supplied
namecolor- even if it doesn't have good contrast.Lexachoc commentedon Oct 28, 2026
I think this is feasible. We could maybe use a fixed-iteration binary search (perhaps just <= 5 iterations) to find a lighter or darker shade that meets the contrast while preserving the original hue.
My only concern is the potential performance impact, since this calculation would run during hover rendering.
Agreed! This was already the behavior in my original PR #8115. The automatic contrast adjustment only applies when
namecoloris not explicitly specified, so user-supplied color is always respected.