Skip to content

Commit

Permalink
make e_charts a method so accepts Node fixes #207
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCoene committed Oct 29, 2020
1 parent 8f49947 commit 082e62c
Show file tree
Hide file tree
Showing 23 changed files with 1,024 additions and 819 deletions.
2 changes: 0 additions & 2 deletions CRAN-RELEASE

This file was deleted.

3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Suggests:
testthat,
knitr,
rmarkdown,
covr
covr,
data.tree
RoxygenNote: 7.1.1.9000
URL: https://echarts4r.john-coene.com/
BugReports: https://github.com/JohnCoene/echarts4r/issues/
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ S3method(e_boxplot,echarts4r)
S3method(e_boxplot,echarts4rProxy)
S3method(e_candle,echarts4r)
S3method(e_candle,echarts4rProxy)
S3method(e_charts,Node)
S3method(e_charts,default)
S3method(e_correlations,echarts4r)
S3method(e_correlations,echarts4rProxy)
S3method(e_density,echarts4r)
Expand Down
24 changes: 22 additions & 2 deletions R/echarts4r.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ echarts_build <- function(e) {
#' @name init
#' @export
e_charts <- function(data, x, width = NULL, height = NULL, elementId = NULL, dispose = TRUE,
draw = TRUE, renderer = "canvas", timeline = FALSE, ..., reorder = TRUE) {
draw = TRUE, renderer = "canvas", timeline = FALSE, ..., reorder = TRUE) UseMethod("e_charts")

#' @rdname init
#' @export
e_charts.default <- function(data, x, width = NULL, height = NULL, elementId = NULL, dispose = TRUE,
draw = TRUE, renderer = "canvas", timeline = FALSE, ..., reorder = TRUE) {
xmap <- NULL

if (!missing(x)) {
Expand Down Expand Up @@ -200,10 +205,25 @@ e_charts <- function(data, x, width = NULL, height = NULL, elementId = NULL, dis
return(widget)
}

#' @rdname init
#' @method e_charts Node
#' @export
e_charts.Node <- function(data, x, width = NULL, height = NULL, elementId = NULL, dispose = TRUE,
draw = TRUE, renderer = "canvas", timeline = FALSE, ..., reorder = TRUE){

check_installed("data.tree")

json <- data.tree::ToListExplicit(data, unname=TRUE)
data <- json$children[[1]]$children

e_charts(data, x, width = width, height = height, elementId = elementId, dispose = dispose,
draw = draw, renderer = renderer, timeline = timeline, ..., reorder = reorder)
}

#' @rdname init
#' @export
e_charts_ <- function(data, x = NULL, width = NULL, height = NULL, elementId = NULL, dispose = TRUE,
draw = TRUE, renderer = "canvas", timeline = FALSE, ..., reorder = TRUE) {
draw = TRUE, renderer = "canvas", timeline = FALSE, ..., reorder = TRUE) {
xmap <- x

# forward options using x
Expand Down
7 changes: 7 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -717,3 +717,10 @@ globalVariables(c("x", "e", ".", "acc", "epoch", "loss", "size", "val_acc", "val
}
return(list(max = max, min = min))
}

check_installed <- function(pkg){
has_it <- base::requireNamespace(pkg, quietly = TRUE)

if(!has_it)
stop(sprintf("This function requires the package {%s}", pkg), call. = FALSE)
}
Binary file added docs/reference/Rplot001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 39 additions & 31 deletions docs/reference/axis3d.html

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

Loading

0 comments on commit 082e62c

Please sign in to comment.