diff --git a/DESCRIPTION b/DESCRIPTION index 7a79b8c68f..c01a872a17 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,7 +23,7 @@ Description: Create interactive web graphics from 'ggplot2' graphs and/or a cust URL: https://plotly-r.com, https://github.com/plotly/plotly.R, https://plotly.com/r/ BugReports: https://github.com/plotly/plotly.R/issues Depends: - R (>= 3.2.0), + R (>= 3.5), ggplot2 (>= 3.0.0) Imports: tools, diff --git a/NEWS.md b/NEWS.md index deae87ce4d..c2a83d079e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,8 @@ # plotly (development version) +## Improvements - +* Create the proper `bundleTraceMap` list as internal package data object directly from the upstream JS file when plotly.js is updated. As a consequence, it's now possible to use the [`strict` bundle](https://github.com/plotly/plotly.js/blob/master/dist/README.md#plotlyjs-strict) via `plotly::partial_bundle(type = "strict")`. # plotly 4.12.0 diff --git a/R/partial_bundles.R b/R/partial_bundles.R index fc7a66795e..def7b7bd62 100644 --- a/R/partial_bundles.R +++ b/R/partial_bundles.R @@ -87,9 +87,9 @@ verify_partial_bundle <- function(p) { if (identical(bundleType, "auto")) { - # resolve an auto bundle by using the 1st bundle that supports all the types - # (ordering of bundleTraceMap is important!) - for (i in seq_along(bundleTraceMap)) { + # resolve an auto bundle by using the 1st bundle that supports all the types, + # except for the 'strict' bundle (ordering of bundleTraceMap is important!) + for (i in seq_along(bundleTraceMap[names(bundleTraceMap) != "strict"])) { if (all(types %in% bundleTraceMap[[i]])) { bundleType <- names(bundleTraceMap)[[i]] break @@ -158,59 +158,3 @@ plotlyjsBundleIDX <- function(p) { plotlyjsBundle <- function(p) { p$dependencies[[plotlyjsBundleIDX(p)]] } - -# TODO: create this object in inst/plotlyjs.R from the dist/README.md -bundleTraceMap <- list( - basic = c( - "scatter", - "bar", - "pie" - ), - cartesian = c( - "scatter", - "bar", - "pie", - "box", - "heatmap", - "histogram", - "histogram2d", - "histogram2dcontour", - "contour", - "scatterternary", - "violin" - ), - geo = c( - "scatter", - "scattergeo", - "choropleth" - ), - gl3d = c( - "scatter", - "scatter3d", - "surface", - "mesh3d", - "cone" - ), - gl2d = c( - "scatter", - "scattergl", - "splom", - "pointcloud", - "heatmapgl", - "contourgl", - "parcoords" - ), - mapbox = c( - "scatter", - "scattermapbox" - ), - finance = c( - "scatter", - "bar", - "pie", - "histogram", - "ohlc", - "candlestick", - "waterfall" - ) -) diff --git a/R/sysdata.rda b/R/sysdata.rda index 529557367a..0e1f4a79c3 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/tests/testthat/test-plotly-partial-bundles.R b/tests/testthat/test-plotly-partial-bundles.R index ff6af2cc14..601ff64d07 100644 --- a/tests/testthat/test-plotly-partial-bundles.R +++ b/tests/testthat/test-plotly-partial-bundles.R @@ -42,7 +42,7 @@ test_that("Throws an informative error if wrong bundle is specified", { expect_error( partial_bundle(p1, type = "basic"), - "The 'basic' bundle supports the following trace types: 'scatter', 'bar', 'pie'" + "The 'basic' bundle supports the following trace types: 'bar', 'pie', 'scatter'" ) }) diff --git a/tools/update_plotlyjs.R b/tools/update_plotlyjs.R index ab27553fe6..312de73cd2 100644 --- a/tools/update_plotlyjs.R +++ b/tools/update_plotlyjs.R @@ -1,6 +1,3 @@ -library(httr) -library(rprojroot) - # Specify the version to update to (set to NULL for latest) PLOTLY_JS_VERSION <- "2.25.2" @@ -14,20 +11,20 @@ if (is.null(PLOTLY_JS_VERSION)) { ) } -x <- RETRY( +x <- httr::RETRY( verb = "GET", url = release_url, times = 5, terminate_on = c(400, 401, 403, 404), terminate_on_success = TRUE ) -zip <- content(x)$zipball_url +zip <- httr::content(x)$zipball_url # remember where to copy over assets -pkg_dir <- find_package_root_file() -lib_dir <- find_package_root_file("inst/htmlwidgets/lib/plotlyjs") +pkg_dir <- rprojroot::find_package_root_file() +lib_dir <- rprojroot::find_package_root_file("inst/htmlwidgets/lib/plotlyjs") patches <- list.files( - find_package_root_file("tools/patches"), + rprojroot::find_package_root_file("tools/patches"), full.names = TRUE ) @@ -37,8 +34,8 @@ dir.create(tmpdir) withr::with_dir(tmpdir, { # download source - download.file(zip, "plotly-js.zip") - unzip("plotly-js.zip", exdir = "plotly-js") + utils::download.file(zip, "plotly-js.zip") + utils::unzip("plotly-js.zip", exdir = "plotly-js") withr::with_dir( dir("plotly-js", full.names = TRUE), { @@ -77,10 +74,26 @@ withr::with_dir(tmpdir, { file.path(lib_dir, "locales", sub("^plotly-locale-", "", basename(locales))), overwrite = TRUE ) - # update plot schema - Schema <- jsonlite::fromJSON(Sys.glob("dist/plot-schema.json")) + # update plot schema and (partial) bundles + Schema <- jsonlite::fromJSON("dist/plot-schema.json") + bundleTraceMap <- + paste0(readLines("tasks/util/constants.js"), collapse = "\n") |> + stringr::str_extract(pattern = "(?<=\\b(const|var) partialBundleTraces = )\\{[^}]+\\}") + + if (is.na(bundleTraceMap)) { + stop("No `partialBundleTraces` variable definition found in Plotly source file `tasks/util/constants.js`. Does the regex pattern need an update?") + } + bundleTraceMap <- yaml::read_yaml(text = bundleTraceMap) + withr::with_dir( - pkg_dir, usethis::use_data(Schema, overwrite = TRUE, internal = TRUE) + pkg_dir, usethis::use_data( + Schema, + bundleTraceMap, + internal = TRUE, + overwrite = TRUE, + compress = "xz", + version = 3L + ) ) # plotly.js used to bundle a typedarray polyfill to support older browsers, @@ -96,5 +109,7 @@ withr::with_dir(tmpdir, { message("Update plotlyMainBundle()'s version to ", version) }) - }) + +# clean up +unlink(tmpdir, recursive = TRUE)