Skip to content

Commit

Permalink
Merge pull request #1788 from trekonom/fix-axis-facets
Browse files Browse the repository at this point in the history
Fix axis facets
  • Loading branch information
cpsievert authored Jun 17, 2020
2 parents c19594b + 642069d commit 8d376d1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

## BUG FIXES

* `ggplotly()` now handles discrete axes of a `facet_wrap` and `facet_grid` correctly when there is only one category in panels > 1 (#1577 and #1720).

* `ggplotly()` now handles `element_blank()` and `factor()` labels in positional scales correctly (#1731 and #1772).

# 4.9.2.1
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ verify_attr <- function(proposed, schema, layoutAttr = FALSE) {

# do the same for "sub-attributes"
if (identical(role, "object") && is.recursive(proposed[[attr]])) {
proposed[[attr]] <- verify_attr(proposed[[attr]], schema[[attr]], layoutAttr = layoutAttr)
proposed[[attr]] <- verify_attr(proposed[[attr]], attrSchema, layoutAttr = layoutAttr)
}
}

Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-facet-axis.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
test_that("ggplotly does not break discrete x-axis with facet_yyyy in panels > 1 with only one category", {
d <- data.frame(cat = c("A", "A", "A"), pan = paste("Panel", c(1, 2, 2)))
gp <- ggplot(d, aes(cat)) +
geom_bar() +
facet_wrap(~pan)
L <- plotly_build(ggplotly(gp))
# tickvals, ticktext and categoryarray have class 'AsIs'
lapply(L$x$layout[c("xaxis", "xaxis2")], function(axis) {
expect_s3_class(axis$tickvals, "AsIs")
expect_s3_class(axis$ticktext, "AsIs")
expect_true(axis$ticktext == "A")
expect_s3_class(axis$categoryarray, "AsIs")
expect_true(axis$categoryarray == "A")
})
})

0 comments on commit 8d376d1

Please sign in to comment.