-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdark_or_light.Rd
52 lines (48 loc) · 1.83 KB
/
dark_or_light.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dark-or-light.R
\name{dark_or_light}
\alias{dark_or_light}
\title{Chose between dark and light color}
\usage{
dark_or_light(
colors,
threshold = 0.45,
dark.color = "black",
light.color = "white"
)
}
\arguments{
\item{colors}{A vector of color definitions or color names in the background.}
\item{threshold}{numeric A value of luminance in [0..1] indicating the switch
point between dark and light background.}
\item{dark.color, light.color}{A color definition or color name to return as
dark and light colors to contrast light and dark backgrounds respectively.}
}
\description{
Chose between a pair of contrasting dark and light colors based on a weighted
mean of RGB channels of a color. This function implements a simple approach
to the choice for a color of a plot element to ensure it is visible against a
background color.
}
\details{
The switch between dark and light color is based on a quick and
dirty approximation of the luminance of colors computed from RGB values.
This easily computed approximation seems to work well enough. The default
threshold chosen for a switch between black and white may need to be
adjusted for other pairs of colors. Graphic devices can differ in the color
spaces they support, but this is unlikely to affect the choice between
black and white or other pairs of colors with large differences in
luminance.
}
\note{
The current implementation of \code{dark_or_light()} ignores
\code{alpha}, the transparency component, of all its arguments.
}
\examples{
dark_or_light("yellow")
dark_or_light("darkblue")
dark_or_light(c("darkblue", "yellow", "red"))
dark_or_light("#FFFFFF")
dark_or_light("#FFFFFF", dark.color = "darkblue", light.color = "lightgrey")
dark_or_light("#000000", dark.color = "darkblue", light.color = "lightgrey")
}