apply-force-directed-layout

Description

apply-force-directed-layout adaptor utilises force-directed graph layout algorithm to arrange the graph's nodes in two-dimensional space such that the edges are roughly equal in length and there is minimal overlap between them.

This is achieved by applying forces between the edges and nodes, which are determined by their spatial relationships.

Inputs

graph Type: graph Required: Yes The graph structure.

stiffness Type: number Required: No Defaults to 400.0.

repulsion Type: number Required: No How much each node should node push each other away. If unspecified, defaults to 400.0.

damping Type: number Required: No The amount to lessen the force to be applied. If unspecified, defaults to 0.5.

min energy threshold Type: number Required: No The minimum amount of force that should be applied. If unspecified, defaults to null.

max speed Type: number Required: No The maximum amount of speed that should be applied. If unspecified, defaults to null.

Outputs

graph Type: graph A force-directed graph drawing.

Examples

Example 1: Default behaviour.

Inputs:

graph:

{ 
  "nodes": [ 
    { "id": "a" },
    { "id": "b" }, 
    { "id": "c" }
  ],
  "edges": [
    { "id": "edge-1", "from": "a", "to": "b" },
    { "id": "edge-2", "from": "a", "to": "c" }
  ]
}

Outputs:

graph:

{ 
  "nodes": [ 
    { "id": "a", "attributes": { "x": -0.3344754101595267, "y": 0.011564418302125241 } },
    { "id": "b", "attributes": { "x": 2.1086496683204, "y": -0.18495166054222117 } },
    { "id": "c", "attributes": { "x": -2.7775956240311155, "y": 0.2081409655145249 } }
  ],
  "edges": [
    { "id": "edge-1", "from": "a", "to": "b" },
    { "id": "edge-2", "from": "a", "to": "c" }
  ]
}

Last updated