Skip to content

Fix the definition of has_fill() #1388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion R/plotly_build.R
Original file line number Diff line number Diff line change
Expand Up @@ -1005,4 +1005,13 @@ supplyUserPalette <- function(default, user) {

# helper functions
array_ok <- function(attr) isTRUE(tryNULL(attr$arrayOk))
has_fill <- function(trace) isTRUE(trace$fill %in% c('tozeroy', 'tozerox', 'tonexty', 'tonextx', 'toself', 'tonext'))
has_fill <- function(trace) {
trace_type <- trace[["type"]] %||% "scatter"
# if trace type has fillcolor, but no fill attribute, then fill is always relevant
has_fillcolor <- has_attr(trace_type, "fillcolor")
has_fill <- has_attr(trace_type, "fill")
if (has_fillcolor && !has_fill) return(TRUE)
fill <- trace[["fill"]] %||% "none"
if (has_fillcolor && isTRUE(fill != "none")) return(TRUE)
FALSE
}
1 change: 1 addition & 0 deletions tests/figs/plotly-color/plotly-color-box-color-stroke.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions tests/testthat/test-plotly-color.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ test_that("Mapping a numeric variable to color works", {
expect_true(all(0 <= markerScale$colorscale[,1] & markerScale$colorscale[,1] <= 1))
})

test_that("color/stroke mapping with box translates correctly", {
d <- data.frame(x = rep(c("A", "B"), each = 5), y = rnorm(10))
l <- plot_ly(d) %>%
add_boxplot(x = ~x, y = ~y, color = ~x, colors = c('A' = "blue", 'B' = "red"), stroke = I("black")) %>%
expect_traces(2, "box-color-stroke")
expect_true(l$data[[1]]$fillcolor == toRGB("blue", 0.5))
expect_true(l$data[[2]]$fillcolor == toRGB("red", 0.5))
expect_true(l$data[[1]]$line$color == toRGB("black"))
expect_true(l$data[[2]]$line$color == toRGB("black"))
})

test_that("Custom RColorBrewer pallette works for numeric variable", {
p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length,
color = ~Petal.Width, colors = "Greens")
Expand Down