I have a Node application using Cytoscape v3.15.2. I have the styling set as follows
let cy = cytoscape({
container: document.getElementById('graph-div'),
style: [
{
selector: 'node',
style: {
'label': 'data(id)',
}
},
{
selector: 'edge',
style: {
'label': (ele) => {
if(ele.data('type') === '1') return 'data(category1)';
if(ele.data('type') === '2') return 'data(category2)';
return value;
}
}]
});
Now, using a checkbox, I am trying to show/hide the labels on the elements. I have tried doing the following:
cy.elements().style("label","");
But this doesn't work. The same thing works when I pass a random string instead an empty string, something like this : cy.elements().style("label","random");
. Doing this sets the labels of all elements in the graph to hidden. How can I do this?
You can manage showing/hiding labels by specifying a class in the stylesheet and then toggling it on button click as in the below example.