Neighbor highlighting via mouseover and click at the same time
1 |
#' Animate
|
|
2 |
#'
|
|
3 |
#' Animate graph components.
|
|
4 |
#'
|
|
5 |
#' @param sg An object of class \code{sigmajs}as intatiated by \code{\link{sigmajs}}.
|
|
6 |
#' @param mapping Variables to map animation to.
|
|
7 |
#' @param options Animations options.
|
|
8 |
#' @param delay Delay in milliseconds before animation is triggered.
|
|
9 |
#'
|
|
10 |
#' @details You can animate, \code{x}, \code{y}, \code{size} and \code{color}.
|
|
11 |
#'
|
|
12 |
#' @examples
|
|
13 |
#' # generate graph
|
|
14 |
#' nodes <- sg_make_nodes(20)
|
|
15 |
#' edges <- sg_make_edges(nodes, 30)
|
|
16 |
#'
|
|
17 |
#' # add transition
|
|
18 |
#' n <- nrow(nodes)
|
|
19 |
#' nodes$to_x <- runif(n, 5, 10)
|
|
20 |
#' nodes$to_y <- runif(n, 5, 10)
|
|
21 |
#' nodes$to_size <- runif(n, 5, 10)
|
|
22 |
#'
|
|
23 |
#' sigmajs() %>%
|
|
24 |
#' sg_nodes(nodes, id, label, size, color, to_x, to_y, to_size) %>%
|
|
25 |
#' sg_edges(edges, id, source, target) %>%
|
|
26 |
#' sg_animate(mapping = list(x = "to_x", y = "to_y", size = "to_size"))
|
|
27 |
#'
|
|
28 |
#' @seealso \href{https://github.com/jacomyal/sigma.js/tree/master/plugins/sigma.plugins.animate}{official documentation}
|
|
29 |
#'
|
|
30 |
#' @return An object of class \code{htmlwidget} which renders the visualisation on print.
|
|
31 |
#'
|
|
32 |
#' @rdname animation
|
|
33 |
#' @export
|
|
34 |
sg_animate <- function(sg, mapping, options = list(easing = "cubicInOut"), delay = 5000) { |
|
35 |
|
|
36 | 1 |
if (missing(sg) || missing(mapping)) |
37 | 1 |
stop("missing sg or mapping", call. = FALSE) |
38 |
|
|
39 | 1 |
.test_sg(sg) |
40 |
|
|
41 | 1 |
sg$x$animateLoop <- FALSE |
42 | 1 |
sg$x$animateOptions <- options |
43 | 1 |
sg$x$animateMapping <- mapping |
44 | 1 |
sg$x$animateDelay <- delay |
45 |
|
|
46 | 1 |
sg |
47 |
}
|
Read our documentation on viewing source code .