diff --git a/NEWS.md b/NEWS.md index c705adddc5..de4f7b9de9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,7 @@ ## Breaking changes in JavaScript API -* This version of the R package upgrades the version of the underlying plotly.js library from v1.57.1 to v2.5.1. This includes many breaking changes, bug fixes, and improvements to the underlying JavaScript library. The [plotly.js release page](https://github.com/plotly/plotly.js/releases) has the full list of changes. +* This version of the R package upgrades the version of the underlying plotly.js library from v1.57.1 to v2.5.1. This includes many breaking changes, bug fixes, and improvements to the underlying JavaScript library. Most of the breaking changes are summarized in [this announcement of the 2.0 release](https://community.plotly.com/t/announcing-plotly-js-2-0/53675), but [see here](https://github.com/plotly/plotly.js/blob/HEAD/CHANGELOG.md) for the full changelog. ## Breaking changes in R API diff --git a/R/add.R b/R/add.R index 473178d7bd..b07164c2b9 100644 --- a/R/add.R +++ b/R/add.R @@ -130,9 +130,14 @@ add_data <- function(p, data = NULL) { #' layout(title = "Basic Pie Chart using Plotly") #' #' data(wind) -#' plot_ly(wind, r = ~r, t = ~t) %>% +#' plot_ly(wind, r = ~r, theta = ~t) %>% #' add_area(color = ~nms) %>% -#' layout(radialaxis = list(ticksuffix = "%"), orientation = 270) +#' layout( +#' polar = list( +#' radialaxis = list(ticksuffix = "%"), +#' angularaxis = list(rotation = 90) +#' ) +#' ) #' #' # ------------------------------------------------------------ #' # 3D chart types @@ -432,20 +437,29 @@ add_image <- function(p, z = NULL, colormodel = NULL, ..., data = NULL, inherit #' @inheritParams add_trace #' @rdname add_trace -#' @param r For polar chart only. Sets the radial coordinates. -#' @param t For polar chart only. Sets the radial coordinates. +#' @param r Sets the radial coordinates. +#' @param theta Sets the angular coordinates. +#' @param t Deprecated. Use `theta` instead. #' @export -add_area <- function(p, r = NULL, t = NULL, ..., +add_area <- function(p, r = NULL, theta = NULL, t = NULL, ..., data = NULL, inherit = TRUE) { + if (!is.null(t)) { + message( + "Since `add_area()` now uses the barpolar instead of the area trace, ", + "the `t` argument is now deprecated. Use the `theta` argument instead." + ) + } + theta <- theta %||% t if (inherit) { - r <- t %||% p$x$attrs[[1]][["r"]] - t <- t %||% p$x$attrs[[1]][["t"]] + attrs <- p$x$attrs[[1]] + r <- r %||% attrs[["r"]] + theta <- theta %||% (attrs[["theta"]] %||% attrs[["t"]]) } - if (is.null(r) || is.null(t)) { - stop("Must supply `r`/`t` attributes", call. = FALSE) + if (is.null(r) || is.null(theta)) { + stop("Must supply `r`/`theta` attributes", call. = FALSE) } add_trace_classed( - p, class = "plotly_area", r = r, t = t, type = "area", + p, class = "plotly_area", r = r, theta = theta, type = "barpolar", ..., data = data, inherit = inherit ) } diff --git a/inst/examples/shiny/event_data/tests/shinytest/mytest-expected/001.png b/inst/examples/shiny/event_data/tests/shinytest/mytest-expected/001.png index c5d5b32e60..fbfee45cd5 100644 Binary files a/inst/examples/shiny/event_data/tests/shinytest/mytest-expected/001.png and b/inst/examples/shiny/event_data/tests/shinytest/mytest-expected/001.png differ diff --git a/inst/examples/shiny/event_data/tests/shinytest/mytest-expected/002.png b/inst/examples/shiny/event_data/tests/shinytest/mytest-expected/002.png index 0acf076b4e..e66496ee6f 100644 Binary files a/inst/examples/shiny/event_data/tests/shinytest/mytest-expected/002.png and b/inst/examples/shiny/event_data/tests/shinytest/mytest-expected/002.png differ diff --git a/inst/examples/shiny/event_data/tests/shinytest/mytest-expected/003.png b/inst/examples/shiny/event_data/tests/shinytest/mytest-expected/003.png index c9cfbf44fe..2f2efc015b 100644 Binary files a/inst/examples/shiny/event_data/tests/shinytest/mytest-expected/003.png and b/inst/examples/shiny/event_data/tests/shinytest/mytest-expected/003.png differ diff --git a/inst/examples/shiny/event_data/tests/shinytest/mytest-expected/004.png b/inst/examples/shiny/event_data/tests/shinytest/mytest-expected/004.png index c5d5b32e60..fbfee45cd5 100644 Binary files a/inst/examples/shiny/event_data/tests/shinytest/mytest-expected/004.png and b/inst/examples/shiny/event_data/tests/shinytest/mytest-expected/004.png differ diff --git a/man/add_trace.Rd b/man/add_trace.Rd index 2fc460bb3b..d17ae69676 100644 --- a/man/add_trace.Rd +++ b/man/add_trace.Rd @@ -75,7 +75,7 @@ add_ribbons( add_image(p, z = NULL, colormodel = NULL, ..., data = NULL, inherit = TRUE) -add_area(p, r = NULL, t = NULL, ..., data = NULL, inherit = TRUE) +add_area(p, r = NULL, theta = NULL, t = NULL, ..., data = NULL, inherit = TRUE) add_pie(p, values = NULL, labels = NULL, ..., data = NULL, inherit = TRUE) @@ -151,9 +151,11 @@ provided at this level may override other arguments \item{colormodel}{Sets the colormodel for image traces if \code{z} is not a raster object. If \code{z} is a raster object (see \code{\link[=as.raster]{as.raster()}}), the \code{'rgba'} colormodel is always used.} -\item{r}{For polar chart only. Sets the radial coordinates.} +\item{r}{Sets the radial coordinates.} -\item{t}{For polar chart only. Sets the radial coordinates.} +\item{theta}{Sets the angular coordinates.} + +\item{t}{Deprecated. Use \code{theta} instead.} \item{values}{the value to associated with each slice of the pie.} diff --git a/tests/testthat/_snaps/plotly-area/add-area.svg b/tests/testthat/_snaps/plotly-area/add-area.svg new file mode 100644 index 0000000000..467003cc86 --- /dev/null +++ b/tests/testthat/_snaps/plotly-area/add-area.svg @@ -0,0 +1 @@ +NorthN-EEastS-ESouthS-WWestN-W0%50%100%150%200%11-14 m/s8-11 m/s5-8 m/sless than m/s diff --git a/tests/testthat/_snaps/plotly-subplot/subplot-reposition-shape-fixed.svg b/tests/testthat/_snaps/plotly-subplot/subplot-reposition-shape-fixed.svg index 387e1f78f1..9cb20b0d4a 100644 --- a/tests/testthat/_snaps/plotly-subplot/subplot-reposition-shape-fixed.svg +++ b/tests/testthat/_snaps/plotly-subplot/subplot-reposition-shape-fixed.svg @@ -1 +1 @@ -0246−1012340246−101234 +0246−1012340246−101234 diff --git a/tests/testthat/test-plotly-area.R b/tests/testthat/test-plotly-area.R new file mode 100644 index 0000000000..94a52a5585 --- /dev/null +++ b/tests/testthat/test-plotly-area.R @@ -0,0 +1,12 @@ +test_that("add_area() works", { + data(wind) + p <- plot_ly(wind, r = ~r, theta = ~t) %>% + add_area(color = ~nms) %>% + layout( + polar = list( + radialaxis = list(ticksuffix = "%"), + angularaxis = list(rotation = 90) + ) + ) + expect_doppelganger_built(p, "add-area") +})