Skip to content

Commit

Permalink
add_area() now uses barpolar instead of area (#2041)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert authored Oct 8, 2021
1 parent 1889ca6 commit c35a44e
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 24 additions & 10 deletions R/add.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions man/add_trace.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat/_snaps/plotly-area/add-area.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions tests/testthat/test-plotly-area.R
Original file line number Diff line number Diff line change
@@ -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")
})

0 comments on commit c35a44e

Please sign in to comment.