Skip to content

Commit

Permalink
deparse + button check on read family
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCoene committed Mar 8, 2019
1 parent 678ab49 commit b4bf78c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 34 deletions.
13 changes: 10 additions & 3 deletions R/graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,21 @@ 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){

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 %>%
Expand All @@ -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() %>%
Expand Down
18 changes: 13 additions & 5 deletions R/graph_proxies.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
#' })
#'
#' }
Expand All @@ -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 %>%
Expand All @@ -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) %>%
Expand Down
7 changes: 4 additions & 3 deletions man/read-batch.Rd

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

9 changes: 6 additions & 3 deletions man/read-static.Rd

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

47 changes: 27 additions & 20 deletions vignettes/buttons.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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.

0 comments on commit b4bf78c

Please sign in to comment.