1
#' No overlap
2
#'
3
#' This plugin runs an algorithm which distributes nodes in the network, ensuring that they do not overlap and providing a margin where specified.
4
#'
5
#' @param proxy An object of class \code{sigmajsProxy} as returned by \code{\link{sigmajsProxy}}.
6
#' @param sg An object of class \code{sigmajs}as intatiated by \code{\link{sigmajs}}.
7
#' @param nodeMargin The additional minimum space to apply around each and every node.
8
#' @param ... any option to pass to the plugin, see \href{https://github.com/jacomyal/sigma.js/tree/master/plugins/sigma.layout.noverlap}{official documentation}.
9
#'
10
#' @examples
11
#' nodes <- sg_make_nodes(500)
12
#' edges <- sg_make_edges(nodes)
13
#'
14
#' sigmajs() %>%
15
#'   sg_nodes(nodes, id, size, color) %>%
16
#'   sg_edges(edges, id, source, target) %>%
17
#'   sg_layout() %>% 
18
#'   sg_noverlap()
19
#' 
20
#' @return The first argument either \code{sg} or \code{proxy}.
21
#'
22
#' @rdname noverlap
23
#' @export
24
sg_noverlap <- function(sg, ...) {
25

26 1
	if (missing(sg))
27 1
		stop("missing sg", call. = FALSE)
28

29 1
	if (!inherits(sg, "sigmajs"))
30 1
		stop("sg must be of class sigmajs", call. = FALSE)
31

32 1
	sg$x$noverlap <- list(...)
33 1
	sg
34
}
35

36
#' @rdname noverlap
37
#' @export
38
sg_noverlap_p <- function(proxy, nodeMargin = 5, ...) {
39 0
	if (!"sigmajsProxy" %in% class(proxy))
40 0
		stop("must pass sigmajsProxy object", call. = FALSE)
41

42 0
	message <- list(id = proxy$id, config = list(nodeMargin = nodeMargin, ...)) # create message
43

44 0
	proxy$session$sendCustomMessage("sg_noverlap_p", message)
45

46 0
	return(proxy)
47
}

Read our documentation on viewing source code .

Loading