Custom Nodes

A node contains the node content itself and its ports. Check NodeModel source code, if you want to see what class methods can be extended.

Extending the NodeModel

If you want to create a custom node that looks entirely different, then you need to create a component that renders using its default or customized data mode. In the example below, it uses a customized data model DiamondNodeModel to render DiamondNodeWidget, and both of them are being created in the model factory DiamondNodeFactory.

Because our Diamond node always has four ports, we add four default port models into the DiamondNodeModel. Depending on the type of node you are creating, this is basically where you store your vertex data in the graph theory sense.

This is where we create our customized component. This component can be any customized react component as long as they respect the node and engine props. Ports also need to be rendered inside the node component.

Now we need to create a new node factory to tell the system how our new node model fits into the core system. We specifically are going to extend the DefaultLinkFactory because we want to render a DiamondNodeWidget with data model being DiamondNodeModel. To accomplish that, we simply extend generateReactWidget(event) to return a DiamondNodeWidget and extend generateModel to return a DiamondNodeModel instance.

The actual code for the DiamondNode can be found here (it is in the demo-custom-node1 folder in the demo gallery).

This is the easiest and most simple way to get started with custom nodes.

Last updated

Was this helpful?