The lighter the bar, the higher the luminance. If the bar is light we like the text overlay be black.
The darker the bar, the lower the luminance. If the bar is dark, we like the text overlay be white.
In the expression above this is written as a predicate. The text appears black if the luminance is above 0.5 and white when the luminance is below 0.5. The luminance is computed using the color scale in combination with the internal computed data field datum.sum_yield. Inspecting the luminance can be done through the tooltip by hovering the bars.
Currently this expression is a str with plain Vega Expression syntax. It would be nice to use the equivalent python syntax instead.
Love this example! I have been doing similar things with a manual threshold as I didn't know there was a function in Vega to compute the luminance already!
This PR adds an example that demonstrates how to change the color of text labels based on measured luminance.
The example looks as such:
Usage of luminance for the text color of the labels was created using the following code (method-based syntax):
Especially this line
In the expression above this is written as a predicate. The text appears black if the luminance is above
0.5
and white when the luminance is below0.5
. The luminance is computed using thecolor
scale in combination with the internal computed data fielddatum.sum_yield
. Inspecting the luminance can be done through the tooltip by hovering the bars.Currently this expression is a
str
with plain Vega Expression syntax. It would be nice to use the equivalent python syntax instead.