Articles in this section
Category / Section

How to Animate Connectors Using AnnotationTemplate in Angular Diagram?

3 mins read

In this article, we’ll learn how to animate connectors in the Angular Diagram component using the annotationTemplate. By default, connectors in the diagram do not support direct animation through built-in properties. However, we can achieve a visual animation effect by dynamically updating the position of annotations rendered through a template.

To simulate the animation, we add one or more annotations to each connector. Each annotation uses an annotationTemplate to visually represent an animation element. At regular intervals, we update the offset value of each annotation to make it move along the path of the connector. As a result, it appears as if the connector is animated.

Refer to the following code example that shows how to update the annotation position periodically:

public startWorkflow(args: number) {
 this.connectorCollection = [];
     var level = args ? args : 1;
     var connectors = this.diagram.connectors;
     for (var i = 0; i < connectors.length; i++) {
       if (connectors[i].addInfo && (connectors[i].addInfo as any).level === level) {
         this.connectorCollection.push(connectors[i]);
       }
     }
     var intervalDuration = 120;
     this.flowInterval = setInterval(() => {
       for (var j = 0; j < this.connectorCollection.length; j++) {
         var connector = this.connectorCollection[j];
         for (var k = 0; k < connector.annotations.length; k++) {
           if (connector.annotations[k].offset < 0.99) {
             connector.annotations[k].offset += 0.025;
             connector.style.strokeColor = '#F8FC02';
           }
           if (connector.annotations[k].offset >= 0.95) {
             connector.annotations[k].offset = 0;
           }
         }
       }
       this.diagram.dataBind();
     }, intervalDuration);
} 

Call this startWorkflow function once the diagram has been rendered. This setup will continuously update the annotation position and visually simulate an animation along the connector path.

Kindly refer to the working sample below for a complete implementation:
Sample

Conclusion

I hope you enjoyed learning on how to animate connectors using annotationTemplate in Angular Diagram.
You can refer to our Angular Diagram feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Angular 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!

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