visEvents: Network visualization events

View source: R/visNetworkEvents.R

visEventsR Documentation

Network visualization events

Description

Network visualization events. For full documentation, have a look at visDocumentation. Use type = "once" to set an event listener only once, and type = "off" to disable all the related events.

Usage

visEvents(
  graph,
  type = "on",
  click = NULL,
  doubleClick = NULL,
  oncontext = NULL,
  hold = NULL,
  release = NULL,
  select = NULL,
  selectNode = NULL,
  selectEdge = NULL,
  deselectNode = NULL,
  deselectEdge = NULL,
  dragStart = NULL,
  dragging = NULL,
  dragEnd = NULL,
  controlNodeDragging = NULL,
  controlNodeDragEnd = NULL,
  hoverNode = NULL,
  blurNode = NULL,
  hoverEdge = NULL,
  blurEdge = NULL,
  zoom = NULL,
  showPopup = NULL,
  hidePopup = NULL,
  startStabilizing = NULL,
  stabilizationProgress = NULL,
  stabilizationIterationsDone = NULL,
  stabilized = NULL,
  resize = NULL,
  initRedraw = NULL,
  beforeDrawing = NULL,
  afterDrawing = NULL,
  animationFinished = NULL,
  configChange = NULL
)

Arguments

graph

: a visNetwork object

type

: Character. "on" (Default) to full listener, "once" to set an event listener only once, or "off" to disable a listener.

click

: Fired when the user clicks the mouse or taps on a touchscreen device.

doubleClick

: Fired when the user double clicks the mouse or double taps on a touchscreen device. Since a double click is in fact 2 clicks, 2 click events are fired, followed by a double click event. If you do not want to use the click events if a double click event is fired, just check the time between click events before processing them.

oncontext

: Fired when the user click on the canvas with the right mouse button. The right mouse button does not select by default. You can use the method getNodeAt to select the node if you want.

hold

: Fired when the user clicks and holds the mouse or taps and holds on a touchscreen device. A click event is also fired in this case.

release

: Fired after drawing on the canvas has been completed. Can be used to draw on top of the network.

select

: Fired when the selection has changed by user action. This means a node or edge has been selected, added to the selection or deselected. All select events are only triggered on click and hold.

selectNode

: Fired when a node has been selected by the user.

selectEdge

: Fired when a edge has been selected by the user.

deselectNode

: Fired when a node (or nodes) has (or have) been deselected by the user. The previous selection is the list of nodes and edges that were selected before the last user event.

deselectEdge

: Fired when a edge (or edges) has (or have) been deselected by the user. The previous selection is the list of nodes and edges that were selected before the last user event.

dragStart

: Fired when starting a drag.

dragging

: Fired when dragging node(s) or the view.

dragEnd

: Fired when the drag has finished.

controlNodeDragging

: Fired when dragging control node. Control Edge is edge that is being dragged and contains ids of 'from' and 'to' nodes. If control node is not dragged over another node, 'to' field is undefined. See visDocumentation.

controlNodeDragEnd

: Fired when the control node drag has finished. See visDocumentation.

hoverNode

: Fired interaction:hover:true and the mouse hovers over a node.

blurNode

: Fired interaction:hover:true and the mouse moved away from a node it was hovering over before.

hoverEdge

: Fired interaction:hover:true and the mouse hovers over a edge

blurEdge

: Fired interaction:hover:true and the mouse moved away from a edge it was hovering over before.

zoom

: Fired when the user zooms in or out. The properties tell you which direction the zoom is in. The scale is a number greater than 0, which is the same that you get with network.getScale().

showPopup

: Fired when the popup (tooltip) is shown.

hidePopup

: Fired when the popup (tooltip) is hidden.

startStabilizing

: Fired when stabilization starts. This is also the case when you drag a node and the physics simulation restarts to stabilize again. Stabilization does not neccesarily imply 'without showing'.

stabilizationProgress

: Fired when a multiple of the updateInterval number of iterations is reached. This only occurs in the 'hidden' stabilization. Passes an object with properties structured as:

stabilizationIterationsDone

: Fired when the 'hidden' stabilization finishes. This does not necessarily mean the network is stabilized; it could also mean that the amount of iterations defined in the options has been reached.

stabilized

: Fired when the network has stabilized or when the stopSimulation() has been called. The amount of iterations it took could be used to tweak the maximum amount of iterations needed to stabilize the network.

resize

: Fired when the size of the canvas has been resized, either by a redraw call when the container div has changed in size, a setSize() call with new values or a setOptions() with new width and/or height values.

initRedraw

: Fired before the redrawing begins. The simulation step has completed at this point. Can be used to move custom elements before starting drawing the new frame.

beforeDrawing

: Fired after the canvas has been cleared, scaled and translated to the viewing position but before all edges and nodes are drawn. Can be used to draw behind the network.

afterDrawing

: Fired after drawing on the canvas has been completed. Can be used to draw on top of the network.

animationFinished

: Fired when an animation is finished.

configChange

: Fired when a user changes any option in the configurator. The options object can be used with the setOptions method or stringified using JSON.stringify(). You do not have to manually put the options into the network: this is done automatically. You can use the event to store user options in the database.

References

See online documentation https://datastorm-open.github.io/visNetwork/

See Also

visNodes for nodes options, visEdges for edges options, visGroups for groups options, visLegend for adding legend, visOptions for custom option, visLayout & visHierarchicalLayout for layout, visPhysics for control physics, visInteraction for interaction, visNetworkProxy & visFocus & visFit for animation within shiny, visDocumentation, visEvents, visConfigure ...

Examples


nodes <- data.frame(id = 1:3)
edges <- data.frame(from = c(1,2), to = c(1,3))

visNetwork(nodes, edges) %>%
 visEvents(select = "function(properties) {
     alert('selected nodes: ' + properties.nodes);}", 
     dragEnd = "function(properties) {
     alert('finish to drag');}")

# set one 
visNetwork(nodes, edges) %>%
 visEvents(type = "once", select = "function() {
     alert('first selection');}") %>%
 visEvents(select = "function(properties) {
     alert('selected nodes: ' + properties.nodes);}", 
     dragEnd = "function(properties) {
     alert('finish to drag');}")
      
# use this to get the network
visNetwork(nodes, edges) %>%
  visEvents(type = "once", startStabilizing = "function() {
            this.moveTo({scale:0.1})}") %>%
  visPhysics(stabilization = FALSE)

# shift+click, .....
visNetwork(nodes, edges) %>%
    visEvents(click = "function(e) {
            if(e.event.srcEvent.shiftKey){
              alert('shift+click event')
            } else if(e.event.srcEvent.ctrlKey){
              alert('ctrl+click event')
            }else if(e.event.srcEvent.altKey){
              alert('alt+click event')
            } else {
              alert('click event')
            }
          }")
          

visNetwork documentation built on Sept. 29, 2022, 5:07 p.m.