> For the complete documentation index, see [llms.txt](https://cgps.gitbook.io/data-flo/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cgps.gitbook.io/data-flo/reference-guide/apply-force-directed-layout.md).

# apply-force-directed-layout

## Description

<mark style="color:purple;">`apply-force-directed-layout`</mark> *adaptor utilises* [*force-directed graph layout algorithm*](https://en.wikipedia.org/wiki/Force-directed_graph_drawing) *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" }
  ]
}
```
