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

isDark(colr)

Arguments

colr

A color. specification. The color 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 color is dark.

  • FALSE if the color is light.

Details

The function uses the relative luminance formula derived from the WCAG (Web Content Accessibility Guidelines) to calculate the perceived brightness of the color. If the luminance is below a 123 (on a scale of 0-255), the color 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(c(0, 0, 0))
#> Error in grDevices::col2rgb(colr): numerical color values must be positive
IssueTrackeR:::isDark(c(255, 255, 255))
#> [1] FALSE FALSE FALSE