Network - nodes

Handles the creation and deletion of nodes and contains the global node options and styles.

Options

This is a list of all the methods in the public API. They are collected here from all individual modules.

name type default description
borderWidth Number 1 The width of the border of the node.
borderWidthSelected Number undefined The width of the border of the node when it is selected. When undefined, the borderWidth is used
brokenImage String undefined When the shape is set to image or circularImage, this option can be an URL to a backup image in case the URL supplied in the image option cannot be resolved.
color Object or String Object The color object contains the color information of the node in every situation. When the node only needs a single color, a color value like 'rgba(120,32,14,1)', '#ffffff' or 'red' can be supplied instead of an object.
fixed Object or Boolean Object When true, the node will not move but IS part of the physics simulation. When defined as an object, movement in either X or Y direction can be disabled.
font Object or String false This object defines the details of the label. A shorthand is also supported in the form 'size face color' for example: '14px arial red'.
group String undefined When not undefined, the
hidden Boolean false When true, the node will not be shown. It will still be part of the physics simulation though!
icon Object Object These options are only used when the shape is set to icon.
image String undefined When the shape is set to image or circularImage, this option should be the URL to an image. If the image cannot be found, the brokenImage option can be used.
label String undefined The label is the piece of text shown in or under the node, depending on the shape.
level Number undefined When using the hierarchical layout, the level determines where the node is going to be positioned.
mass Number 1 The barnesHut physics model (which is enabled by default) is based on an inverted gravity model. By increasing the mass of a node, you increase it's repulsion. Values lower than 1 are not recommended.
physics Boolean true When false, the node is not part of the physics simulation. It will not move except for from manual dragging.
scaling Object Object If the value option is specified, the size of the nodes will be scaled according to the properties in this object. All node shapes can be scaled, but some only when label scaling is enabled as their size is based on the size of the label. Only scalable when label scaling is enabled are: ellipse, circle, database, box, text. Always scalable are: image, circularImage, diamond, dot, star, triangle, triangleDown, square and icon. Keep in mind that when using scaling, the size option is neglected.
shadow Object or Boolean Object When true, the node casts a shadow using the default settings. This can be further refined by supplying an object.
shape String 'ellipse' The shape defines what the node looks like. There are two types of nodes. One type has the label inside of it and the other type has the label underneath it. The types with the label inside of it are: ellipse, circle, database, box, text. The ones with the label outside of it are: image, circularImage, diamond, dot, star, triangle, triangleDown, square and icon.
size Number 25 The size is used to determine the size of node shapes that do not have the label inside of them. These shapes are: image, circularImage, diamond, dot, star, triangle, triangleDown, square and icon
title String or Element undefined Title to be displayed when the user hovers over the node. The title can be an HTML element or a string containing plain text or HTML.
value Number undefined When a value is set, the nodes will be scaled using the options in the scaling object defined above.
x Number undefined This gives a node an initial x position. When using the hierarchical layout, either the x or y position is set by the layout engine depending on the type of view. The other value remains untouched. When using stabilization, the stabilized position may be different from the initial one. To lock the node to that position use the physics or fixed options.
y Number undefined This gives a node an initial y position. When using the hierarchical layout, either the x or y position is set by the layout engine depending on the type of view. The other value remains untouched. When using stabilization, the stabilized position may be different from the initial one. To lock the node to that position use the physics or fixed options.

Methods

The nodes module has no methods.

name returns description
getPositions(
   [Array of nodeIds]
)
Object Returns the x y positions in canvas space of the nodes with the supplied nodeIds as an object:
{
  nodeId1: {x: xValue, y:yValue},
  nodeId2: {x: xValue, y:yValue},
  ...
}
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.
storePositions() none 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.
getBoundingBox(
   String nodeId
)
Object Returns a bounding box for the node including label in the format:
{
  top: Number,
  left: Number,
  right: Number,
  bottom: Number
}
These values are in canvas space.
getConnectedNodes(
   String nodeId
)
Array Returns an array of nodeIds of the all the nodes that are directly connected to this node.
getEdges(
   String nodeId
)
Array Returns an array of edgeIds of the edges connected to this node.

Events

The nodes module emits no events. Click and select events are emitted from the interaction and selection modules.