Changed name of set_text_color() to choose_text_color() to avoid confusion with the global option setter functions, e.g. set_text_size(). Updated tests to reflect modified threshold.pull/18/merge
| @@ -45,7 +45,7 @@ static_plot <- function( | |||
| if (!".alpha" %in% names(d)) d <- d %>% mutate(.alpha = 1) | |||
| if (!".textcolor" %in% names(d)) | |||
| d <- d %>% mutate(.textcolor = set_text_color(.color)) | |||
| d <- d %>% mutate(.textcolor = choose_text_color(.color)) | |||
| if (".id_long" %in% names(d)) { | |||
| d <- d %>% mutate(.item_id = paste(.id_long, .col, sep = "-")) | |||
| @@ -142,7 +142,7 @@ add_color_join <- function(x, ids, by, | |||
| .textcolor = text_color) | |||
| if (is.na(text_color)) | |||
| res <- res %>% mutate(.textcolor = set_text_color(.color)) | |||
| res <- res %>% mutate(.textcolor = choose_text_color(.color)) | |||
| return(res) | |||
| } | |||
| @@ -1,6 +1,6 @@ | |||
| `%||%` <- function(x, y) if (is.null(x)) y else x | |||
| set_text_color <- function(x, black = "#000000", white = "#FFFFFF") { | |||
| choose_text_color <- function(x, black = "#000000", white = "#FFFFFF") { | |||
| # x = color_hex | |||
| color_rgb <- col2rgb(x) | |||
| # modified from https://stackoverflow.com/a/3943023/2022615 | |||
| @@ -0,0 +1,6 @@ | |||
| context("test-set_text_color") | |||
| test_that("correct color selection", { | |||
| colors <- c("#FFFFFF", scales::brewer_pal("seq", "Set1")(4), "#000000") | |||
| expect_equal(set_text_color(colors), c("#000000", rep("#FFFFFF", 5))) | |||
| }) | |||
| @@ -1,7 +0,0 @@ | |||
| context("test-set_text_color") | |||
| test_that("correct color selection", { | |||
| colors <- c("#FFFFFF", "#9E788C", "#B679E5", "#4BB757", | |||
| "#000000", "#0027D8", "#E6071B", "#495B3F") | |||
| expect_equal(set_text_color(colors), c(rep("#000000", 4), rep("#FFFFFF", 4))) | |||
| }) | |||