Skip to Content

Custom Nodes

reagraph supports the ability to override the Node shape and pass your own custom node component.

In the GraphCanvas you can pass a callback to the renderNode function which passes the following attributes:

NameTypeDefault
colorColorRepresentation

Color of the node. Handles selected/etc.

nodeInternalGraphNode

The internal node model.

sizenumber

Size of the node.

activeboolean

Whether the node is active or not.

selectedboolean

Whether the node is selected or not.

opacitynumber

Opacity of the node. Mainly used for selection.

animatedboolean

Animation of the node.

idstring

ID of the node.

Using react-three-fiber  you can use JSX to create your own WebGL custom node like:

export const Custom3DNode = () => ( <GraphCanvas nodes={simpleNodes} edges={simpleEdges} cameraMode="rotate" renderNode={({ size, color, opacity }) => ( <group> <mesh> <torusKnotGeometry attach="geometry" args={[size, 1.25, 50, 8]} /> <meshBasicMaterial attach="material" color={color} opacity={opacity} transparent /> </mesh> </group> )} />
Last updated on