Neighbor highlighting via mouseover and click at the same time
1 |
#' Add a camera
|
|
2 |
#'
|
|
3 |
#' Add a camera to your graph.
|
|
4 |
#'
|
|
5 |
#' @param sg An object of class \code{sigmajs}as intatiated by \code{\link{sigmajs}}.
|
|
6 |
#' @param elementId Id of graph that initialised the camera.
|
|
7 |
#' @param initialise Whether to initialise the camera.
|
|
8 |
#'
|
|
9 |
#' @note Cameras should only be initialised once.
|
|
10 |
#'
|
|
11 |
#' @examples
|
|
12 |
#' \dontrun{
|
|
13 |
#' demo("add-camera", package = "sigmajs")
|
|
14 |
#' }
|
|
15 |
#'
|
|
16 |
#' @return An object of class \code{htmlwidget} which renders the visualisation on print.
|
|
17 |
#'
|
|
18 |
#' @noRd
|
|
19 |
#' @keywords internal
|
|
20 |
sg_camera <- function(sg, elementId = NULL, initialise = FALSE) { |
|
21 |
if (missing(elementId) && !isTRUE(initialise)) |
|
22 |
stop("must pass element id if not initialising the camera", call. = FALSE) |
|
23 |
|
|
24 |
if (missing(sg)) |
|
25 |
stop("missing sg", call. = FALSE) |
|
26 |
|
|
27 |
if (!inherits(sg, "sigmajs")) |
|
28 |
stop("sg must be of class sigmajs", call. = FALSE) |
|
29 |
|
|
30 |
sg$x$camera <- list( |
|
31 |
init = initialise, |
|
32 |
id = elementId
|
|
33 |
)
|
|
34 |
|
|
35 |
sg |
|
36 |
}
|
|
37 |
|
|
38 |
#' Zoom
|
|
39 |
#'
|
|
40 |
#' Dynamically Zoom a node.
|
|
41 |
#'
|
|
42 |
#' @param proxy An object of class \code{sigmajsProxy} as returned by \code{\link{sigmajsProxy}}.
|
|
43 |
#' @param id Node id to zoom to.
|
|
44 |
#' @param duration Duration of animation.
|
|
45 |
#' @param ratio The zoom ratio of the graph and its items.
|
|
46 |
#'
|
|
47 |
#' @export
|
|
48 |
sg_zoom_p <- function(proxy, id, ratio = .5, duration = 1000) { |
|
49 |
|
|
50 |
if (missing(proxy) || missing(id)) |
|
51 |
stop("must pass proxy and id", call. = FALSE) |
|
52 |
|
|
53 |
.test_proxy(proxy) |
|
54 |
|
|
55 |
message <- list(id = proxy$id, node = id, duration = duration, ratio = ratio) |
|
56 |
|
|
57 |
proxy$session$sendCustomMessage("sg_zoom_p", message) |
|
58 |
|
|
59 |
return(proxy) |
|
60 |
}
|
Read our documentation on viewing source code .