Skip to content

Commit

Permalink
patch plotly.js source to support phantomjs/shinytest
Browse files Browse the repository at this point in the history
reverts part of plotly/plotly.js#5380
  • Loading branch information
cpsievert committed Jun 21, 2021
1 parent d9c7ee0 commit cda64ad
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@
},
{
"name": "plotly-htmlwidgets-css",
"version": "1.57.1",
"version": "2.0.0",
"src": {
"href": "plotly-htmlwidgets-css-1.57.1"
"href": "plotly-htmlwidgets-css-2.0.0"
},
"meta": null,
"script": null,
Expand All @@ -452,9 +452,9 @@
},
{
"name": "plotly-main",
"version": "1.57.1",
"version": "2.0.0",
"src": {
"href": "plotly-main-1.57.1"
"href": "plotly-main-2.0.0"
},
"meta": null,
"script": "plotly-latest.min.js",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"plotly_afterplot-A": "\"plot\"",
"plotly_click-A": "[{\"curveNumber\":0,\"pointNumber\":7,\"x\":24.4,\"y\":3.19,\"customdata\":\"Merc 240D\"}]",
"plotly_hover-A": null,
"plotly_relayout-A": "{\"width\":962,\"height\":400}",
"plotType": "ggplotly"
},
"output": {
Expand Down Expand Up @@ -456,9 +457,9 @@
},
{
"name": "plotly-htmlwidgets-css",
"version": "1.57.1",
"version": "2.0.0",
"src": {
"href": "plotly-htmlwidgets-css-1.57.1"
"href": "plotly-htmlwidgets-css-2.0.0"
},
"meta": null,
"script": null,
Expand All @@ -469,9 +470,9 @@
},
{
"name": "plotly-main",
"version": "1.57.1",
"version": "2.0.0",
"src": {
"href": "plotly-main-1.57.1"
"href": "plotly-main-2.0.0"
},
"meta": null,
"script": "plotly-latest.min.js",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"plotly_brushing-A": "{\"x\":[23.95978500551268,25.98332414553473],\"y\":[3.0020072289156627,3.5073743975903615]}",
"plotly_click-A": "[{\"curveNumber\":0,\"pointNumber\":7,\"x\":24.4,\"y\":3.19,\"customdata\":\"Merc 240D\"}]",
"plotly_hover-A": null,
"plotly_relayout-A": "{\"width\":962,\"height\":400}",
"plotly_selected-A": "[{\"curveNumber\":0,\"pointNumber\":7,\"x\":24.4,\"y\":3.19,\"customdata\":\"Merc 240D\"}]",
"plotly_selecting-A": "[{\"curveNumber\":0,\"pointNumber\":7,\"x\":24.4,\"y\":3.19,\"customdata\":\"Merc 240D\"}]",
"plotType": "ggplotly"
Expand Down Expand Up @@ -460,9 +461,9 @@
},
{
"name": "plotly-htmlwidgets-css",
"version": "1.57.1",
"version": "2.0.0",
"src": {
"href": "plotly-htmlwidgets-css-1.57.1"
"href": "plotly-htmlwidgets-css-2.0.0"
},
"meta": null,
"script": null,
Expand All @@ -473,9 +474,9 @@
},
{
"name": "plotly-main",
"version": "1.57.1",
"version": "2.0.0",
"src": {
"href": "plotly-main-1.57.1"
"href": "plotly-main-2.0.0"
},
"meta": null,
"script": "plotly-latest.min.js",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"plotly_click-A": null,
"plotly_deselect-A": "\"plot\"",
"plotly_hover-A": null,
"plotly_relayout-A": "{\"width\":962,\"height\":400}",
"plotly_selected-A": null,
"plotly_selecting-A": null,
"plotType": "ggplotly"
Expand Down Expand Up @@ -461,9 +462,9 @@
},
{
"name": "plotly-htmlwidgets-css",
"version": "1.57.1",
"version": "2.0.0",
"src": {
"href": "plotly-htmlwidgets-css-1.57.1"
"href": "plotly-htmlwidgets-css-2.0.0"
},
"meta": null,
"script": null,
Expand All @@ -474,9 +475,9 @@
},
{
"name": "plotly-main",
"version": "1.57.1",
"version": "2.0.0",
"src": {
"href": "plotly-main-1.57.1"
"href": "plotly-main-2.0.0"
},
"meta": null,
"script": "plotly-latest.min.js",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 13 additions & 9 deletions inst/htmlwidgets/lib/plotlyjs/plotly-latest.min.js

Large diffs are not rendered by default.

62 changes: 0 additions & 62 deletions inst/plotlyjs.R

This file was deleted.

22 changes: 22 additions & 0 deletions tools/patches/001-revert-ie-fallbacks.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/src/lib/array.js b/src/lib/array.js
index 19463675a..470d3d6bf 100644
--- a/src/lib/array.js
+++ b/src/lib/array.js
@@ -2,8 +2,15 @@

var isArray = Array.isArray;

-var ab = ArrayBuffer;
-var dv = DataView;
+// IE9 fallbacks
+
+var ab = (typeof ArrayBuffer === 'undefined' || !ArrayBuffer.isView) ?
+ {isView: function() { return false; }} :
+ ArrayBuffer;
+
+var dv = (typeof DataView === 'undefined') ?
+ function() {} :
+ DataView;

function isTypedArray(a) {
return ab.isView(a) && !(a instanceof dv);
85 changes: 85 additions & 0 deletions tools/update_plotlyjs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
library(httr)
library(rprojroot)

# get zip URL to latest plotly.js release
x <- RETRY(
verb = "GET",
url = 'https://api.github.com/repos/plotly/plotly.js/releases/latest',
times = 5,
terminate_on = c(400, 401, 403, 404),
terminate_on_success = TRUE
)
zip <- 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")
patches <- list.files(
find_package_root_file("tools/patches"),
full.names = TRUE
)

# download, patch, and build plotly.js in temp dir
tmpdir <- tempfile()
dir.create(tmpdir)

withr::with_dir(tmpdir, {
# download source
download.file(zip, "plotly-js.zip")
unzip("plotly-js.zip", exdir = "plotly-js")

withr::with_dir(
dir("plotly-js", full.names = TRUE), {

# apply patches
for (patch in patches) {
tryCatch({
message(sprintf("Applying %s", basename(patch)))
system(sprintf("git apply %s", patch))
},
error = function(e) quit(save = "no", status = 1)
)
}

# build
system("yarn install")
system("yarn build")

# copy assets to R package source
file.copy(
"dist/plotly.min.js",
file.path(lib_dir, "plotly-latest.min.js"),
overwrite = TRUE
)
file.copy(
"LICENSE",
file.path(lib_dir, "LICENSE"),
overwrite = TRUE
)

locales <- Sys.glob("dist/plotly-locale-*.js")
file.copy(
locales,
file.path(lib_dir, "locales", sub("^plotly-locale-", "", basename(locales))),
overwrite = TRUE
)
# update plot schema
Schema <- jsonlite::fromJSON(Sys.glob("dist/plot-schema.json"))
withr::with_dir(
pkg_dir, usethis::use_data(Schema, overwrite = TRUE, internal = TRUE)
)

# plotly.js used to bundle a typedarray polyfill to support older browsers,
# but v2 drops support for them, so it no longer includes this polyfill
# Hopefully, we can continue to get away with using the pre-v2 polyfill
# to support shinytest/phantomjs
#download.file(
# "dist/extras/typedarray.min.js",
# "inst/htmlwidgets/lib/typedarray/typedarray.min.js"
#)

message("Update plotlyMainBundle()'s version with ", basename(zip))

})

})

0 comments on commit cda64ad

Please sign in to comment.