Skip to content
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

webshot2 #179

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Imports:
utils,
htmlwidgets,
rstudioapi,
webshot,
webshot2,
styler,
methods,
here,
Expand All @@ -30,7 +30,8 @@ Suggests:
rmarkdown,
esquisse,
tidyselect,
purrr
purrr,
webshot
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr
Expand Down
2 changes: 1 addition & 1 deletion R/03_0_flow_view.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#' can also be a vector of block ids, in this case `browser()` calls will be
#' inserted at the start of these blocks
#' @param out a path to save the diagram to.
#' Special values "html", "htm", "png", "pdf", "jpg" and "jpeg" can be used to
#' Special values "html", "htm", "png", "pdf", "jpg", "jpeg" and "webp" can be used to
#' export the object to a temp file of the relevant format and open it,
#' if a regular path is used the format will be guessed from the extension.
#' @param engine either `"nomnoml"` (default) or `"plantuml"` (experimental, brittle
Expand Down
15 changes: 12 additions & 3 deletions R/03_1_flow_view_nomnoml.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ print.flow_diagram <- function(x, ...) {
png <- tempfile("flow_", fileext = ".png")
html <- tempfile("flow_", fileext = ".html")
do.call(htmlwidgets::saveWidget, c(list(widget, html, FALSE)))
webshot::webshot(html, png, selector = "canvas")
if (isFALSE(getOption("flow.webshot2"))) {
webshot::webshot(html, png, selector = "canvas")
} else {
webshot2::webshot(html, png, selector = "canvas")
}

#FIXME: printing should return the input, but couldn't find another way here
return(knitr::include_graphics(png))
} else {
Expand Down Expand Up @@ -73,7 +78,7 @@ save_nomnoml <- function(code, out) {
}

## flag if out is a temp file shorthand
is_tmp <- out %in% c("html", "htm", "png", "pdf", "jpg", "jpeg")
is_tmp <- out %in% c("html", "htm", "png", "pdf", "jpg", "jpeg", "webp")

## is it ?
if (is_tmp) {
Expand All @@ -92,7 +97,11 @@ save_nomnoml <- function(code, out) {
## save to a temp html file then convert to required output
html <- tempfile("flow_", fileext = ".html")
do.call(htmlwidgets::saveWidget, c(list(widget, html)))
webshot::webshot(html, out, selector = "canvas")
if (isFALSE(getOption("flow.webshot2"))) {
webshot::webshot(html, out, selector = "canvas")
} else {
webshot2::webshot(html, out, selector = "canvas")
}
}

## was the out argument a temp file shorthand ?
Expand Down
8 changes: 6 additions & 2 deletions R/04_0_flow_run.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ flow_run <-
# hence the following call
nomnoml::nomnoml_validate()

is_tmp <- out %in% c("html", "htm", "png", "pdf", "jpg", "jpeg")
is_tmp <- out %in% c("html", "htm", "png", "pdf", "jpg", "jpeg", "webp")
if (is_tmp) {
out <- tempfile("flow_", fileext = paste0(".", out))
}
Expand All @@ -113,7 +113,11 @@ flow_run <-
} else {
html <- tempfile("flow_", fileext = ".html")
do.call(htmlwidgets::saveWidget, c(list(widget, html)))
webshot::webshot(html, out, selector = "canvas")
if (isFALSE(getOption("flow.webshot2"))) {
webshot::webshot(html, out, selector = "canvas")
} else {
webshot2::webshot(html, out, selector = "canvas")
}
}

if (is_tmp) {
Expand Down
2 changes: 1 addition & 1 deletion R/07_C.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ build_plantuml_code_from_c <- function(x, fun = NULL, out = NULL) {
}

## flag if out is a temp file shorthand
is_tmp <- out %in% c("html", "htm", "png", "pdf", "jpg", "jpeg")
is_tmp <- out %in% c("html", "htm", "png", "pdf", "jpg", "jpeg", "webp")

## is it ?
if (is_tmp) {
Expand Down
5 changes: 4 additions & 1 deletion R/12_flow_view_source_calls.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ extract_strings <- function(call) {
#' This evaluates the `file` argument of `source` in the global environment,
#' when this fails, as it might with constructs like `for (file in files) source(file)`
#' the unevaluated argument is printed instead between backticks. Since this messes
#' up the relationships in the graph, an warning is thus issued. In a case like `source(file.path(my_dir, "foo.R")`
#' up the relationships in the graph, an warning is thus issued. In a case like `source(file.path(my_dir, "foo.R"))`
#' defining `my_dir` will be enough to solve the issue.
#' In the latter case, if `smart` is `TRUE`, the function will check in all the paths in scope
#' if any script is named "foo.R" and will consider it if a single fitting candidate is found.
#'
#' `c(c(1)`
#' `c(c(1))`
#'
#' @param paths Paths to scripts or folders containing scripts
#' By default explores the working directory.
#' @param recursive Passed to `list.files()` when `paths` contains directories
Expand Down
13 changes: 13 additions & 0 deletions R/flow-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,16 @@
## usethis namespace: end
NULL

#' options for the 'flow' package
#'
#' * `flow.indenter`: To circumvent a limitation from nomnoml we use by default
#' the Braille character `"\u2800"` in places where consecutive standard
#' spaces would be ignored. On some systems it doesn't print nicely though,
#' `"\u00b7"` is another option that looks nice.
#' * `flow.svg`: Whether to use svg graphics in html or viewer output.
#' * `flow.webshot2`: Whether to use 'webshot2', set to `FALSE` to use 'webshot'
#' as was the default until version `0.2.0`.
#'
#' @aliases flow.indenter flow.svg flow.webshot2
#' @name flow-options
NULL
3 changes: 2 additions & 1 deletion R/zz.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ NULL
op <- options()
op.flow <- list(
flow.indenter = "\u2800",
flow.svg = TRUE
flow.svg = TRUE,
flow.webshot2 = TRUE
)
toset <- !(names(op.flow) %in% names(op))
if(any(toset)) options(op.flow[toset])
Expand Down
19 changes: 19 additions & 0 deletions man/flow-options.Rd

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

2 changes: 1 addition & 1 deletion man/flow_debug.Rd

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

2 changes: 1 addition & 1 deletion man/flow_view.Rd

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

2 changes: 1 addition & 1 deletion man/flow_view_deps.Rd

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

2 changes: 1 addition & 1 deletion man/flow_view_shiny.Rd

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

7 changes: 5 additions & 2 deletions man/flow_view_source_calls.Rd

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

2 changes: 1 addition & 1 deletion man/flow_view_uses.Rd

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

2 changes: 1 addition & 1 deletion man/flow_view_vars.Rd

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

Loading