Skip to content

Commit

Permalink
Merge pull request #561 from JohnCoene/formatterJS
Browse files Browse the repository at this point in the history
feat: ✨ add possibility to Whether to wrap pure JS functions…
  • Loading branch information
munoztd0 authored Aug 22, 2023
2 parents 16a6fa1 + 3f48a22 commit 2ee457a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 13 additions & 1 deletion R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ e_aria <- function(e, enabled = TRUE, ...) {
#' @inheritParams e_bar
#' @param json Whether to return the JSON, otherwise returns a \code{list}.
#' @param txt JSON character string, url, or file.
#' @param jswrapper Whether to wrap pure JS functions in \code{htmlwidgets::JS}, Default is FALSE.
#' @param ... Additional options to pass to \link[=jsonlite]{toJSON}.
#'
#' @details \code{txt} should contain the full list of options required to build a chart.
Expand Down Expand Up @@ -348,10 +349,21 @@ e_inspect <- function(e, json = FALSE, ...) {

#' @rdname echartsNJSON
#' @export
echarts_from_json <- function(txt) {
echarts_from_json <- function(txt, jswrapper = FALSE) {
json <- jsonlite::fromJSON(txt, simplifyVector = FALSE)

e_charts() -> e
e$x$opts <- json
if (isTRUE(jswrapper)) {
for (i in seq_along(e$x$opts$tooltip)) {

if (is.character(e$x$opts$tooltip[[i]]) && startsWith(e$x$opts$tooltip[[i]], "function")) {
# Wrap pure JS functions in htmlwidgets::JS
e$x$opts$tooltip[[i]] <- htmlwidgets::JS(e$x$opts$tooltip[[i]])
}

}
}

e
}
4 changes: 3 additions & 1 deletion man/echartsNJSON.Rd

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

0 comments on commit 2ee457a

Please sign in to comment.