How to Show/Hide Annotations at Runtime in React Diagram?
You can control the visibility of annotations by adjusting their visible property. The visible property of an annotation determines whether it is shown or hidden on the React Diagram.
To hide or show annotations at once, you need to loop through each node in the diagram and checks the annotations attached to those nodes. Below is a code example demonstrating how to toggle the visibility of annotations with a button click.
let showNodeAnnotations = true;
function App() {
const handleannotation = () => {
let nodesCollection = diagramInstance.nodes;
let visibility = showNodeAnnotations ? false : true;
nodesCollection.forEach(node => {
node.annotations.forEach(annotation => {
annotation.visibility = visibility;
});
});
showNodeAnnotations = !showNodeAnnotations;
};
Conclusion
I hope you enjoyed learning how to show/hide annotations at runtime in React Diagram.
You can refer to our React 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 React 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!