Articles in this section

How to Hook GetNodeDefaults and GetConnectorDefaults in React Diagram?

This article explains how to Hook GetNodeDefaults and GetConnectorDefaults in React Diagram.

GetNodeDefaults

getNodeDefaults is a method we often use in our React Diagram component to customize common properties of diagram nodes. It can return or allow you to set properties such as:

Node appearance: Size, shape, color, border, etc.
Node data structure: Initial attributes like width, height and etc.

GetConnectorDefaults

Similar to getNodeDefaults, getConnectorDefaults is also a method used to customize common properties of connectors in the diagram component. It allows you to set properties such as:

Connector appearance: Style, shape, line width, type etc.

Refer to the code sample to hook getNodeDefaults and getConnectorDefaults in org-chart layout:

// Initialize the diagram component

<DiagramComponent
           id="diagram"
           ref={(diagram) => (diagramInstance = diagram)}
           width={'100%'}
           height={'700px'}
           // Configures data source settings
           dataSourceSettings={{
             id: 'Id',
             parentId: 'Manager',
             dataSource: new DataManager(localBindData),
           }}
           // Disables all interactions except zoom/pan
           tool={DiagramTools.ZoomPan}
           // Configures automatic layout
           layout={{
             type: 'OrganizationalChart',
             getLayoutInfo: (node, options) => {
               /* tslint:disable:no-string-literal */
               if (node.data['Role'] === 'General Manager') {
                 options.assistants.push(options.children[0]);
                 options.children.splice(0, 1);
               }
               if (!options.hasSubTree) {
                 options.type = 'Right';
               }
             },
           }}
           // Defines the default node and connector properties
           getNodeDefaults={(obj, diagram) => {
             return nodeDefaults(obj, diagram);
           }}
           getConnectorDefaults={(connector, diagram) => {
             return connectorDefaults(connector, diagram);
           }}
         >
           <Inject
             services={[DataBinding, HierarchicalTree, LayoutAnimation]}
           />
         </DiagramComponent>
// Sets default value for Node.
 function nodeDefaults(obj, diagram) {
   obj.backgroundColor = obj.data.color;
   obj.style = { fill: 'none', strokeColor: 'none', color: 'white' };
   obj.width = 120;
   obj.height = 30;
   return obj;
 }
 // Sets default value for Connector.
 function connectorDefaults(connector, diagram) {
   connector.targetDecorator.shape = 'None';
   connector.type = 'Orthogonal';
   connector.constraints = ConnectorConstraints.None;
   connector.cornerRadius = 0;
   return connector;
 } 

Below, we have provided an example sample for the nodeDefaults and connectorDefaults functions to customize the common properties of nodes and connectors of an organizational chart.

Organization chart :Sample

Conclusion

We hope you enjoyed about how to get child nodes from deleted nodes in React Diagram layout.

You can refer to our React Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our React Diagram example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to explore our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied