8000 Make ribbon_dat() a no-op if there is no data by cpsievert · Pull Request #2209 · plotly/plotly.R · GitHub
[go: up one dir, main page]

Skip to content

Make ribbon_dat() a no-op if there is no data #2209

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 2 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Close #2208: make ribbon_dat() a no-op if there is no data
  • Loading branch information
cpsievert committed Nov 28, 2022
commit a2709d369babded6e00d25d8fc2945303bc2946b
1 change: 1 addition & 0 deletions R/layers2traces.R
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,7 @@ make_error <- function(data, params, xy = "x") {
# (note this function is also used for geom_smooth)
ribbon_dat <- function(dat) {
n <- nrow(dat)
if (n == 0) return(dat)
o <- order(dat[["x"]])
o2 <- order(dat[["x"]], decreasing = TRUE)
used <- c("x", "ymin", "ymax", "y")
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-ggplot-area.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,18 @@ test_that("traces are ordered correctly in geom_area", {
}
})


test_that("Can handle an 'empty' geom_area()", {
p <- ggplot(data.frame(x = 1, y = 1), aes(x, y)) +
geom_area() +
geom_point()

l <- ggplotly(p)$x

expect_length(l$data, 2)

expect_false(l$data[[1]]$visible)
expect_true(l$data[[2]]$x == 1)
expect_true(l$data[[2]]$y == 1)
expect_true(l$data[[2]]$mode == "markers")
})
0