Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

27 rindas
947B

  1. `%||%` <- function(x, y) if (is.null(x)) y else x
  2. choose_text_color <- function(x, black = "#000000", white = "#FFFFFF") {
  3. # x = color_hex
  4. color_rgb <- col2rgb(x)
  5. # modified from https://stackoverflow.com/a/3943023/2022615
  6. # following W3 guidelines: https://www.w3.org/TR/WCAG20/#relativeluminancedef
  7. color_rgb <- color_rgb / 255
  8. color_rgb[color_rgb <= 0.03928] <- color_rgb[color_rgb <= 0.03928]/12.92
  9. color_rgb[color_rgb > 0.03928] <- ((color_rgb[color_rgb > 0.03928] + 0.055)/1.055)^2.4
  10. lum <- t(color_rgb) %*% c(0.2126, 0.7152, 0.0722)
  11. lum <- lum[,1]
  12. # threshold is supposed to be 0.179 but 1/3 seems to work better for our plots
  13. ifelse(lum > 1/3, black, white)
  14. }
  15. get_input_text <- function(x) {
  16. if (!rlang::is_quosure(x)) x <- rlang::enquo(x)
  17. rlang::quo_name(x)
  18. }
  19. make_named_data <- function(x, y, data_names = c("x", "y")) {
  20. ll <- rlang::eval_tidy(rlang::quo(list(!!x, !!y)))
  21. names(ll) <- data_names
  22. ll
  23. }