1
#' Text
2
#' 
3
#' Add text to your graph.
4
#' 
5
#' @inheritParams sg_nodes
6
#' @param data Data.frame holding \code{delay} and \code{text}.
7
#' @param delay Delay, in milliseconds at which text should appear.
8
#' @param text Text to appear on graph.
9
#' @param tag A Valid \code{htmltools} tags function.
10
#' @param id A valid CSS id.
11
#' @param position Position of button, \code{top} or \code{bottom}.
12
#' @param ... Content of the button, complient with \code{htmltools}.
13
#' @param cumsum Whether to compute the cumulative sum on the \code{delay}.
14
#' 
15
#' @details The \code{element} is passed to \href{https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement}{Document.createElement()}
16
#' and therefore takes any valid \code{tagName}, including, but not limited to; \code{p}, \code{h1}, \code{div}.
17
#' 
18
#' @examples 
19
#' # initial nodes
20
#' nodes <- sg_make_nodes()
21
#' 
22
#' # additional nodes
23
#' nodes2 <- sg_make_nodes()
24
#' nodes2$id <- as.character(seq(11, 20))
25
#' 
26
#' # add delay
27
#' nodes2$delay <- runif(nrow(nodes2), 500, 1000)
28
#' nodes2$text <- seq.Date(Sys.Date(), Sys.Date() + 9, "days")
29
#' 
30
#' sigmajs() %>%
31
#'   sg_nodes(nodes, id, label, size, color) %>%
32
#'   sg_add_nodes(nodes2, delay, id, label, size, color) %>% 
33
#'   sg_progress(nodes2, delay, text, element = "h3") %>%
34
#'   sg_button(c("add_nodes", "progress"), "add") 
35
#' 
36
#' @return A modified version of the \code{sg} object.
37
#' 
38
#' @export
39
sg_progress <- function(sg, data, delay, text, ..., position = "top", id = NULL,
40
                        tag = htmltools::span, cumsum = TRUE){
41
  
42 0
  if(missing(data) || missing(delay) || missing(text))
43 0
    stop("missing data, delay or text")
44
  
45 0
  delay_col <- eval(substitute(delay), data) # subset delay
46 0
  if (isTRUE(cumsum))
47 0
    delay_col <- cumsum(delay_col) # cumul for setTimeout
48
  
49 0
  text <- eval(substitute(text), data) # subset ids
50 0
  data <- data.frame(delay = delay_col, text = text)
51
  
52 0
  if(is.null(id))
53 0
    id <- .make_rand_id()
54
  
55 0
  sg$x$progressBar <- list(
56 0
    id = id,
57 0
    position = position,
58 0
    data = apply(data, 1, as.list)
59
  )
60
  
61 0
  if(position == "top")
62 0
    htmlwidgets::prependContent(sg, tag(id = id, ...))
63
  else
64 0
    htmlwidgets::appendContent(sg, tag(id = id, ...))
65
}

Read our documentation on viewing source code .

Loading