Skip to content

Commit 3b3eb61

Browse files
committed
contour colorscale doesn't support alpha
1 parent 8808852 commit 3b3eb61

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

R/plotly_build.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ map_color <- function(traces, title = "", na.color = "transparent") {
416416
colorObj[["showscale"]] <- TRUE
417417
traces[[i]] <- modify_list(colorObj, traces[[i]])
418418
traces[[i]]$colorscale <- as_df(traces[[i]]$colorscale)
419+
# sigh, contour colorscale doesn't support alpha
420+
if (traces[[i]][["type"]] == "contour") {
421+
traces[[i]]$colorscale[, 2] <- strip_alpha(traces[[i]]$colorscale[, 2])
422+
}
419423
next
420424
}
421425
colorObj$color <- color[[i]]

R/toRGB.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,15 @@ rgb2hex <- function(string = "rgba(255,255,255,1)") {
3939
do.call(grDevices::rgb, c(x, list(maxColorValue = 255)))
4040
})
4141
}
42+
43+
#convert rgba() to rgb()
44+
strip_alpha <- function(string = "rgba(255,255,255,1)", warn = TRUE) {
45+
if (length(string) == 0) return(string)
46+
if (warn) {
47+
if (any(!grepl(",1\\)$", string))) {
48+
warning("Removing an alpha value lower than 1")
49+
}
50+
}
51+
string <- sub(",1\\)$", ")", string)
52+
sub("^rgba", "rgb", string)
53+
}

0 commit comments

Comments
 (0)