I want to add specific CSS (for instance a specific line-color) to certain, but all, edges added with cytoscape.js-edgehandles.js.
I used to cy.edges(selector) command to apply a specific line-color (red) to the edges with source ('I'). But this only works for already existing edges, but not for added edges.
$('#cy').cytoscape({
ready: function(){
window.cy = this;
cy.edges("[source='I']").addClass('red');
},
elements: {
nodes: [
{ data: { id: 'I', name: 'Irlande' } },
{ data: { id: 'H', name: 'Pays-Bas' } },
{ data: { id: 'F', name: 'France' } },
{ data: { id: 'L', name: 'Luxembourg' } }
],
edges: [
{ data: { source: 'I', target: 'F' } },
{ data: { source: 'I', target: 'H' } }
{ data: { source: 'I', target: 'L' } },
{ data: { source: 'H', target: 'I' } },
{ data: { source: 'H', target: 'F' } },
{ data: { source: 'F', target: 'I' } },
{ data: { source: 'F', target: 'H' } },
{ data: { source: 'F', target: 'L' } },
{ data: { source: 'L', target: 'I' } }
]
},
});
This leads me to a couple of related questions:
Do the added edges merge with the existing edges? If the answer is 'no', how can I get them to merge with edges[]?
The relevant code in cytoscape.js-edgehandles.js is :
var edge = cy.add($.extend( true, { group: 'edges', data: { source: source.id(), target: target.id() } }, options().edgeParams(source, target, 0))).addClass(classes);
added = added.add( edge );
break;
default:
target.removeClass('edgehandles-target');
break; // don't add anything
}
}
Thanks,
Umbolt
There are classes you can use in your stylesheet for this purpose. They will take on the style specified in the stylesheet, regardless of when they are created -- similar to CSS stylesheets in HTML.