Articles in this section

How to create and update annotation template dynamically in Vue Diagram?

This article explains how to create and update an annotation template dynamically in Vue Diagram. In Vue Diagram, an annotation is a block of text that can be displayed over a node or connector. An annotation is used to textually represent an object with a string that can be edited at runtime. The diagram provides either an HTML or SVG template for node and connector annotations. To do this, simply access the annotation template property and specify the desired template. The template should be in string format. To see an example of how to set an annotation template for a node and connector, please refer to the code snippet below.

<ejs-diagram style="display: block" ref="diagramObject" id="diagram" :width="width" :height="height" :nodes="nodes" :connectors="connectors"></ejs-diagram>
// Initialize the nodes and connectors
let nodes = [
  {
    id: 'node1',
    width: 100,
    height: 100,
    offsetX: 100,
    offsetY: 100,
    annotations:[ {
      content: '|||',
      template:
      '<div><img src="https://www.freepnglogos.com/uploads/plus-icon/plus-icon-plus-math-icon-download-icons-9.png" height="30" weight="30"></div>',
    },]
  },  ]
let connectors= [
  {
    id: 'connector4',
    sourcePoint: { x: 250, y: 400 },
    targetPoint: { x: 400, y: 400 },
    annotations: [
      {
        content: 'F',
        offset: 1,
        margin: { bottom: 20 },
        template: '<div><input type="button" value="Submit"></div>',
      },
      {
        offset: 0.5,
        content: 'HTML Template',
        margin: { top: 20 },
      }
    ],
  },
 
];

The provided code sets initial annotation templates for a node and a connector.

Additionally, annotation templates can be changed dynamically in response to user actions. The code snippet below illustrates how to update the annotation template for a node and a connector on a button click:

 function add(){
       diagramInstance.connectors[0].annotations[0].template =
       '<div><input type="button" value="connector"></div>';
 
       diagramInstance.nodes[0].annotations[0].template =
       '<div><input type="button" value="Node"></div>';
   }

This code dynamically changes the annotation templates for a node and a connector, followed by updating the diagram to reflect the changes.

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

Conclusion

We hope you enjoyed learning about how to create and update annotation templates dynamically in Vue Diagram.

You can refer to our Vue 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 Vue 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