Articles in this section

How to change node and connector shape of the JavaScript Diagram dynamically?

This article explains how to change the node and connector shapes of the JavaScript Diagram dynamically. To dynamically change the shape of nodes or connectors in the Syncfusion® JavaScript Diagram, use the shape and type properties of the node or connector.

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:
document.getElementById('changeShape').onclick = function () {
 if (diagram.selectedItems.nodes.length > 0) {
   diagram.selectedItems.nodes[0].shape = { type: 'Flow', shape: 'Decision' };
   diagram.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:
document.getElementById('changeConnectortype').onclick = function () {
 if (diagram.selectedItems.connectors.length > 0) {
   diagram.selectedItems.connectors[0].type = 'Orthogonal';
   diagram.dataBind();
 }
};
Sample:

Refer to the working sample for additional details and implementation: Click here for sample

Conclusion

We hope you enjoyed learning about how to change node and connector shapes dynamically.

You can refer to our JavaScript diagram feature tour page to learn about its other groundbreaking feature representations. You can also explore our JavaScript diagram documentation to understand how to present and manipulate data.

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

If you have any queries or require clarifications, please let us know in the comments 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