1
#' Drag nodes
2
#' 
3
#' Allow user to drag and drop nodes.
4
#'
5
#' @param sg An object of class \code{sigmajs}as intatiated by \code{\link{sigmajs}}.
6
#' @param proxy An object of class \code{sigmajsProxy} as returned by \code{\link{sigmajsProxy}}.
7
#'
8
#' @examples
9
#' # generate graph
10
#' nodes <- sg_make_nodes(20)
11
#' edges <- sg_make_edges(nodes, 35)
12
#'
13
#' sigmajs() %>%
14
#'   sg_nodes(nodes, id, label, size) %>%
15
#'   sg_edges(edges, id, source, target) %>%
16
#'   sg_drag_nodes()
17
#'
18
#' \dontrun{
19
#' # proxies
20
#' demo("drag-nodes", package = "sigmajs")
21
#' }
22
#' 
23
#' @return \code{sg_drag_nodes} An object of class \code{htmlwidget} which renders the visualisation on print.
24
#' While \code{sg_drag_nodes_start_p} and \code{sg_drag_nodes_kill_p}
25
#'
26
#' @rdname drag-nodes
27
#' @export
28
sg_drag_nodes <- function(sg) {
29

30 1
	if (missing(sg))
31 1
		stop("missing sg", call. = FALSE)
32

33 1
  .test_sg(sg)
34

35 1
  sg$x$dragNodes <- TRUE
36 1
  sg
37
}
38

39
#' @rdname drag-nodes
40
#' @export
41
sg_drag_nodes_start_p <- function(proxy) {
42

43 0
	if (missing(proxy))
44 0
		stop("missing proxy", call. = FALSE)
45

46 0
  .test_proxy(proxy)
47

48 0
	message <- list(id = proxy$id) # create message
49

50 0
	proxy$session$sendCustomMessage("sg_drag_nodes_start_p", message)
51
  
52 0
  proxy
53
}
54

55
#' @rdname drag-nodes
56
#' @export
57
sg_drag_nodes_kill_p <- function(proxy) {
58

59 0
	if (missing(proxy))
60 0
		stop("missing proxy", call. = FALSE)
61

62 0
  .test_proxy(proxy)
63

64 0
	message <- list(id = proxy$id) # create message
65

66 0
	proxy$session$sendCustomMessage("sg_drag_nodes_kill_p", message)
67 0
  proxy
68
}

Read our documentation on viewing source code .

Loading