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 0
  if (missing(elementId) && !isTRUE(initialise))
22 0
    stop("must pass element id if not initialising the camera", call. = FALSE)
23
  
24 0
  if (missing(sg))
25 0
    stop("missing sg", call. = FALSE)
26
  
27 0
  if (!inherits(sg, "sigmajs"))
28 0
    stop("sg must be of class sigmajs", call. = FALSE)
29
  
30 0
  sg$x$camera <- list(
31 0
    init = initialise,
32 0
    id = elementId
33
  )
34
  
35 0
  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 0
  if (missing(proxy) || missing(id))
51 0
    stop("must pass proxy and id", call. = FALSE)
52
  
53 0
  .test_proxy(proxy)
54

55 0
	message <- list(id = proxy$id, node = id, duration = duration, ratio = ratio)
56

57 0
	proxy$session$sendCustomMessage("sg_zoom_p", message)
58

59 0
	return(proxy)
60
}

Read our documentation on viewing source code .

Loading