Articles in this section

How to Hook GetNodeDefaults and GetConnectorDefaults in JavaScript Diagram?

This article explains how to hook GetNodeDefaults and GetConnectorDefaults in JavaScript Diagram.

GetNodeDefaults

GetNodeDefaults is a method we often use in our JavaScript 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 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.

To hook getNodeDefaults and getConnectorDefaults onto the JavaScript Diagram, you can follow these steps:

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

//Initializes the nodes for the diagram
var diagram = new ej.diagrams.Diagram({
 width: '100%',
 height: '700px',
 //Defines the default node and connector properties
 getNodeDefaults: function (obj, diagram) {
   return getNodeDefaults(obj, diagram);
 },
 getConnectorDefaults: function (connector, diagram) {
   return getConnectorDefaults(connector, diagram);
 },
});
//sets default value for Node.
function getNodeDefaults(obj) {
 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 getConnectorDefaults(connector) {
 connector.targetDecorator.shape = 'None';
 connector.type = 'Orthogonal';
 connector.constraints = 0;
 connector.cornerRadius = 0;
 return connector;
}

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

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

Conclusion

We hope you enjoyed learning how to hook getNodeDefaults and getConnector in the JavaScript Diagram.

You can refer to our JavaScript Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, as well as how to quickly get started with configuration specifications. You can also explore our JavaScript 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