1
#' Highlight neighbours
2
#' 
3
#' Highlight node neighbours on click.
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
#' @param nodes,edges Color of nodes and edges
8
#' @param on The sigmajs event on which to trigger the neighbours highlighting.
9
#'   'clickNode' (default) means when a node is clicked on. 'overNode' means
10
#'   when mouse is hovering on a node. 'clickNode|overNode' means a combination
11
#'   of the two modes at the same time.
12
#' 
13
#' @examples 
14
#' nodes <- sg_make_nodes() 
15
#' edges <- sg_make_edges(nodes, 20)
16
#' 
17
#' sigmajs() %>% 
18
#'   sg_nodes(nodes, id, size, color) %>% 
19
#'   sg_edges(edges, id, source, target) %>% 
20
#'   sg_layout() %>% 
21
#'   sg_neighbours()
22
#' 
23
#' @return A modified version of the \code{sg} object.
24
#'
25
#' @rdname neighbours
26
#' @export
27
sg_neighbours <- function(sg, nodes = "#eee", edges = "#eee", on = c("clickNode", "overNode", "clickNode|overNode")){
28
  
29 1
  if(missing(sg))
30 1
    stop("must pass sg", call. = FALSE)
31
  
32 1
  if(!inherits(sg, "sigmajs"))
33 1
    stop("sg must be sigmajs object", call. = FALSE)
34
  
35 1
  on <- match.arg(on)
36

37 1
  sg$x$neighbours <- list(
38 1
    nodes = nodes,
39 1
    edges = edges,
40 1
    on = on
41
  )
42 1
  sg
43
}
44

45
#' @rdname neighbours
46
#' @export
47
sg_neighbors <- sg_neighbours
48

49
#' @rdname neighbours
50
#' @export
51
sg_neighbours_p <- function(proxy, nodes = "#eee", edges = "#eee", on = c("clickNode", "overNode", "clickNode|overNode")){
52

53 0
  .test_proxy(proxy)
54 0
  on <- match.arg(on)
55 0
  message <- list(id = proxy$id, nodes = nodes, edges = edges, on = on)
56

57 0
  proxy$session$sendCustomMessage("sg_neighbours_p", message)
58 0
  return(proxy)
59
}
60

61
#' @rdname neighbours
62
#' @export
63
sg_neighbors_p <- sg_neighbours_p

Read our documentation on viewing source code .

Loading