How to Add Annotation Constraints in JavaScript Diagram?
In this article, we will learn how to add annotation constraints for dynamically added annotations during the TextEdit event in the JavaScript Diagram component.
When you double-click on a node or connector annotation, the edit box will open. After editing the annotation content, the TextEdit event will be triggered. In this event, you can access the edited node or connector object. Using this object, you can add annotation constraints for the corresponding node or connector.
Please refer to the code below to handle changes inside the TextEdit event:
textEdit: function (args) {
let element = args.element;
if (element.annotations.length > 0) {
element.annotations[0].constraints =
ej.diagrams.AnnotationConstraints.Interaction | ej.diagrams.AnnotationConstraints.Drag;
}
}
In this code:
- After editing, we access the edited node or connector through args.element.
- If the element has annotations, we apply the Interaction and Drag constraints to the first annotation.
Kindly refer to the working sample provided below for your reference:
Conclusion
I hope you enjoyed learning how to add annotation constraints in JavaScript Diagram.
You can refer to our JavaScript 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 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, Direct-Trac, or feedback portal. We are always happy to assist you!