# 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" }
  ]
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cgps.gitbook.io/data-flo/reference-guide/apply-force-directed-layout.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
