### Basic React Force Graph Example
Source: https://vasturiano.github.io/react-force-graph/index
Demonstrates the fundamental setup and usage of the React Force Graph component for rendering a force-directed graph.
```html
```
--------------------------------
### Input JSON Syntax
Source: https://vasturiano.github.io/react-force-graph/index
Example of the expected JSON structure for defining nodes and links in the graph.
```javascript
{
"nodes": [
{"id": "id1", "name": "name1", "val": 1},
{"id": "id2", "name": "name2", "val": 10},
...
],
"links": [
{"source": "id1", "target": "id2"},
...
]
}
```
--------------------------------
### Basic Force Graph Usage
Source: https://vasturiano.github.io/react-force-graph/index
A simple example of rendering a Force Graph component with graph data.
```html
```
--------------------------------
### AR Graph Integration
Source: https://vasturiano.github.io/react-force-graph/index
Shows an example of integrating the force graph into an Augmented Reality (AR) environment, likely using WebXR.
```html
```
--------------------------------
### Importing Force Graph Components
Source: https://vasturiano.github.io/react-force-graph/index
Demonstrates how to import the different Force Graph components (2D, 3D, VR, AR) for use in a React project.
```javascript
import ForceGraph2D from 'react-force-graph-2d';
import ForceGraph3D from 'react-force-graph-3d';
import ForceGraphVR from 'react-force-graph-vr';
import ForceGraphAR from 'react-force-graph-ar';
```
--------------------------------
### Including Force Graph via Script Tag
Source: https://vasturiano.github.io/react-force-graph/index
Shows how to include the react-force-graph libraries using script tags for direct use in HTML.
```html
```
--------------------------------
### Highlight Nodes and Links
Source: https://vasturiano.github.io/react-force-graph/index
Demonstrates how to highlight specific nodes and links on hover or selection, improving user interaction and focus.
```html
```
--------------------------------
### Camera Automatic Orbitting
Source: https://vasturiano.github.io/react-force-graph/index
Demonstrates how to set up an automatic orbiting camera movement around the graph in 3D space, creating an animated viewing experience.
```html
```
--------------------------------
### Managing Lights and Post-Processing
Source: https://vasturiano.github.io/react-force-graph/index
Allows for the management of lights within the scene and access to the post-processing composer for applying visual effects. The composer can be extended with various rendering passes.
```APIDOC
lights: ([_array_]) | Getter/setter for the list of lights to use in the scene. Each item should be an instance of [Light](https://threejs.org/docs/#api/en/lights/Light).
postProcessingComposer: [_object_] | Access the [post-processing composer](https://threejs.org/docs/#examples/en/postprocessing/EffectComposer). Use this to add post-processing [rendering effects](https://github.com/mrdoob/three.js/tree/dev/examples/jsm/postprocessing) to the scene. By default the composer has a single pass ([RenderPass](https://github.com/mrdoob/three.js/blob/dev/examples/jsm/postprocessing/RenderPass.js)) that directly renders the scene without any effects.
```
--------------------------------
### Larger Graph Performance
Source: https://vasturiano.github.io/react-force-graph/index
Demonstrates techniques and configurations for rendering and interacting with significantly larger graphs efficiently.
```html
```
--------------------------------
### Auto-Colored Nodes and Links
Source: https://vasturiano.github.io/react-force-graph/index
Demonstrates how to automatically assign colors to nodes and links based on their properties or data, simplifying visual differentiation.
```html
```
--------------------------------
### Image Nodes
Source: https://vasturiano.github.io/react-force-graph/index
Shows how to use images as node representations in the force graph, allowing for richer visual content.
```html
```
--------------------------------
### Dynamic Data Changes
Source: https://vasturiano.github.io/react-force-graph/index
Shows how to update the graph data dynamically after initial rendering, allowing for real-time data visualization.
```html
```
--------------------------------
### Force Engine Configuration Properties
Source: https://vasturiano.github.io/react-force-graph/index
This section details the properties used to configure the force simulation engine. These properties control aspects like the number of dimensions, the simulation engine choice, DAG layout behavior, and specific parameters for d3 and ngraph engines.
```APIDOC
Force Engine Configuration:
Properties:
numDimensions: number (1, 2, or 3, default: 3)
Description: Number of dimensions for the force simulation. Not applicable to 2D mode.
forceEngine: string ('d3' or 'ngraph', default: 'd3')
Description: Specifies which force-simulation engine to use. Options are 'd3' (using d3-force-3d) or 'ngraph' (using ngraph.forcelayout).
dagMode: string (default: null)
Description: Applies layout constraints based on graph directionality for DAG structures. Possible values: 'td', 'bu', 'lr', 'rl', 'zout', 'zin', 'radialout', 'radialin'.
dagLevelDistance: number (default: auto-derived)
Description: Distance between graph depths when 'dagMode' is active.
dagNodeFilter: function (default: node => true)
Description: A function to filter nodes for DAG layout processing. Returns true to include, false to exclude.
onDagError: function (default: throws exception)
Description: Callback invoked if a cycle is encountered during DAG layout processing. Receives the loop segment as an array of node ids.
d3AlphaMin: number (default: 0)
Description: Sets the simulation alpha min parameter for d3 engine.
d3AlphaDecay: number (default: 0.0228)
Description: Sets the simulation intensity decay parameter for d3 engine.
d3VelocityDecay: number (default: 0.4)
Description: Sets the nodes' velocity decay parameter for d3 engine.
ngraphPhysics: object (default: null)
Description: Custom physics configuration for ngraph engine, following its configuration object syntax.
warmupTicks: number (default: 0)
Description: Number of layout engine cycles to dry-run before rendering.
cooldownTicks: number (default: Infinity)
Description: Number of frames to render before stopping the layout engine.
cooldownTime: number (default: 15000)
Description: Duration (ms) to render before stopping the layout engine.
onEngineTick: function (default: null)
Description: Callback function invoked at every tick of the simulation engine.
onEngineStop: function (default: null)
Description: Callback function invoked when the simulation engine stops.
```
--------------------------------
### API Reference: Data Input Props
Source: https://vasturiano.github.io/react-force-graph/index
Details the properties related to inputting and accessing graph data, including node and link identifiers.
```APIDOC
Prop | Type | Default | Description | 2D | 3D | VR | AR
---|---|---|---|---|---|---|---
**graphData** | _object_ | `{ nodes: [], links: [] }` | Graph data structure (see below for syntax details). Can also be used to apply incremental updates. | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark:
**nodeId** | _string_ | `id` | Node object accessor attribute for unique node id (used in link objects source/target). | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark:
**linkSource** | _string_ | `source` | Link object accessor attribute referring to id of source node. | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark:
**linkTarget** | _string_ | `target` | Link object accessor attribute referring to id of target node. | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark:
```
--------------------------------
### API Reference: Container Layout Props
Source: https://vasturiano.github.io/react-force-graph/index
Describes properties for controlling the visual dimensions and appearance of the graph container, including background and AR-specific settings.
```APIDOC
Prop | Type | Default | Description | 2D | 3D | VR | AR
---|---|---|---|---|---|---|---
**width** | _number_ | _< window width>_ | Canvas width, in px. | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark:
**height** | _number_ | _< window height>_ | Canvas height, in px. | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark:
**backgroundColor** | _string_ | (2D - _light_ / 3D - _dark_) | Chart background color. | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
**showNavInfo** | _bool_ | `true` | Whether to show the navigation controls footer info. | | :heavy_check_mark: | :heavy_check_mark: |
**yOffset** | _number_ | 1.5 | In AR mode, defines the offset distance above the marker where to place the center coordinates `<0,0,0>` of the force directed graph. Measured in terms of marker width units. | | | | :heavy_check_mark:
**glScale** | _number_ | 200 | In AR mode, defines the translation scale between real world distances and WebGL units, determining the overall size of the graph. Defined in terms of how many GL units fit in a full marker width. | | | | :heavy_check_mark:
**markerAttrs** | _object_ | `{ preset: 'hiro' }` | Set of attributes that define the marker where the AR force directed graph is mounted, according to the [a-marker specification](https://ar-js-org.github.io/AR.js-Docs/marker-based/). This prop only has an effect on component mount. | | | | :heavy_check_mark:
```
--------------------------------
### 3D Text Nodes
Source: https://vasturiano.github.io/react-force-graph/index
Illustrates rendering text labels on nodes within a 3D force graph environment, enhancing the visual presentation in 3D space.
```html
```
--------------------------------
### Text in Links
Source: https://vasturiano.github.io/react-force-graph/index
Shows how to display text labels on the links themselves, providing additional context or information about the connections.
```html
```
--------------------------------
### Curved Lines and Self Links
Source: https://vasturiano.github.io/react-force-graph/index
Demonstrates how to render curved links and handle self-referencing links (links from a node to itself) for more complex graph visualizations.
```html
```
--------------------------------
### Animation and Viewport Control Methods
Source: https://vasturiano.github.io/react-force-graph/index
Methods for controlling the animation cycle, pausing and resuming rendering, and manipulating the viewport. Includes methods for centering the view, zooming, and fitting the graph to the viewport.
```APIDOC
pauseAnimation(): void
Pauses the rendering cycle of the component, effectively freezing the current view and cancelling all user interaction. This method can be used to save performance in circumstances when a static image is sufficient.
resumeAnimation(): void
Resumes the rendering cycle of the component, and re-enables the user interaction. This method can be used together with `pauseAnimation` for performance optimization purposes.
centerAt(x: number, y: number, ms: number): void
Set the coordinates of the center of the viewport. This method can be used to perform panning on the 2D canvas programmatically. Each of the `x, y` coordinates is optional, allowing for motion in just one dimension. An optional 3rd argument defines the duration of the transition (in ms) to animate the canvas motion.
zoom(level: number, ms: number): void
Set the 2D canvas zoom amount. The zoom is defined in terms of the scale transform of each px. A value of `1` indicates unity, larger values zoom in and smaller values zoom out. An optional 2nd argument defines the duration of the transition (in ms) to animate the canvas motion. By default the zoom is set to a value inversely proportional to the amount of nodes in the system.
zoomToFit(ms: number, padding: number, nodeFilterFn: function): void
Automatically zooms/pans the canvas so that all of the nodes fit inside it. If no nodes are found no action is taken. It accepts two optional arguments: the first defines the duration of the transition (in ms) to animate the canvas motion (default: 0ms). The second argument is the amount of padding (in px) between the edge of the canvas and the outermost node (default: 10px). The third argument specifies a custom node filter: `node => `, which should return a truthy value if the node is to be included. This can be useful for focusing on a portion of the graph.
cameraPosition(position: {x: number, y: number, z: number}, lookAt: {x: number, y: number, z: number}, ms: number): void
Re-position the camera, in terms of `x`, `y`, `z` coordinates. Each of the coordinates is optional, allowing for motion in just some dimensions. The optional second argument can be used to define the direction that the camera should aim at, in terms of an `{x,y,z}` point in the 3D space. The 3rd optional argument defines the duration of the transition (in ms) to animate the camera motion. A value of 0 (default) moves the camera immediately to the final position. By default the camera will face the center of the graph at a `z` distance proportional to the amount of nodes in the system.
```
--------------------------------
### Multiple Node Selection
Source: https://vasturiano.github.io/react-force-graph/index
Shows how to enable and manage the selection of multiple nodes simultaneously, facilitating batch operations or analysis.
```html
```
--------------------------------
### Custom Pointer Area Painting
Source: https://vasturiano.github.io/react-force-graph/index
Define custom callback functions for painting interaction areas for nodes and links. These areas are invisible but used for pointer detection.
```APIDOC
nodePointerAreaPaint | func | _default interaction area is a circle centered on the node and sized according to`val`._ | Callback function for painting a canvas area used to detect node pointer interactions. The provided paint color uniquely identifies the node and should be used to perform drawing operations on the provided canvas context. This painted area will not be visible, but instead be used to detect pointer interactions with the node. The callback function has the signature: `nodePointerAreaPaint(, ,