Skip to content

Commit 81ed807

Browse files
committed
Create plotly.js bundle map programmatically
Creates the proper `bundleTraceMap` list as internal data object directly from the upstream JS file when updating plotly.js. This commit adds an updated `bundleTraceMap` for the currently used plotly.js v2.11.1 to `R/sysdata.rda`.
1 parent 16261c3 commit 81ed807

File tree

5 files changed

+26
-66
lines changed

5 files changed

+26
-66
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Description: Create interactive web graphics from 'ggplot2' graphs and/or a cust
2323
URL: https://plotly-r.com, https://github.com/plotly/plotly.R, https://plotly.com/r/
2424
BugReports: https://github.com/plotly/plotly.R/issues
2525
Depends:
26-
R (>= 3.2.0),
26+
R (>= 3.5),
2727
ggplot2 (>= 3.0.0)
2828
Imports:
2929
tools,
@@ -77,7 +77,7 @@ Suggests:
7777
reticulate,
7878
rsvg
7979
LazyData: true
80-
RoxygenNote: 7.2.3
80+
RoxygenNote: 7.3.1
8181
Encoding: UTF-8
8282
Roxygen: list(markdown = TRUE)
8383
Config/Needs/check:

R/partial_bundles.R

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ verify_partial_bundle <- function(p) {
8787

8888
if (identical(bundleType, "auto")) {
8989

90-
# resolve an auto bundle by using the 1st bundle that supports all the types
91-
# (ordering of bundleTraceMap is important!)
92-
for (i in seq_along(bundleTraceMap)) {
90+
# resolve an auto bundle by using the 1st bundle that supports all the types,
91+
# except for the 'strict' bundle (ordering of bundleTraceMap is important!)
92+
for (i in seq_along(bundleTraceMap[names(bundleTraceMap) != "strict"])) {
9393
if (all(types %in% bundleTraceMap[[i]])) {
9494
bundleType <- names(bundleTraceMap)[[i]]
9595
break
@@ -158,59 +158,3 @@ plotlyjsBundleIDX <- function(p) {
158158
plotlyjsBundle <- function(p) {
159159
p$dependencies[[plotlyjsBundleIDX(p)]]
160160
}
161-
162-
# TODO: create this object in inst/plotlyjs.R from the dist/README.md
163-
bundleTraceMap <- list(
164-
basic = c(
165-
"scatter",
166-
"bar",
167-
"pie"
168-
),
169-
cartesian = c(
170-
"scatter",
171-
"bar",
172-
"pie",
173-
"box",
174-
"heatmap",
175-
"histogram",
176-
"histogram2d",
177-
"histogram2dcontour",
178-
"contour",
179-
"scatterternary",
180-
"violin"
181-
),
182-
geo = c(
183-
"scatter",
184-
"scattergeo",
185-
"choropleth"
186-
),
187-
gl3d = c(
188-
"scatter",
189-
"scatter3d",
190-
"surface",
191-
"mesh3d",
192-
"cone"
193-
),
194-
gl2d = c(
195-
"scatter",
196-
"scattergl",
197-
"splom",
198-
"pointcloud",
199-
"heatmapgl",
200-
"contourgl",
201-
"parcoords"
202-
),
203-
mapbox = c(
204-
"scatter",
205-
"scattermapbox"
206-
),
207-
finance = c(
208-
"scatter",
209-
"bar",
210-
"pie",
211-
"histogram",
212-
"ohlc",
213-
"candlestick",
214-
"waterfall"
215-
)
216-
)

R/sysdata.rda

-73.1 KB
Binary file not shown.

tests/testthat/test-plotly-partial-bundles.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ test_that("Throws an informative error if wrong bundle is specified", {
4242

4343
expect_error(
4444
partial_bundle(p1, type = "basic"),
45-
"The 'basic' bundle supports the following trace types: 'scatter', 'bar', 'pie'"
45+
"The 'basic' bundle supports the following trace types: 'bar', 'pie', 'scatter'"
4646
)
4747
})
4848

tools/update_plotlyjs.R

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,28 @@ withr::with_dir(tmpdir, {
6565
file.path(lib_dir, "locales", sub("^plotly-locale-", "", basename(locales))),
6666
overwrite = TRUE
6767
)
68-
# update plot schema
68+
# update plot schema and (partial) bundles
69+
if (!nzchar(system.file(package = "yay"))) {
70+
stop("pkg 'yay' must be installed via: remotes::install_gitlab('rpkg.dev/yay')")
71+
}
6972
Schema <- jsonlite::fromJSON(Sys.glob("dist/plot-schema.json"))
73+
bundleTraceMap <-
74+
yay::gh_text_file(path = "tasks/util/constants.js",
75+
owner = "plotly",
76+
name = "plotly.js",
77+
rev = basename(zip)) |>
78+
stringr::str_extract(pattern = "(?<=var partialBundleTraces = )\\{[^}]+\\}") |>
79+
yaml::read_yaml(text = _)
80+
7081
withr::with_dir(
71-
pkg_dir, usethis::use_data(Schema, overwrite = TRUE, internal = TRUE)
82+
pkg_dir, usethis::use_data(
83+
Schema,
84+
bundleTraceMap,
85+
internal = TRUE,
86+
overwrite = TRUE,
87+
compress = "xz",
88+
version = 3L
89+
)
7290
)
7391

7492
# plotly.js used to bundle a typedarray polyfill to support older browsers,
@@ -81,7 +99,5 @@ withr::with_dir(tmpdir, {
8199
#)
82100

83101
message("Update plotlyMainBundle()'s version with ", basename(zip))
84-
85102
})
86-
87103
})

0 commit comments

Comments
 (0)