Skip to content
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

add_area() now uses barpolar instead of area #2041

Merged
merged 5 commits into from
Oct 8, 2021
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
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")
})