Skip to Content

Layouts

reagraph has the following layout types:

Layout Overrides

You can override the default layout options for each respective layout using the layoutOverrides property on the GraphCanvas component. In each layout description, it will list the available overrides for that layout if applicable.

Position Overrides

You can override the position in any layout by passing the getNodePosition property to the canvas.

The getNodePosition property has the following signature:

getNodePosition: ( id: string, args: NodePositionArgs ) => InternalGraphPosition;

where NodePositionArgs is:

NameTypeDefault
graphGraph<Attributes, Attributes, Attributes>

The graphology object. Useful for any graph manipulation.

dragsDragReferences

Any nodes that were dragged. This is useful if you want to override the position of a node when dragged.

nodesInternalGraphNode[]

The nodes for the graph.

edgesInternalGraphEdge[]

The edges for the graph.

Custom Layout Draggable

To keep draggable nodes in place, you can use the drags property to get the position of the node when it is dragged.

getNodePosition: (id: string, { nodes, drags }: NodePositionArgs) => { const dragPosition = drags?.[id]?.position; if (dragPosition) { return dragPosition; } // ... }

Layout Types

Below are examples of each layout type and corresponding descriptions.

Force Directed 2D

This is the standard force-directed layout which uses d3-force-3d . This is a modified version of the force directed library from d3 except adds support for three dimensional layouts.

This is a one of the most common layouts used because of the simplicity and flexibility that the layout can support.

This layout supports the following overrides:

NameTypeDefault
centerInertianumber

Center inertia for the layout.

1
dimensionsnumber

Number of dimensions for the layout. 2d or 3d.

2
modeDagMode

Mode for the dag layout. Only applicable for dag layouts.

null
linkDistancenumber

Distance between links.

50
nodeStrengthnumber

Strength of the node repulsion.

-250
clusterStrengthnumber

Strength of the cluster repulsion.

0.5
clustersMap<string, ClusterGroup>

The clusters dragged position to reuse for the layout.

clusterType"force" | "treemap"

The type of clustering.

'force'
nodeLevelRationumber

Ratio of the distance between nodes on the same level.

2
linkStrengthInterClusternumber | ((d: any) => number)

LinkStrength between nodes of different clusters

0.01
linkStrengthIntraClusternumber | ((d: any) => number)

LinkStrength between nodes of the same cluster

0.5
forceLinkDistancenumber

Charge between the meta-nodes (Force template only)

100
forceLinkStrengthnumber

Used to compute the template force nodes size (Force template only)

0.1
forceChargenumber

Used to compute the template force nodes size (Force template only)

-700
forceLayoutstring

Used to determine the simulation forceX and forceY values

typeLayoutTypes

The type of layout to use.

clusterAttributestring

The cluster attribute to use.

graphGraph<Attributes, Attributes, Attributes>

The graph object.

dragsDragReferences

Dragged node position refs.

getNodePosition(id: string, args: NodePositionArgs) => InternalGraphPosition

Get the node position for a given node id.

Force Directed 3D

The force directed 3d layout is similar to the 2D version except it adds another dimension. It uses the same library as the 2D version ( d3-force-3d  ). The 3D version is useful for very large graphs where many nodes would overlap each other.

This layout accepts the same layout overrides as the forceDirected2d.

Circular 2D

The circular layout arranges nodes in a circular fashion drawing relationships between the nodes on the outside of the circle.

This layout supports the following overrides:

NameTypeDefault
radiusnumber

Radius of the circle.

typeLayoutTypes

The type of layout to use.

clusterAttributestring

The cluster attribute to use.

graphGraph<Attributes, Attributes, Attributes>

The graph object.

dragsDragReferences

Dragged node position refs.

getNodePosition(id: string, args: NodePositionArgs) => InternalGraphPosition

Get the node position for a given node id.

Concentric 2D

The concentric layout organises the nodes into concentric circles, based on the specified metric (data.level). The nodes with the lowest metric values are placed in the innermost circle, and the metric values of the nodes acend for each outward circle. Each circle has nodes with metric values between a specified range. This layout is useful for highlighting relative importance of the nodes, and its visual effect can be reinforced by creating a style mapper to the metric — e.g. nodes with larger metric values are darker in colour.

This layout supports the following configuration options:

NameTypeDefault
radiusnumber

Base radius of the innermost circle.

40
concentricSpacingnumber

Distance between circles.

100
typeLayoutTypes

The type of layout to use.

clusterAttributestring

The cluster attribute to use.

graphGraph<Attributes, Attributes, Attributes>

The graph object.

dragsDragReferences

Dragged node position refs.

getNodePosition(id: string, args: NodePositionArgs) => InternalGraphPosition

Get the node position for a given node id.

Concentric 3D

This layout works just like Concentric 2D, using the same interface and configuration. The only difference is that it arranges nodes on spheres instead of circles.

Tree Top Down 2D

Tree Left Right 2D

The tree layout is a good way to display a clear parent-child relationship between nodes. This layout uses d3-force-3d .

This layout accepts the same layout overrides as the forceDirected2d.

Tree 3D

This layout is the same as the tree 2d except adds another dimension. It uses d3-force-3d  under the hood for the layout.

This layout accepts the same layout overrides as the forceDirected2d.

Radial 2D

The radial layout arranges nodes in a circular fashion around the focus node in a radial tree. Each relationship extends to another level in the tree to show a depedency tree. This layout uses d3-force-3d .

This layout accepts the same layout overrides as the forceDirected2d.

Radial 3D

Similar to the Radial 2D but adds another dimension. This layout uses d3-force-3d .

This layout accepts the same layout overrides as the forceDirected2d.

Hierarchical 2D

This layout uses d3-hierarchy .

This layout supports the following overrides:

NameTypeDefault
mode"td" | "lr"

Direction of the layout.

'td'
nodeSeparationnumber

Factor of distance between nodes.

1
nodeSize[number, number]

Size of each node.

[50, 50]
typeLayoutTypes

The type of layout to use.

clusterAttributestring

The cluster attribute to use.

graphGraph<Attributes, Attributes, Attributes>

The graph object.

dragsDragReferences

Dragged node position refs.

getNodePosition(id: string, args: NodePositionArgs) => InternalGraphPosition

Get the node position for a given node id.

No Overlap

This layout uses graphology-layout-nooverlap .

This layout supports the following overrides:

NameTypeDefault
gridSizenumber

Grid size.

20
rationumber

Ratio of the layout.

1
maxIterationsnumber

Maximum number of iterations.

500
marginnumber

Margin between nodes.

5
typeLayoutTypes

The type of layout to use.

clusterAttributestring

The cluster attribute to use.

graphGraph<Attributes, Attributes, Attributes>

The graph object.

dragsDragReferences

Dragged node position refs.

getNodePosition(id: string, args: NodePositionArgs) => InternalGraphPosition

Get the node position for a given node id.

Force Atlas 2

This layout uses graphology-layout-forceatlas2 .

This layout supports the following overrides:

NameTypeDefault
adjustSizesboolean

Should the node’s sizes be taken into account.

false
barnesHutOptimizeboolean

whether to use the Barnes-Hut approximation to compute repulsion in O(n*log(n)) rather than default O(n^2), n being the number of nodes.

false
barnesHutThetanumber

Barnes-Hut approximation theta parameter.

0.5
edgeWeightInfluencenumber

Influence of the edge’s weights on the layout. To consider edge weight, don’t forget to pass weighted as true.

1
gravitynumber

Strength of the layout’s gravity.

10
linLogModeboolean

Whether to use Noack’s LinLog model.

false
outboundAttractionDistributionboolean

Whether to consider edge weights when calculating repulsion.

false
scalingRationumber

Scaling ratio for repulsion.

100
slowDownnumber

Speed of the slowdown.

1
strongGravityModeboolean

Whether to use the strong gravity mode.

false
iterationsnumber

Number of iterations to perform.

50
typeLayoutTypes

The type of layout to use.

clusterAttributestring

The cluster attribute to use.

graphGraph<Attributes, Attributes, Attributes>

The graph object.

dragsDragReferences

Dragged node position refs.

getNodePosition(id: string, args: NodePositionArgs) => InternalGraphPosition

Get the node position for a given node id.

Custom Layouts

For creating custom layouts, you can use the getNodePosition function described in the Position Overrides section above. This allows you to implement your own positioning logic for nodes based on your specific requirements.

Last updated on