Articles in this section

How to add annotation to the diagram objects while dragging it from palette onto the Vue Diagram?

You can dynamically add an annotation to a node when dragging a node from the palette and dropping it onto the Vue Diagram using the drop event. In the following article, we will explain how to achieve this by incorporating a dialog control.

Adding annotation content to the node with a dialog box

In the provided sample, when a node is dragged from the palette and dropped onto the diagram, the drop event is triggered. In this event, a dialog box is opened. Below is the corresponding code example for reference.

<ejs-diagram
         style="display: block"
         ref="diagramObject"
         id="diagram"
         :width="width"
         :height="height"
         :drop="drop"
       ></ejs-diagram> 
// Drop function
function drop(args) {
 let obj = args.element;
 if (obj instanceof Node || obj instanceof Connector) {
   // Get a selected item id
   objectFromPalette = obj.id;
 }
 dialogInstance.show();
 return args;
}

In the dialog box, you can enter text, which will be appended to the node or connector upon pressing the submit button. Closing the dialog or pressing the cancel button will remove the selected diagram element. Below is the corresponding code example.

// Initialize 
 <ejs-dialog
       ref="dialogObj"
       :footerTemplate="'footerTemplate'"
       :content="'contentTemplate'"
       :height="dHeight"
       :showCloseIcon="showCloseIcon"
       :target="target"
       :width="dWidth"
       :visible="visible"
       :open="dialogOpen"
     >
       <template v-slot:footerTemplate>
         <div id="container">
           <div>
             <button
               id="submitButton"
               class="e-control e-btn e-primary"
               data-ripple="true"
             >
               Submit
             </button>

             <button
               id="cancelButton"
               class="e-control e-btn e-primary"
               data-ripple="true"
             >
               close
             </button>
           </div>
         </div>
       </template>
       <template v-slot:contentTemplate>
         <div id="container">
           <div class="dialogContent">
             <table
               style="
                 border-collapse: separate;
                 border-spacing: 10px;
                 width: 85%;
                 margin: 0px -5px 0px;
               "
             >
               <tr>
                 <td>Annotation Content:</td>
                 <td>
                   <span class="e-input-group">
                     <input
                       type="text"
                       id="annotationContent"
                       name="Required"
                       class="e-input"
                     />
                   </span>
                 </td>
               </tr>
             </table>
           </div>
         </div>
       </template>
     </ejs-dialog>
// Method to append an annotation to the node

document.getElementById('submitButton').onclick = () => {
       if (objectFromPalette !== '') {
         let obj = diagram.getObject(objectFromPalette);
         let content = document.getElementById('annotationContent').value;
         if (obj instanceof Node || obj instanceof Connector) {
           if (content == '') {
             diagram.remove(obj);
           } else {
             obj.annotations[0].content = content;
             diagram.dataBind();
           }
         }
       }

       dialogInstance.hide();
     };

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

Conclusion

We hope you enjoyed learning about how to create an image as a group node using 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 for 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