Skip to content

Commit 3018fa1

Browse files
committed
Support a named vector as an override to computed colors
1 parent d33f467 commit 3018fa1

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

R/render-plot.R

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,23 @@ renderPlot <- function(expr, width='auto', height='auto', res=72, ...,
9393
}
9494

9595
getColors <- function() {
96-
if (!isTRUE(autoColors)) {
96+
if (identical(autoColors, FALSE)) {
9797
return(NULL)
9898
}
99-
bg <- parseCssColor(session$clientData[[paste0('output_', outputName, '_bg')]])
100-
fg <- parseCssColor(session$clientData[[paste0('output_', outputName, '_fg')]])
99+
bg <- if ("bg" %in% names(autoColors)) {
100+
# TODO: it would be cool to be able to use Sass variables are part of
101+
# this specification, like bg = "$primary", but would need something like
102+
# this first https://github.com/rstudio/bootstraplib/issues/33
103+
autoColors[["bg"]]
104+
} else {
105+
parseCssColor(session$clientData[[paste0('output_', outputName, '_bg')]])
106+
}
107+
fg <- if ("fg" %in% names(autoColors)) {
108+
autoColors[["fg"]]
109+
} else {
110+
parseCssColor(session$clientData[[paste0('output_', outputName, '_fg')]])
111+
}
112+
101113
if (length(bg) == 1 && length(fg) == 1 && !is.na(bg) && !is.na(fg)) {
102114
return(list(bg = bg, fg = fg))
103115
} else {

R/utils.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,8 @@ parseCssColor <- function(colorStr) {
18461846
colorStr[is_rgba] <- rgbFuncToHex(colorStr[is_rgba])
18471847

18481848
# TODO: Implement hsl? Ugh.
1849+
# Update: getPropertyValue() seems to return rgba() codes even if
1850+
# the element is styled with hsl(), so let's not worry for now.
18491851

18501852
colorStr[!(is_hex | is_rgba)] <- NA
18511853
colorStr

0 commit comments

Comments
 (0)