this.cy = cytoscape({
container: document.getElementById(this.pageId),
boxSelectionEnabled: false,
autounselectify: true,
zoomingEnabled: true,
panningEnabled: true,
autoungrabify: false,
elements: this.nodes,
style: [{
selector: 'node',
style: {
'width':'data(cpu)',
'height': 'data(cpu)',
//'shape': 'circle',
'background-image': 'data(HealthImage)',
'background-fit': 'contain contain',
'background-color': '#f5f7fa',
'label': 'data(' + this.nodeName + ')',
'cssClass': 'form-group', //tried this didn't work
"text-valign": "bottom",
"text-halign": "center",
"font-size": "12px",
"text-margin-y": "8px"
}
}, {
selector: '.day',
style: { "text-background-color": "white" }
}, {
selector: '.night',
style: { "text-background-color": "black" }
}]
});
После этого вам просто нужно добавить правильный класс для каждого узла, и все готово. Также не забудьте удалить неактивный класс при добавлении другого класса.
cy.elements().toggleClass('day').toggleClass('night'); // maybe replace that with add/removeClass if this doesn't work