1#' Network visualization collapse / uncollapsed method 2#' 3#'@param graph : a \code{\link{visNetworkProxy}} object 4#'@param nodes : a vector of nodes id. NULL for \code{visUncollapse} for open all collapsed nodes 5#'@param fit : Optional. Boolean. Default to FALSE. Call fit method after collapse/uncollapse event ? 6#'@param resetHighlight : Optional. Boolean. Default to TRUE to reset highlighted nodes after collapse/uncollapse event. 7#'@param keepCoord : Optional. Boolean. Default to TRUE to keep nodes coordinates on collapse 8#'@param clusterOptions : Optional. List. Default to NULL. A list of all options you want to pass to cluster collapsed node 9#'@param labelSuffix : Optional. Character. Use node label + suffix or just suffix. Default to '(cluster)' 10#' 11#'@seealso \link{visNodes} for nodes options, \link{visEdges} for edges options, \link{visGroups} for groups options, 12#'\link{visLegend} for adding legend, \link{visOptions} for custom option, \link{visLayout} & \link{visHierarchicalLayout} for layout, 13#'\link{visPhysics} for control physics, \link{visInteraction} for interaction, \link{visNetworkProxy} & \link{visFocus} & \link{visFit} for animation within shiny, 14#'\link{visDocumentation}, \link{visEvents}, \link{visConfigure} ... 15#' 16#' @examples 17#'\dontrun{ 18#' 19#'# have a look to : 20#' 21#'shiny::runApp(system.file("shiny", package = "visNetwork")) 22#' 23#'# You can also disable / enabled the double-click event opening cluster 24#'visNetworkProxy("network_id") %>% visEvents(type = "off", doubleClick = "networkOpenCluster") 25#'visNetworkProxy("network_id") %>% visEvents(type = "on", doubleClick = "networkOpenCluster") 26#' 27#'} 28#' 29#'@export 30#'@references See online documentation \url{http://datastorm-open.github.io/visNetwork/} 31#'@name visNetwork-collapse 32#' 33visCollapse <- function(graph, nodes, fit = FALSE, resetHighlight = TRUE, 34 clusterOptions = NULL, labelSuffix = "(cluster)"){ 35 36 if(!any(class(graph) %in% "visNetwork_Proxy")){ 37 stop("Can't use visCollapse with visNetwork object. Only within shiny & using visNetworkProxy") 38 } 39 40 if(length(nodes) == 1){ 41 nodes <- list(nodes) 42 } 43 44 data <- list(id = graph$id, nodes = nodes, fit = fit, 45 resetHighlight = resetHighlight, labelSuffix = labelSuffix) 46 data$clusterOptions <- clusterOptions 47 48 graph$session$sendCustomMessage("visShinyCollapse", data) 49 50 graph 51} 52 53#' @name visNetwork-collapse 54#' 55#' @export 56visUncollapse <- function(graph, nodes = NULL, fit = FALSE, resetHighlight = TRUE, keepCoord = TRUE){ 57 58 if(!any(class(graph) %in% "visNetwork_Proxy")){ 59 stop("Can't use visUncollapse with visNetwork object. Only within shiny & using visNetworkProxy") 60 } 61 62 data <- list(id = graph$id, fit = fit, resetHighlight = resetHighlight, keepCoord = keepCoord) 63 64 if(!is.null(nodes)){ 65 if(length(nodes) == 1){ 66 nodes <- list(nodes) 67 } 68 } 69 data$nodes <- nodes 70 71 graph$session$sendCustomMessage("visShinyUncollapse", data) 72 73 graph 74} 75