Skip to content

Commit 0a5ad3b

Browse files
committed
fix definition of has_fill(), closes #1292
1 parent 741ce17 commit 0a5ad3b

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

R/plotly_build.R

+10-1
Original file line numberDiff line numberDiff line change
@@ -1005,4 +1005,13 @@ supplyUserPalette <- function(default, user) {
10051005

10061006
# helper functions
10071007
array_ok <- function(attr) isTRUE(tryNULL(attr$arrayOk))
1008-
has_fill <- function(trace) isTRUE(trace$fill %in% c('tozeroy', 'tozerox', 'tonexty', 'tonextx', 'toself', 'tonext'))
1008+
has_fill <- function(trace) {
1009+
trace_type <- trace[["type"]] %||% "scatter"
1010+
# if trace type has fillcolor, but no fill attribute, then fill is always relevant
1011+
has_fillcolor <- has_attr(trace_type, "fillcolor")
1012+
has_fill <- has_attr(trace_type, "fill")
1013+
if (has_fillcolor && !has_fill) return(TRUE)
1014+
fill <- trace[["fill"]] %||% "none"
1015+
if (has_fillcolor && isTRUE(fill != "none")) return(TRUE)
1016+
FALSE
1017+
}
Loading

tests/testthat/test-plotly-color.R

+11
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ test_that("Mapping a numeric variable to color works", {
6363
expect_true(all(0 <= markerScale$colorscale[,1] & markerScale$colorscale[,1] <= 1))
6464
})
6565

66+
test_that("color/stroke mapping with box translates correctly", {
67+
d <- data.frame(x = rep(c("A", "B"), each = 5), y = rnorm(10))
68+
l <- plot_ly(d) %>%
69+
add_boxplot(x = ~x, y = ~y, color = ~x, colors = c('A' = "blue", 'B' = "red"), stroke = I("black")) %>%
70+
expect_traces(2, "box-color-stroke")
71+
expect_true(l$data[[1]]$fillcolor == toRGB("blue", 0.5))
72+
expect_true(l$data[[2]]$fillcolor == toRGB("red", 0.5))
73+
expect_true(l$data[[1]]$line$color == toRGB("black"))
74+
expect_true(l$data[[2]]$line$color == toRGB("black"))
75+
})
76+
6677
test_that("Custom RColorBrewer pallette works for numeric variable", {
6778
p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length,
6879
color = ~Petal.Width, colors = "Greens")

0 commit comments

Comments
 (0)