How to Customize the Annotations using toolbar in Angular Diagram?
In the Syncfusion® Angular 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:
public updateAnnotationValue(value, fontSize, fontFamily, index, isSelected) {
// Iterate through selected nodes in the diagram
for (let i: number = 0; i < this.diagram.selectedItems.nodes.length; i++) {
let node = this.diagram.selectedItems.nodes[i];
// Iterate through annotations of each node
for (var j = 0; j < node.annotations.length; j++) {
var annotationstyle = node.annotations[j].style;
// Update style attributes based on the provided value
if (value === 'fontsize') {
annotationstyle.fontSize = fontSize;
} else if (value === 'fontfamily') {
annotationstyle.fontFamily = fontFamily.toString();
}
}
}
}
Similarly, to update the font color of the annotation, the colorChange 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:
public colorChange(args) {
for (let i: number = 0; i < this.diagram.selectedItems.nodes.length; i++) {
var nodes = this.diagram.selectedItems.nodes[i];
for (let j: number = 0; j < nodes.annotations.length; j++) {
nodes.annotations[j].style.color = args.currentValue.hex;
this.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 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!