Skip to content

Commit 9816123

Browse files
committed
merge conflicts
2 parents b9a7d98 + 34541df commit 9816123

File tree

7 files changed

+70
-27
lines changed

7 files changed

+70
-27
lines changed

NEWS.md

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,60 @@
22

33
## NEW FEATURES & IMPROVEMENTS
44

5-
* Upgraded to plotly.js v1.38.2. A _huge_ amount of features and improvements have been made since v1.29.2 (i.e., the version included in the last CRAN release of the R package - v4.7.1). Highlights include a complete re-write of `scattergl` to make it nearly feature complete with `scatter`, localization of text rendering (i.e., international translations), and two new trace types (`violin` & `table`). Read more about the v1.32.0 release [here](https://codeburst.io/notes-from-the-latest-plotly-js-release-b035a5b43e21) and the complete list of changes [here](https://github.com/plotly/plotly.js/releases).
5+
### plotly.js and `plot_ly()` specific improvements
6+
7+
* Upgraded to plotly.js v1.38.2. A _huge_ amount of features and improvements have been made since v1.29.2 (i.e., the version included in the last CRAN release of the R package - v4.7.1). Highlights include a complete re-write of `scattergl` to make it nearly feature complete with `scatter`, localization of text rendering (i.e., international translations), and six new trace types (`cone`, `scatterpolar`, `scatterpolargl`, `splom`, `table`, & `violin`)! See [here](https://github.com/plotly/plotly.js/releases) for a complete list of plotly.js-specific improvements.
68
* Support for **sf** (simple feature) data structures was added to `plot_ly()`, `plot_mapbox()`, and `plot_geo()` (via the new `add_sf()` function). See [this blog post](https://blog.cpsievert.me/2018/03/30/visualizing-geo-spatial-data-with-sf-and-plotly) for an overview.
7-
* New "special `plot_ly()` arguments" (`stroke`, `strokes`, `alpha_stroke`, `span`, and `spans`) were added for easier control over the stroke (i.e., outline) appearance of various filled graphical marks. For an overview, see the **sf** blog post linked to in the bullet point above and the new package demos (list all demos with `demo(package = "plotly")`).
8-
* The new `partial_bundle()` function makes it easy to leverage [partial bundles of plotly.js](https://github.com/plotly/plotly.js#partial-bundles) for reduced file sizes and faster render times.
9-
* The `config()` function gains a `locale` argument for easily changing localization defaults (see #1270). This makes it possible localize date axes, and in some cases, modebar buttons (see #1270)
9+
* Better control over the stroke (i.e., outline) appearance of various filled graphical marks via the new "special arguments" (`stroke`, `strokes`, `alpha_stroke`, `span`, and `spans`). For an overview, see the **sf** blog post linked to in the bullet point above and the new package demos (list all demos with `demo(package = "plotly")`).
10+
11+
### `ggplotly()` specific improvements
12+
13+
* `ggplotly()` now supports conversion of **ggplot2**'s `geom_sf()`.
1014
* One may now inform `ggplotly()` about the relevant **shiny** output size via `session$clientData`. This ensures `ggplotly()` sizing is closer to **ggplot2** sizing, even on window resize. For an example, run `plotly_example("shiny", "ggplotly_sizing")`.
11-
* Instead of an error, `ggplotly(NULL, "message")` and `plotly_build(NULL, "message")` now returns `htmltools::div("message")`, making it easier to relay messages in shiny when data isn't yet ready to plot (see #1116)
15+
16+
### Other improvements relevant for all **plotly** objects
17+
1218
* The selection (i.e., linked-brushing) mode can now switch from 'transient' to 'persistent' by holding the 'shift' key. It's still possible to _force_ persistent selection by setting `persistent = TRUE` in `highlight()`, but `persistent = FALSE` (the default) is now recommended since it allows one to switch between [persistent/transient selection](https://plotly-book.cpsievert.me/linking-views-without-shiny.html#transient-versus-persistent-selection) in the browser, rather than at the command line.
13-
* The `highlight()` function gains a `debounce` argument for throttling the rate at which `on` events may be fired. This is mainly useful for improving user experience when `highlight(on = "plotly_hover")` and mousing over relevant markers at a rapid rate (see #1277)
14-
* The `animation_button()` function gains a `label` argument, making it easier to control the label of an animation button generated through the `frame` API (see #1205).
19+
* The `highlight()` function gains a `debounce` argument for throttling the rate at which `on` events may be fired. This is mainly useful for improving user experience when `highlight(on = "plotly_hover")` and mousing over relevant markers at a rapid rate (#1277)
20+
* The new `partial_bundle()` function makes it easy to leverage [partial bundles of plotly.js](https://github.com/plotly/plotly.js#partial-bundles) for reduced file sizes and faster render times.
21+
* The `config()` function gains a `locale` argument for easily changing localization defaults (#1270). This makes it possible localize date axes, and in some cases, modebar buttons (#1270).
22+
* Instead of an error, `ggplotly(NULL, "message")` and `plotly_build(NULL, "message")` now returns `htmltools::div("message")`, making it easier to relay messages in shiny when data isn't yet ready to plot (#1116).
23+
* The `animation_button()` function gains a `label` argument, making it easier to control the label of an animation button generated through the `frame` API (#1205).
24+
* Support for async rendering of inside **shiny** apps using the [promises](https://rstudio.github.io/promises/) package (#1209).
1525

1626
## CHANGES
1727

28+
### `plot_ly()` specific changes
29+
1830
* The `name` attribute is now a "special `plot_ly()` argument" and behaves similar to `split` (it ensures a different trace for every unique value supplied). Although this leads to a breaking change (`name` was previously appended to an automatically generated trace name), it leads to a more flexible and transparent API. Those that wish to have the old behavior back should provide relevant mappings to the `name` attributes (e.g. `plot_ly(mtcars, x = ~wt, y = ~mpg, color = ~factor(vs), name = "a")` should become `plot_ly(mtcars, x = ~wt, y = ~mpg, color = ~factor(vs), name = ~paste(vs, "\na"))`)
1931
* The `color` argument now maps to `fillcolor`, making it much easier to use polygon fills to encode data values (e.g., choropleth maps). For backwards-compatibilty reasons, when `color` maps to `fillcolor`, `alpha` defaults to 0.5 (instead of 1). For an example, `plot_mapbox(mn_res, color = ~INDRESNAME)` or `plot_mapbox(mn_res, split = ~INDRESNAME, color = ~AREA, showlegend = FALSE, stroke = I("black"))`.
2032
* The `color` argument no longer automatically add `"markers"` to the `mode` attribute for scatter/scattergl trace types. Those who wish to have the old behavior back, should add `"markers"` to the `mode` explicity (e.g., change `plot_ly(economics, x = ~pce, y = ~pop, color = ~as.numeric(date), mode = "lines")` to `plot_ly(economics, x = ~pce, y = ~pop, color = ~as.numeric(date), mode = "lines+markers")`).
2133
* The `size` argument now informs a default [error_[x/y].width](https://plot.ly/r/reference/#scatter-error_x-width) (and `span` informs [error_[x/y].thickness](https://plot.ly/r/reference/#scatter-error_x-thickness)). Note you can override the default by specifying directly (e.g. `plot_ly(x = 1:10, y = 1:10, size = I(10), error_x = list(value = 5, width = 0))`).
2234
* `layout.showlegend` now defaults to `TRUE` for a *single* pie trace. This is a more sensible default and matches pure plotly.js behavior.
23-
* The `elementId` field is no longer populated, which fixes the "Ignoring explicitly provided widget ID" warning in shiny applications (see #985).
35+
36+
### Other changes relevant for all **plotly** objects
37+
38+
* The `elementId` field is no longer populated, which fixes the "Ignoring explicitly provided widget ID" warning in shiny applications (#985).
2439

2540
## BUG FIXES
2641

42+
### `ggplotly()` specific fixes
2743

2844
* The default `height`/`width` that `ggplotly()` assumes is now more consistently correct in various context, but it also now requires access to one of the following devices: `Cairo::Cairo()`, `png()`, or `jpg()`.
29-
* In RStudio, `ggplotly()` was ignoring a specified `height`/`width` (see #1190).
30-
* `ggplotly()` now uses fixed heights for facet strips meaning that their height is still correct after a window resize (see #1265).
31-
* Bug fix for linking views with crosstalk where the source of the selection is an aggregated trace (see #1218).
32-
* Fixed algorithm for coercing the proposed layout to the plot schema (see #1156).
33-
* `add_*()` no longer inherits `crosstalk::SharedData` key information when `inherit = FALSE` (see #1242).
34-
* The `limits` argument of `colorbar()` wasn't being applied to `line.color`/`line.cmin`/`line.cmax` (see #1236).
45+
* In RStudio, `ggplotly()` was ignoring a specified `height`/`width` (#1190).
46+
* `ggplotly()` now uses fixed heights for facet strips meaning that their height is still correct after a window resize (#1265).
47+
48+
### `plot_ly()` specific fixes
49+
50+
* The `limits` argument of `colorbar()` wasn't being applied to `line.color`/`line.cmin`/`line.cmax` (#1236).
51+
52+
### Other fixes relevant for all **plotly** objects
53+
54+
* Bug fix for linking views with crosstalk where the source of the selection is an aggregated trace (#1218).
55+
* Fixed algorithm for coercing the proposed layout to the plot schema (#1156).
56+
* `add_*()` no longer inherits `crosstalk::SharedData` key information when `inherit = FALSE` (#1242).
57+
58+
3559

3660
# 4.7.1
3761

R/highlight.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@
4343
#' @param opacityDim a number between 0 and 1 used to reduce the
4444
#' opacity of non-selected traces (by multiplying with the existing opacity).
4545
#' @param selected attributes of the selection, see [attrs_selected()].
46-
#' @param debounce amount of time to wait before firing an event (in milliseconds).
47-
#' This is especially useful when `on = "plotly_hover"` to avoid firing too many events
46+
#' @param debounce amount of time to wait before firing an event (in milliseconds).
47+
#' The default of 0 means do not debounce at all.
48+
#' Debouncing is mainly useful when `on = "plotly_hover"` to avoid firing too many events
4849
#' when users clickly move the mouse over relevant graphical marks.
4950
#' @param ... currently not supported.
5051
#' @export
@@ -83,7 +84,7 @@ highlight <- function(p, on = "plotly_click", off,
8384
dynamic = FALSE, color = NULL,
8485
selectize = FALSE, defaultValues = NULL,
8586
opacityDim = getOption("opacityDim", 0.2),
86-
selected = attrs_selected(), debounce = 1,
87+
selected = attrs_selected(), debounce = 0,
8788
...) {
8889

8990
# currently ... is not-supported and will catch

R/layers2traces.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ to_basic.GeomRect <- function(data, prestats_data, layout, params, p, ...) {
273273
#' @export
274274
to_basic.GeomSf <- function(data, prestats_data, layout, params, p, ...) {
275275

276-
data <- sf::st_as_sf(data)
276+
data[["geometry"]] <- sf::st_sfc(data[["geometry"]])
277+
data <- sf::st_as_sf(data, sf_column_name = "geometry")
277278
geom_type <- sf::st_geometry_type(data)
278279
# st_cast should "expand" a collection into multiple rows (one per feature)
279280
if ("GEOMETRYCOLLECTION" %in% geom_type) {

inst/htmlwidgets/plotly.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,10 @@ HTMLWidgets.widget({
471471
}
472472
}
473473
};
474-
475-
graphDiv.on(x.highlight.on, debounce(turnOn, x.highlight.debounce));
474+
if (x.highlight.debounce > 0) {
475+
turnOn = debounce(turnOn, x.highlight.debounce);
476+
}
477+
graphDiv.on(x.highlight.on, turnOn);
476478

477479
graphDiv.on(x.highlight.off, function turnOff(e) {
478480
// remove any visual clues

man/highlight.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plot_ly.Rd

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-animate-highlight.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,21 @@ test_that("animation button can be customized", {
368368
expect_true(menu$font$color == "white")
369369
expect_true(menu$buttons[[1]]$label == "Custom")
370370
})
371+
372+
373+
test_that("sf works with crosstalk", {
374+
skip_if_not_installed("sf")
375+
376+
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"))
377+
# shared data will make the polygons "query-able"
378+
ncsd <- SharedData$new(nc)
379+
p <- ggplot(ncsd) +
380+
geom_sf(aes(fill = AREA, text = paste0(NAME, "\n", "FIPS: ", FIPS))) +
381+
ggthemes::theme_map()
382+
gg <- ggplotly(p, tooltip = "text")
383+
d <- gg$x$data
384+
for (i in seq_along(d)) {
385+
expect_false(is.null(d[[i]]$key))
386+
expect_false(is.null(d[[i]]$set))
387+
}
388+
})

0 commit comments

Comments
 (0)