Articles in this section

How to change node and connector shape of React Diagram dynamically?

This article explains how to change node and connector shape of React Diagram dynamically.

Changing the shape of nodes:

• Select the node whose shape you want to change.
• Access the selectedNode from the selectedItems’ nodes property.
• Update the “shape” property of the node to the desired shape. For example, to change a rectangle to an ellipse, set the shape property to “ellipse”.
• You can also update the “type” property of the node to change the type of the shape.
• To apply the changes, call the dataBind () method on the diagram.

Code-Snippet:

function changeShape(){
 if (diagramInstance.selectedItems.nodes.length > 0) {
   diagramInstance.selectedItems.nodes[0].shape = {
     type: 'Flow',
     shape: 'Decision',
   };
   diagramInstance.dataBind();
 }
} 

Changing the connector type:

• Select the connector whose type you want to change.
• Access the selectedConnector from the selectedItems connectors property.
• Update the “type” property of the connector. For example, you can set the type as “Orthogonal” from “Straight”.
• To apply the changes, call the dataBind () method on the diagram.

Code-Snippet:

function changeConnectortype(){
 if (diagramInstance.selectedItems.connectors.length > 0) {
   if (diagramInstance.selectedItems.connectors[0].type === 'Orthogonal') {
     diagramInstance.selectedItems.connectors[0].type = 'Straight';
   } else {
     diagramInstance.selectedItems.connectors[0].type = 'Orthogonal';
   }
   diagramInstance.dataBind();
 }
}

Refer to the working sample for additional details and implementation: Sample

Conclusion

We hope you enjoyed learning about how to change node and connector shape of React Diagram dynamically.

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 check out 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