1#' Network visualization focus method
2#'
3#' For use focus() method in a shiny app. For full documentation, have a look at \link{visDocumentation}.
4#'
5#'@param graph : a \code{\link{visNetworkProxy}}  object
6#'@param id : a node id
7#'@param scale : Optional. Number. The scale is the target zoomlevel. Default value is 2.0.
8#'@param offset : Optional. List. The offset (in DOM units) is how many pixels from the center the view is focussed. Default value is list(x = 0, y = 0).
9#'@param locked : Optional. Boolean. Locked denotes whether or not the view remains locked to the node once the zoom-in animation is finished. Default value is true.
10#'@param animation : Optional. List. For animation you can define the duration (in milliseconds) and easing function manually.
11#'Available are: linear, easeInQuad, easeOutQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic, easeInQuart, easeOutQuart, easeInOutQuart, easeInQuint, easeOutQuint, easeInOutQuint.
12#'Default to list(duration = 1500, easingFunction = "easeInOutQuad")
13#'
14#'@seealso \link{visNodes} for nodes options, \link{visEdges} for edges options, \link{visGroups} for groups options,
15#'\link{visLegend} for adding legend, \link{visOptions} for custom option, \link{visLayout} & \link{visHierarchicalLayout} for layout,
16#'\link{visPhysics} for control physics, \link{visInteraction} for interaction, \link{visNetworkProxy} & \link{visFocus} & \link{visFit} for animation within shiny,
17#'\link{visDocumentation}, \link{visEvents}, \link{visConfigure} ...
18#'
19#' @examples
20#'\dontrun{
21#'
22#'# have a look to :
23#'shiny::runApp(system.file("shiny", package = "visNetwork"))
24#'
25#'}
26#'
27#'@export
28#'@references See online documentation \url{http://datastorm-open.github.io/visNetwork/}
29visFocus <- function(graph, id, scale =  2,
30                     offset =  list(x = 0, y = 0),
31                     locked = TRUE,
32                     animation = list(duration = 1500, easingFunction = "easeInOutQuad")){
33
34  if(!any(class(graph) %in% "visNetwork_Proxy")){
35    stop("Can't use visFocus with visNetwork object. Only within shiny & using visNetworkProxy")
36  }
37
38  stopifnot(length(id) == 1)
39
40  options <- list(scale = scale, offset = offset, locked = locked, animation = animation)
41  data <- list(id = graph$id, focusId = id, options = options)
42
43  graph$session$sendCustomMessage("visShinyFocus", data)
44
45  graph
46}
47