Skip to content

Upgrade plotly.js to 1.52 #1695

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

Merged
merged 8 commits into from
Feb 6, 2020
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 4.9.1.9000

## Changes to plotly.js

* This version of the R package upgrades the version of the underlying plotly.js library from v1.49.4 to v1.52.2. The [plotly.js release page](https://github.com/plotly/plotly.js/releases) has the full list of changes.

## BUG FIXES

* `add_sf()`/`geom_sf()` now correctly handle geometry columns that are named something other than `"geometry"` (#1659).

# 4.9.1

## Changes to plotly.js
Expand Down
39 changes: 38 additions & 1 deletion R/add.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ add_data <- function(p, data = NULL) {
#' @inheritParams plot_ly
#' @param p a plotly object
#' @param inherit inherit attributes from [plot_ly()]?
#' @param z a numeric matrix
#' @param z a numeric matrix (unless [add_image()], which wants a raster object, see [as.raster()]).
#' @param x the x variable.
#' @param y the y variable.
#' @param text textual labels.
Expand Down Expand Up @@ -393,6 +393,43 @@ add_ribbons <- function(p, x = NULL, ymin = NULL, ymax = NULL, ...,
)
}

#' @inheritParams add_trace
#' @rdname add_trace
#' @param colormodel Sets the colormodel for image traces if `z` is not a raster object.
#' If `z` is a raster object (see [as.raster()]), the `'rgba'` colormodel is always used.
#' @export
add_image <- function(p, z = NULL, colormodel = NULL, ..., data = NULL, inherit = TRUE) {

if (inherit) {
z <- z %||% p$x$attrs[[1]][["z"]]
colormodel <- colormodel %||% p$x$attrs[[1]][["colormodel"]]
}

if (inherits(z, "raster")) {
cols <- col2rgb(z, alpha = TRUE)
dims <- c(dim(z), 4)
z <- array(numeric(prod(dims)), dims)
matrix_ <- function(x) {
matrix(x, byrow = TRUE, nrow = dims[1], ncol = dims[2])
}
z[,,1] <- matrix_(cols["red",])
z[,,2] <- matrix_(cols["green",])
z[,,3] <- matrix_(cols["blue",])
z[,,4] <- matrix_(cols["alpha",])

# Throw if we detect another colormodel
if (!identical(colormodel %||% "rgba", "rgba")) {
warning("Passing a raster object to z requires rgba colormodel")
}
colormodel <- "rgba"
}

add_trace(
p, z = z, colormodel = colormodel, ...,
data = data, type = "image"
)
}

#' @inheritParams add_trace
#' @rdname add_trace
#' @param r For polar chart only. Sets the radial coordinates.
Expand Down
7 changes: 3 additions & 4 deletions R/layers2traces.R
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,14 @@ to_basic.GeomRect <- function(data, prestats_data, layout, params, p, ...) {

#' @export
to_basic.GeomSf <- function(data, prestats_data, layout, params, p, ...) {

data[["geometry"]] <- sf::st_sfc(data[["geometry"]])
data <- sf::st_as_sf(data, sf_column_name = "geometry")

data <- sf::st_as_sf(data)
geom_type <- sf::st_geometry_type(data)
# st_cast should "expand" a collection into multiple rows (one per feature)
if ("GEOMETRYCOLLECTION" %in% geom_type) {
data <- sf::st_cast(data)
geom_type <- sf::st_geometry_type(data)
}
data <- remove_class(data, "sf")

basic_type <- dplyr::recode(
as.character(geom_type),
Expand Down Expand Up @@ -310,6 +308,7 @@ to_basic.GeomSf <- function(data, prestats_data, layout, params, p, ...) {
d[[i]] <- prefix_class(
fortify_sf(d[[i]]), c(names(d)[[i]], "GeomSf")
)
d[[i]] <- remove_class(d[[i]], "sf")
}
if (length(d) == 1) d[[1]] else d
}
Expand Down
22 changes: 21 additions & 1 deletion R/plotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,15 @@ as_widget <- function(x, ...) {
),
preRenderHook = plotly_build,
dependencies = c(
# phantomjs doesn't support Object.setPrototypeOf() and a
# plotly.js dependency (buffer) uses it to detect TypedArray support.
# Thus, we add a polyfill if this is running in shinytest, but otherwise
# we shouldn't need it because Object.setPrototypeOf() is pretty widely supported
# https://github.com/plotly/plotly.js/issues/4556#issuecomment-583061419
# https://caniuse.com/#search=setPrototypeOf
if (isTRUE(getOption("shiny.testmode"))) {
list(setPrototypeOfPolyfill())
},
list(typedArrayPolyfill()),
crosstalk::crosstalkLibs(),
list(plotlyHtmlwidgetsCSS()),
Expand All @@ -432,6 +441,17 @@ as_widget <- function(x, ...) {
)
}

setPrototypeOfPolyfill <- function() {
htmltools::htmlDependency(
name = "setprototypeof",
version = "0.1",
package = "plotly",
src = dependency_dir("setprototypeof"),
script = "setprototypeof.js",
all_files = FALSE
)
}

typedArrayPolyfill <- function() {
htmltools::htmlDependency(
name = "typedarray",
Expand All @@ -446,7 +466,7 @@ typedArrayPolyfill <- function() {
plotlyMainBundle <- function() {
htmltools::htmlDependency(
name = "plotly-main",
version = "1.49.4",
version = "1.52.2",
package = "plotly",
src = dependency_dir("plotlyjs"),
script = "plotly-latest.min.js",
Expand Down
2 changes: 1 addition & 1 deletion R/plotly_build.R
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ coerce_attr_defaults <- function(trace, layout) {
if (length(trace[["stroke"]]) && !is.default(trace[["stroke"]])) {
trace$span <- trace[["span"]] %||% default(I(1))
}
if (trace[["type"]] %in% c("sunburst", "pie")) {
if (trace[["type"]] %in% c("sunburst", "pie", "treemap")) {
# As of v1.46.1, paper_bgcolor defaults to '#fff' which
# col2rgb() can't parse, but expands to '#ffffff'
# https://stackoverflow.com/a/2899224/1583084
Expand Down
2 changes: 1 addition & 1 deletion R/sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fortify_sf <- function(model, ...) {
# the coordinate belongs; for POINT this is absent (each coordinate is a feature),
# for LINESTRING L1 refers to the feature, for MULTIPOLYGON L1 refers to the main
# ring or holes, L2 to the ring id in the MULTIPOLYGON, and L3 to the simple feature.
coords <- sf::st_coordinates(model$geometry)
coords <- sf::st_coordinates(sf::st_geometry(model))
colnames(coords) <- tolower(colnames(coords))
lcols <- grep("^l", colnames(coords))

Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
1 change: 1 addition & 0 deletions inst/docker/Dockerfile.vtest
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ RUN R -e "install.packages('assertthat')"
RUN R -e "install.packages('testthat')"
ARG CRANCACHE=1
RUN R -e "update.packages(ask=FALSE)"
RUN R -e "remotes::install_github('r-lib/vdiffr')"

# install any new dependencies, then either manage cases (the default) or run tests
# note the workaround to get docker to run a proper exit status when there are testthat errors
Expand Down
21 changes: 17 additions & 4 deletions inst/examples/shiny/event_data/tests/mytest-expected/001.json
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,19 @@

],
"deps": [
{
"name": "setprototypeof",
"version": "0.1",
"src": {
"href": "setprototypeof-0.1"
},
"meta": null,
"script": "setprototypeof.js",
"stylesheet": null,
"head": null,
"attachment": null,
"all_files": false
},
{
"name": "typedarray",
"version": "0.1",
Expand Down Expand Up @@ -428,9 +441,9 @@
},
{
"name": "plotly-htmlwidgets-css",
"version": "1.49.4",
"version": "1.52.2",
"src": {
"href": "plotly-htmlwidgets-css-1.49.4"
"href": "plotly-htmlwidgets-css-1.52.2"
},
"meta": null,
"script": null,
Expand All @@ -441,9 +454,9 @@
},
{
"name": "plotly-main",
"version": "1.49.4",
"version": "1.52.2",
"src": {
"href": "plotly-main-1.49.4"
"href": "plotly-main-1.52.2"
},
"meta": null,
"script": "plotly-latest.min.js",
Expand Down
21 changes: 17 additions & 4 deletions inst/examples/shiny/event_data/tests/mytest-expected/002.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,19 @@

],
"deps": [
{
"name": "setprototypeof",
"version": "0.1",
"src": {
"href": "setprototypeof-0.1"
},
"meta": null,
"script": "setprototypeof.js",
"stylesheet": null,
"head": null,
"attachment": null,
"all_files": false
},
{
"name": "typedarray",
"version": "0.1",
Expand Down Expand Up @@ -445,9 +458,9 @@
},
{
"name": "plotly-htmlwidgets-css",
"version": "1.49.4",
"version": "1.52.2",
"src": {
"href": "plotly-htmlwidgets-css-1.49.4"
"href": "plotly-htmlwidgets-css-1.52.2"
},
"meta": null,
"script": null,
Expand All @@ -458,9 +471,9 @@
},
{
"name": "plotly-main",
"version": "1.49.4",
"version": "1.52.2",
"src": {
"href": "plotly-main-1.49.4"
"href": "plotly-main-1.52.2"
},
"meta": null,
"script": "plotly-latest.min.js",
Expand Down
21 changes: 17 additions & 4 deletions inst/examples/shiny/event_data/tests/mytest-expected/003.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,19 @@

],
"deps": [
{
"name": "setprototypeof",
"version": "0.1",
"src": {
"href": "setprototypeof-0.1"
},
"meta": null,
"script": "setprototypeof.js",
"stylesheet": null,
"head": null,
"attachment": null,
"all_files": false
},
{
"name": "typedarray",
"version": "0.1",
Expand Down Expand Up @@ -449,9 +462,9 @@
},
{
"name": "plotly-htmlwidgets-css",
"version": "1.49.4",
"version": "1.52.2",
"src": {
"href": "plotly-htmlwidgets-css-1.49.4"
"href": "plotly-htmlwidgets-css-1.52.2"
},
"meta": null,
"script": null,
Expand All @@ -462,9 +475,9 @@
},
{
"name": "plotly-main",
"version": "1.49.4",
"version": "1.52.2",
"src": {
"href": "plotly-main-1.49.4"
"href": "plotly-main-1.52.2"
},
"meta": null,
"script": "plotly-latest.min.js",
Expand Down
21 changes: 17 additions & 4 deletions inst/examples/shiny/event_data/tests/mytest-expected/004.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,19 @@

],
"deps": [
{
"name": "setprototypeof",
"version": "0.1",
"src": {
"href": "setprototypeof-0.1"
},
"meta": null,
"script": "setprototypeof.js",
"stylesheet": null,
"head": null,
"attachment": null,
"all_files": false
},
{
"name": "typedarray",
"version": "0.1",
Expand Down Expand Up @@ -450,9 +463,9 @@
},
{
"name": "plotly-htmlwidgets-css",
"version": "1.49.4",
"version": "1.52.2",
"src": {
"href": "plotly-htmlwidgets-css-1.49.4"
"href": "plotly-htmlwidgets-css-1.52.2"
},
"meta": null,
"script": null,
Expand All @@ -463,9 +476,9 @@
},
{
"name": "plotly-main",
"version": "1.49.4",
"version": "1.52.2",
"src": {
"href": "plotly-main-1.49.4"
"href": "plotly-main-1.52.2"
},
"meta": null,
"script": "plotly-latest.min.js",
Expand Down
2 changes: 1 addition & 1 deletion inst/htmlwidgets/lib/plotlyjs/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019 Plotly, Inc
Copyright (c) 2020 Plotly, Inc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion inst/htmlwidgets/lib/plotlyjs/locales/af.js

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

2 changes: 1 addition & 1 deletion inst/htmlwidgets/lib/plotlyjs/locales/am.js

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

2 changes: 1 addition & 1 deletion inst/htmlwidgets/lib/plotlyjs/locales/ar-dz.js

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

2 changes: 1 addition & 1 deletion inst/htmlwidgets/lib/plotlyjs/locales/ar-eg.js

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

Loading