Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GraphNetwork

Hierarchy

  • Network
    • GraphNetwork

Index

Constructors

constructor

  • new GraphNetwork(container: HTMLElement, data: Data, options?: Options): GraphNetwork
  • Creates an instance of Network.

    Parameters

    • container: HTMLElement

      the HTML element representing the network container

    • data: Data

      network data

    • Optional options: Options

    Returns GraphNetwork

Methods

DOMtoCanvas

  • DOMtoCanvas(position: Position): Position
  • This function converts DOM coordinates to coordinates on the canvas. Input and output are in the form of {x:Number,y:Number} (IPosition interface). The DOM values are relative to the network container.

    Parameters

    • position: Position

      the DOM coordinates

    Returns Position

    the canvas coordinates

addEdgeMode

  • addEdgeMode(): void
  • Go into addEdge mode. The explaination from addNodeMode applies here as well.

    Returns void

addNodeMode

  • addNodeMode(): void
  • Go into addNode mode. Having edit mode or manipulation enabled is not required.
    

    To get out of this mode, call disableEditMode(). The callback functions defined in handlerFunctions still apply. To use these methods without having the manipulation GUI, make sure you set enabled to false.

    Returns void

canvasToDOM

  • canvasToDOM(position: Position): Position
  • This function converts canvas coordinates to coordinates on the DOM. Input and output are in the form of {x:Number, y:Number} (IPosition interface). The DOM values are relative to the network container.

    Parameters

    • position: Position

      the canvas coordinates

    Returns Position

    the DOM coordinates

cluster

  • cluster(options?: ClusterOptions): void
  • The joinCondition function is presented with all nodes.

    Parameters

    • Optional options: ClusterOptions

    Returns void

clusterByConnection

  • clusterByConnection(nodeId: string, options?: ClusterOptions): void
  • This method looks at the provided node and makes a cluster of it and all it's connected nodes.
    

    The behaviour can be customized by proving the options object. All options of this object are explained below. The joinCondition is only presented with the connected nodes.

    Parameters

    • nodeId: string

      the id of the node

    • Optional options: ClusterOptions

    Returns void

clusterByHubsize

  • clusterByHubsize(hubsize?: number, options?: ClusterOptions): void
  • This method checks all nodes in the network and those with a equal or higher amount of edges than specified with the hubsize qualify. If a hubsize is not defined, the hubsize will be determined as the average value plus two standard deviations. For all qualifying nodes, clusterByConnection is performed on each of them. The options object is described for clusterByConnection and does the same here.

    Parameters

    • Optional hubsize: number
    • Optional options: ClusterOptions

    Returns void

clusterOutliers

  • clusterOutliers(options?: ClusterOptions): void
  • This method will cluster all nodes with 1 edge with their respective connected node.

    Parameters

    • Optional options: ClusterOptions

    Returns void

deleteSelected

  • deleteSelected(): void
  • Delete selected. Having edit mode or manipulation enabled is not required.

    Returns void

destroy

  • destroy(): void
  • Remove the network from the DOM and remove all Hammer bindings and references.
    

    Returns void

disableEditMode

  • disableEditMode(): void
  • Programatically disable the edit mode. Similar effect to pressing the close icon (small cross in the corner of the toolbar).

    Returns void

editEdgeMode

  • editEdgeMode(): void
  • Go into editEdge mode. The explaination from addNodeMode applies here as well.

    Returns void

editNode

  • editNode(): void
  • Edit the selected node. The explaination from addNodeMode applies here as well.

    Returns void

enableEditMode

  • enableEditMode(): void
  • Programatically enable the edit mode.
    

    Similar effect to pressing the edit button.

    Returns void

findNode

  • findNode(nodeId: IdType): IdType[]
  • Nodes can be in clusters. Clusters can also be in clusters. This function returns an array of nodeIds showing where the node is.

    Example: cluster 'A' contains cluster 'B', cluster 'B' contains cluster 'C', cluster 'C' contains node 'fred'.

    network.clustering.findNode('fred') will return ['A','B','C','fred'].

    Parameters

    • nodeId: IdType

      the node id.

    Returns IdType[]

    an array of nodeIds showing where the node is

fit

  • fit(options?: FitOptions): void
  • Zooms out so all nodes fit on the canvas.

    Parameters

    • Optional options: FitOptions

    Returns void

focus

  • focus(nodeId: IdType, options?: FocusOptions): void
  • You can focus on a node with this function. What that means is the view will lock onto that node, if it is moving, the view will also move accordingly. If the view is dragged by the user, the focus is broken. You can supply options to customize the effect.

    Parameters

    • nodeId: IdType
    • Optional options: FocusOptions

    Returns void

getBaseEdge

  • getBaseEdge(clusteredEdgeId: IdType): IdType
  • When a clusteredEdgeId is available, this method will return the original baseEdgeId provided in data.edges ie. After clustering the 'SelectEdge' event is fired but provides only the clustered edge. This method can then be used to return the baseEdgeId.

    Parameters

    • clusteredEdgeId: IdType

    Returns IdType

getBoundingBox

  • getBoundingBox(nodeId: IdType): BoundingBox
  • Returns a bounding box for the node including label.

    Parameters

    • nodeId: IdType

    Returns BoundingBox

getClusteredEdges

  • getClusteredEdges(baseEdgeId: IdType): IdType[]
  • Similar to findNode in that it returns all the edge ids that were created from the provided edge during clustering.

    Parameters

    • baseEdgeId: IdType

      the base edge id

    Returns IdType[]

    an array of edgeIds

getConnectedEdges

  • getConnectedEdges(nodeId: IdType): IdType[]
  • Returns an array of edgeIds of the edges connected to this node.

    Parameters

    • nodeId: IdType

      the node id

    Returns IdType[]

getConnectedNodes

  • getConnectedNodes(nodeOrEdgeId: IdType): IdType[] | Array<object>
  • Returns an array of nodeIds of the all the nodes that are directly connected to this node. If you supply an edgeId, vis will first match the id to nodes. If no match is found, it will search in the edgelist and return an array: [fromId, toId].

    Parameters

    • nodeOrEdgeId: IdType

      a node or edge id

    Returns IdType[] | Array<object>

getEdgeAt

  • getEdgeAt(position: Position): IdType
  • Returns a edgeId or undefined. The DOM positions are expected to be in pixels from the top left corner of the canvas.

    Parameters

    • position: Position

    Returns IdType

getNodeAt

  • getNodeAt(position: Position): IdType
  • Returns a nodeId or undefined. The DOM positions are expected to be in pixels from the top left corner of the canvas.

    Parameters

    • position: Position

    Returns IdType

getNodesInCluster

  • getNodesInCluster(clusterNodeId: IdType): IdType[]
  • Returns an array of all nodeIds of the nodes that would be released if you open the cluster.

    Parameters

    • clusterNodeId: IdType

      the id of the cluster node

    Returns IdType[]

getOptionsFromConfigurator

  • getOptionsFromConfigurator(): any
  • If you use the configurator, you can call this method to get an options object that contains all differences from the default options caused by users interacting with the configurator.

    Returns any

getPositions

  • getPositions(nodeIds?: IdType[]): object
  • getPositions(nodeId: IdType): Position
  • Returns the x y positions in canvas space of the nodes with the supplied nodeIds as an object.

    Alternative inputs are a String containing a nodeId or nothing. When a String is supplied, the position of the node corresponding to the ID is returned. When nothing is supplied, the positions of all nodes are returned.

    Parameters

    • Optional nodeIds: IdType[]

    Returns object

    • [nodeId: string]: Position
  • Parameters

    • nodeId: IdType

    Returns Position

getScale

  • getScale(): number
  • Returns the current scale of the network. 1.0 is comparible to 100%, 0 is zoomed out infinitely.

    Returns number

    the current scale of the network

getSeed

  • getSeed(): number
  • If you like the layout of your network and would like it to start in the same way next time, ask for the seed using this method and put it in the layout.randomSeed option.

    Returns number

    the current seed of the network.

getSelectedEdges

  • getSelectedEdges(): IdType[]
  • Returns an array of selected edge ids like so: [edgeId1, edgeId2, ..].

    Returns IdType[]

getSelectedNodes

  • getSelectedNodes(): IdType[]
  • Returns an array of selected node ids like so: [nodeId1, nodeId2, ..].

    Returns IdType[]

getSelection

  • getSelection(): object
  • Returns an object with selected nodes and edges ids.

    Returns object

    • edges: IdType[]
    • nodes: IdType[]

getViewPosition

  • getViewPosition(): Position
  • Returns the current central focus point of the view in the form: { x: {Number}, y: {Number} }

    Returns Position

    the view position;

isCluster

  • isCluster(nodeId: IdType): boolean
  • Returns true if the node whose ID has been supplied is a cluster.

    Parameters

    • nodeId: IdType

      the node id.

    Returns boolean

moveNode

  • moveNode(nodeId: IdType, x: number, y: number): void
  • You can use this to programatically move a node. The supplied x and y positions have to be in canvas space!

    Parameters

    • nodeId: IdType

      the node that will be moved

    • x: number

      new canvas space x position

    • y: number

      new canvas space y position

    Returns void

moveTo

  • moveTo(options: MoveToOptions): void
  • You can animate or move the camera using the moveTo method.

    Parameters

    • options: MoveToOptions

    Returns void

off

  • off(eventName: NetworkEvents, callback?: function): void
  • Remove an event listener. The function you supply has to be the exact same as the one you used in the on function. If no function is supplied, all listeners will be removed.

    Parameters

    • eventName: NetworkEvents

      the name of the event, f.e. 'click'

    • Optional callback: function
        • (params?: any): void
        • Parameters

          • Optional params: any

          Returns void

    Returns void

on

  • on(eventName: NetworkEvents, callback: function): void
  • Set an event listener. Depending on the type of event you get different parameters for the callback function.

    Parameters

    • eventName: NetworkEvents

      the name of the event, f.e. 'click'

    • callback: function

      the callback function that will be raised

        • (params?: any): void
        • Parameters

          • Optional params: any

          Returns void

    Returns void

once

  • once(eventName: NetworkEvents, callback: function): void
  • Set an event listener only once. After it has taken place, the event listener will be removed. Depending on the type of event you get different parameters for the callback function.

    Parameters

    • eventName: NetworkEvents

      the name of the event, f.e. 'click'

    • callback: function

      the callback function that will be raised once

        • (params?: any): void
        • Parameters

          • Optional params: any

          Returns void

    Returns void

openCluster

  • openCluster(nodeId: IdType, options?: OpenClusterOptions): void
  • Opens the cluster, releases the contained nodes and edges, removing the cluster node and cluster edges. The options object is optional and currently supports one option, releaseFunction, which is a function that can be used to manually position the nodes after the cluster is opened.

    Parameters

    • nodeId: IdType

      the node id

    • Optional options: OpenClusterOptions

    Returns void

redraw

  • redraw(): void
  • Redraw the network.

    Returns void

releaseNode

  • releaseNode(): void
  • Programatically release the focussed node.

    Returns void

selectEdges

  • selectEdges(edgeIds: IdType[]): void
  • Selects the edges corresponding to the id's in the input array. This method unselects all other objects before selecting its own objects. Does not fire events.

    Parameters

    • edgeIds: IdType[]

    Returns void

selectNodes

  • selectNodes(nodeIds: IdType[], highlightEdges?: boolean): void
  • Selects the nodes corresponding to the id's in the input array. If highlightEdges is true or undefined, the neighbouring edges will also be selected. This method unselects all other objects before selecting its own objects. Does not fire events.

    Parameters

    • nodeIds: IdType[]
    • Optional highlightEdges: boolean

    Returns void

setData

  • setData(data: Data): void
  • Override all the data in the network. If stabilization is enabled in the physics module, the network will stabilize again. This method is also performed when first initializing the network.

    Parameters

    • data: Data

      network data

    Returns void

setOptions

  • setOptions(options: Options): void
  • Set the options. All available options can be found in the modules above. Each module requires it's own container with the module name to contain its options.

    Parameters

    • options: Options

      network options

    Returns void

setSelection

  • setSelection(selection: object, options?: SelectionOptions): void
  • Sets the selection. You can also pass only nodes or edges in selection object.

    Parameters

    • selection: object
      • edges: IdType[]
      • nodes: IdType[]
    • Optional options: SelectionOptions

    Returns void

setSize

  • setSize(width: string, height: string): void
  • Set the size of the canvas. This is automatically done on a window resize.

    Parameters

    • width: string

      width in a common format, f.e. '100px'

    • height: string

      height in a common format, f.e. '100px'

    Returns void

stabilize

  • stabilize(iterations?: number): void
  • You can manually call stabilize at any time. All the stabilization options above are used. You can optionally supply the number of iterations it should do.

    Parameters

    • Optional iterations: number

    Returns void

startSimulation

  • startSimulation(): void
  • Start the physics simulation. This is normally done whenever needed and is only really useful if you stop the simulation yourself and wish to continue it afterwards.

    Returns void

stopSimulation

  • stopSimulation(): void
  • This stops the physics simulation and triggers a stabilized event. Tt can be restarted by dragging a node, altering the dataset or calling startSimulation().

    Returns void

storePositions

  • storePositions(): void
  • When using the vis.DataSet to load your nodes into the network,
    

    this method will put the X and Y positions of all nodes into that dataset. If you're loading your nodes from a database and have this dynamically coupled with the DataSet, you can use this to stablize your network once, then save the positions in that database through the DataSet so the next time you load the nodes, stabilization will be near instantaneous.

    If the nodes are still moving and you're using dynamic smooth edges (which is on by default), you can use the option stabilization.onlyDynamicEdges in the physics module to improve initialization time.

    This method does not support clustering. At the moment it is not possible to cache positions when using clusters since they cannot be correctly initialized from just the positions.

    Returns void

unselectAll

  • unselectAll(): void
  • Unselect all objects. Does not fire events.

    Returns void

updateClusteredNode

  • updateClusteredNode(clusteredNodeId: IdType, options?: NodeOptions): void
  • Clustered Nodes when created are not contained in the original data.nodes passed on network creation. This method updates the cluster node.

    Parameters

    • clusteredNodeId: IdType
    • Optional options: NodeOptions

    Returns void

updateEdge

  • updateEdge(startEdgeId: IdType, options?: EdgeOptions): void
  • Visible edges between clustered nodes are not the same edge as the ones provided in data.edges passed on network creation. With each layer of clustering, copies of the edges between clusters are created and the previous edges are hidden, until the cluster is opened. This method takes an edgeId (ie. a base edgeId from data.edges) and applys the options to it and any edges that were created from it while clustering.

    Parameters

    • startEdgeId: IdType
    • Optional options: EdgeOptions

    Returns void