Articles in this section
Category / Section

How to Customize Annotations using Toolbar in JavaScript Diagram?

2 mins read

In the Syncfusion® JavaScript Diagram component, you can customize node annotations dynamically using toolbar controls. This KB demonstrates how to change the font size, font family, and font color of annotations by integrating UI components such as the NumericTextBox for font size, DropDownList for font family, and ColorPicker for font color. When a node is selected and the user interacts with the toolbar, respective handler methods are triggered. These handlers internally call the updateAnnotationValue method to update the selected annotation’s style properties. The updateAnnotationValue method accepts two parameters: the property to be updated (e.g., “fontSize” or “fontFamily”) and the new value. Below is the method definition:

function updateAnnotationValue(property, value) {
   let selectedNodes = diagram.selectedItems.nodes;
       selectedNodes.forEach(node => {
         node.annotations[0].style[property] = value;
       });
       diagram.dataBind();
 } 

Similarly, to update the font color of the annotation, the change event of the ColorPicker component is used. Within this handler, the new color is applied to all annotations of the selected nodes as shown below:

change: function (arg) {
     for (var i = 0; i < diagram.selectedItems.nodes.length; i++) {
       var nodes = diagram.selectedItems.nodes[i];
       for (var j = 0; j < nodes.annotations.length; j++) {
         nodes.annotations[j].style.color = arg.currentValue.hex;
         diagram.dataBind();
       }
     }
   } 

Kindly refer to the working sample below:
Sample

Conclusion

I hope you enjoyed learning on how to update toolbar control values based on selected node in JavaScript Diagram.
You can refer to our JavaScript 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 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!

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