Selaa lähdekoodia

Rename to choose_text_color and update tests

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
Garrick Aden-Buie 7 vuotta sitten
vanhempi
commit
3ab9ff2096
5 muutettua tiedostoa jossa 9 lisäystä ja 10 poistoa
  1. +1
    -1
      R/plot_helpers.R
  2. +1
    -1
      R/process_data_helpers.R
  3. +1
    -1
      R/utils.R
  4. +6
    -0
      tests/testthat/test-choose_text_color.R
  5. +0
    -7
      tests/testthat/test-set_text_color.R

+ 1
- 1
R/plot_helpers.R Näytä tiedosto

@@ -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 = "-"))

+ 1
- 1
R/process_data_helpers.R Näytä tiedosto

@@ -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
- 1
R/utils.R Näytä tiedosto

@@ -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

+ 6
- 0
tests/testthat/test-choose_text_color.R Näytä tiedosto

@@ -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)))
})

+ 0
- 7
tests/testthat/test-set_text_color.R Näytä tiedosto

@@ -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)))
})

Loading…
Peruuta
Tallenna