Determines whether a given colour is "dark" based on its luminance contrast.

isDark(colr)

Arguments

colr

A colour. specification. The colour must be valid and recognized by grDevices::col2rgb(). It can be a character string (e.g., "#RRGGBB", "red", "transparent") or an integer vector representing RGB values.

Value

A logical value:

  • TRUE if the colour is dark.

  • FALSE if the colour is light.

Details

The function uses the relative luminance formula derived from the WCAG (Web Content ccessibility Guidelines) to calculate the perceived brightness of the colour. If the luminance is below a 123 (on a scale of 0-255), the colour is considered dark.

Examples

# Check a hexadecimal color
IssueTrackeR:::isDark("#000000")  # black is dark
#> [1] TRUE
IssueTrackeR:::isDark("#FFFFFF")  # white is light
#> [1] FALSE

# Check a named color
IssueTrackeR:::isDark("navy")
#> [1] TRUE
IssueTrackeR:::isDark("yellow")
#> [1] FALSE

# Check an RGB vector
IssueTrackeR:::isDark(grDevices::rgb(0, 0, 0))
#> [1] TRUE
IssueTrackeR:::isDark(grDevices::rgb(255, 255, 255, maxColorValue = 255))
#> [1] FALSE