diff --git a/R/graph.R b/R/graph.R index b332905..e3e353e 100644 --- a/R/graph.R +++ b/R/graph.R @@ -347,9 +347,12 @@ sg_drop_edges <- function(sg, data, ids, delay, cumsum = TRUE, refresh = FALSE) #' #' sigmajs() %>% #' sg_force_start() %>% -#' sg_read_nodes(nodes, id, label, color, size, delay = "batch") %>% -#' sg_read_edges(edges, id, source, target, delay = "batch") %>% -#' sg_read_exec() +#' sg_read_nodes(nodes, id, label, color, size, delay = batch) %>% +#' sg_read_edges(edges, id, source, target, delay = batch) %>% +#' sg_force_stop(4000) %>% +#' sg_read_exec() %>% +#' sg_button("read_exec", "Add nodes & edges") +#' #' @name read-static #' @export sg_read_nodes <- function(sg, data, ..., delay){ @@ -357,6 +360,8 @@ sg_read_nodes <- function(sg, data, ..., delay){ if (missing(sg) || missing(data) || missing(delay)) stop("must pass sg, data, and delay", call. = FALSE) + delay <- deparse(substitute(delay)) + .test_sg(sg) nodes <- data %>% @@ -379,6 +384,8 @@ sg_read_edges <- function(sg, data, ..., delay){ .test_sg(sg) + delay <- deparse(substitute(delay)) + edges <- data %>% .build_data(..., delay = delay) %>% .check_ids() %>% diff --git a/R/graph_proxies.R b/R/graph_proxies.R index 5e847c2..706e5fd 100644 --- a/R/graph_proxies.R +++ b/R/graph_proxies.R @@ -645,9 +645,10 @@ sg_read_exec_p <- function(proxy){ #' #' sigmajsProxy("sg") %>% #' sg_force_start_p() %>% -#' sg_read_delay_nodes_p(nodes, id, color, label, size, delay = "batch") %>% -#' sg_read_delay_edges_p(edges, id, source, target, delay = "batch") %>% -#' sg_read_delay_exec_p() +#' sg_read_delay_nodes_p(nodes, id, color, label, size, delay = batch) %>% +#' sg_read_delay_edges_p(edges, id, source, target, delay = batch) %>% +#' sg_read_delay_exec_p() %>% +#' sg_force_stop_p() #' }) #' #' } @@ -660,8 +661,10 @@ sg_read_delay_nodes_p <- function(proxy, data, ..., delay){ .test_proxy(proxy) - if(missing(delay)) - stop("missing delay", call. = FALSE) + if(missing(delay) || missing(data)) + stop("missing data or delay", call. = FALSE) + + delay <- deparse(substitute(delay)) # build data nodes <- data %>% @@ -681,6 +684,11 @@ sg_read_delay_nodes_p <- function(proxy, data, ..., delay){ sg_read_delay_edges_p <- function(proxy, data, ..., delay){ .test_proxy(proxy) + if(missing(delay) || missing(data)) + stop("missing data or delay", call. = FALSE) + + delay <- deparse(substitute(delay)) + # build data edges <- data %>% .build_data(..., delay = delay) %>% diff --git a/man/read-batch.Rd b/man/read-batch.Rd index a239a44..a82d197 100644 --- a/man/read-batch.Rd +++ b/man/read-batch.Rd @@ -68,9 +68,10 @@ server <- function(input, output, session){ sigmajsProxy("sg") \%>\% sg_force_start_p() \%>\% - sg_read_delay_nodes_p(nodes, id, color, label, size, delay = "batch") \%>\% - sg_read_delay_edges_p(edges, id, source, target, delay = "batch") \%>\% - sg_read_delay_exec_p() + sg_read_delay_nodes_p(nodes, id, color, label, size, delay = batch) \%>\% + sg_read_delay_edges_p(edges, id, source, target, delay = batch) \%>\% + sg_read_delay_exec_p() \%>\% + sg_force_stop_p() }) } diff --git a/man/read-static.Rd b/man/read-static.Rd index d6a33c6..ad9fd86 100644 --- a/man/read-static.Rd +++ b/man/read-static.Rd @@ -53,7 +53,10 @@ edges <- data.frame( sigmajs() \%>\% sg_force_start() \%>\% - sg_read_nodes(nodes, id, label, color, size, delay = "batch") \%>\% - sg_read_edges(edges, id, source, target, delay = "batch") \%>\% - sg_read_exec() + sg_read_nodes(nodes, id, label, color, size, delay = batch) \%>\% + sg_read_edges(edges, id, source, target, delay = batch) \%>\% + sg_force_stop(4000) \%>\% + sg_read_exec() \%>\% + sg_button("read_exec", "Add nodes & edges") + } diff --git a/vignettes/buttons.Rmd b/vignettes/buttons.Rmd index 2ef1c0d..e56ccaf 100644 --- a/vignettes/buttons.Rmd +++ b/vignettes/buttons.Rmd @@ -21,6 +21,30 @@ library(sigmajs) `sigmajs` lets you add buttons to trigger events, *in static documents*. +## All events + +Events that can be triggered via a button (corresponding function name minus `sg_`): + +* `force_start` +* `force_stop` +* `noverlap` +* `drag_nodes` +* `relative_size` +* `add_nodes` +* `add_edges` +* `add_nodes_edges` +* `drop_nodes` +* `drop_edges` +* `animate` +* `export_svg` +* `export_img` +* `progress` +* `read_exec` + +You will examples of the above scattered throughout the documentation. + +## Download + A button to export the graph as SVG, not that you can export to an image (png, jpeg, gif or tiff). ```{r} @@ -56,7 +80,9 @@ sigmajs() %>% ) ``` -Since version `1.1.2` you can add multiple buttons. +## Multiple buttons + +Since version `1.1.2` you can add multiple buttons, and a single button can trigger multiple events. ```{r} # initial nodes @@ -78,22 +104,3 @@ sigmajs() %>% sg_button(c("add_nodes", "progress"), "add", tag = tags$a, position = "bottom") %>% sg_button("force_start", "force", tag = tags$a, position = "bottom") ``` - -Events that can be triggered via a button (corresponding function name minus `sg_`): - -* `force_start` -* `force_stop` -* `noverlap` -* `drag_nodes` -* `relative_size` -* `add_nodes` -* `add_edges` -* `add_nodes_edges` -* `drop_nodes` -* `drop_edges` -* `animate` -* `export_svg` -* `export_img` -* `progress` - -You will examples of the above scattered throughout the documentation. \ No newline at end of file