Skip to content

Commit f8a57ea

Browse files
committed
Colors: always use complete set
It is small enough so it is not slow, and much more useful than the basic set.
1 parent 8950ff0 commit f8a57ea

File tree

5 files changed

+20
-39
lines changed

5 files changed

+20
-39
lines changed

R/color.R

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,27 @@
22
#'
33
#' @param color A scalar color that is usable as an input to `col2rgb()`
44
#' (assumed to be in the sRGB color space).
5-
#' @param color_set Should the returned color names come from a "simple" smaller
6-
#' set or a longer, more "complete" set?
75
#' @return A character string that is the closest named colors to the input
86
#' color. The output will have an attribute of alternate color names (named
97
#' "alt").
108
#' @export
119
#' @importFrom grDevices col2rgb convertColor
1210

13-
pretty_color <- function(color, color_set=c("simple", "complete")) {
11+
pretty_color <- function(color) {
1412
stopifnot(length(color) == 1)
1513
if (is.na(color)) {
1614
structure(NA_character_, alt=NA_character_)
1715
} else {
18-
color_set <- match.arg(color_set)
1916
if (is.factor(color)) color <- as.character(color)
2017
stopifnot(is.character(color))
2118
color_rgb <- col2rgb(color)
2219
color_lab <- convertColor(t(color_rgb), from="sRGB", to="Lab", scale.in=256)
23-
color_reference_set <-
24-
if (color_set == "simple") {
25-
color_reference[color_reference$basic | color_reference$roygbiv, ]
26-
} else {
27-
color_reference
28-
}
2920
dist <- color_diff_cie76(
3021
color_lab,
31-
as.matrix(color_reference_set[, c("L", "a", "b")])
22+
as.matrix(color_reference[, c("L", "a", "b")])
3223
)
33-
ret <- color_reference_set$name[dist == min(dist)][1]
34-
attr(ret, "alt") <- color_reference_set$name_alt[dist == min(dist)][[1]]
24+
ret <- color_reference$name[dist == min(dist)][1]
25+
attr(ret, "alt") <- color_reference$name_alt[dist == min(dist)][[1]]
3526
ret
3627
}
3728
}
@@ -50,7 +41,9 @@ pretty_colour <- pretty_color
5041
#' \item{roygbiv,basic,html,R,pantone,x11,ntc}{Source dataset containing the color}
5142
#' }
5243
#' @source {https://github.com/colorjs/color-namer} and R `colors()`
53-
"color_reference"
44+
#' @keywords internal
45+
#' @name color_reference
46+
NULL
5447

5548
color_diff_cie76 <- function(color, refs) {
5649
d <- t(refs) - c(color)

man/color_reference.Rd

Lines changed: 7 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/pretty_color.Rd

Lines changed: 5 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/prettyunits.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-color.r

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ test_that("pretty_color works", {
77
)
88
expect_equal(
99
pretty_color("#123456"),
10-
structure("black", alt=c("black", "gray0", "grey0", "Black"))
11-
)
12-
expect_equal(
13-
pretty_color("#123456", color_set="complete"),
1410
structure("Prussian Blue", alt=c("Prussian Blue"))
1511
)
1612
expect_equal(

0 commit comments

Comments
 (0)