Reputation: 160
I have some nodes which are children of parents (Group of nodes). Is it possible to override the Backgraound-color for some children?
I could only override the normal nodes color like this:
cy.nodes('[id = "start"]').style('background-color', '#FBFBFB');
Thanks in advance.
[
{
"style": [
{
"selector": "node",
"css": {
"shape": "roundrectangle",
"height": "40px",
"background-color": "#58D68D",
"label": "data(id)",
"text-valign": "center",
"border-width": "2",
"border-color": "black"
}
},
{
"selector": ":parent",
"css": {
"background-opacity": "0.333",
"text-halign": "center",
"text-valign": "top"
}
},
]
]
}
Upvotes: 0
Views: 647
Reputation: 6074
You can always just specify the color of nodes when you initialize them:
var cy = (window.cy = cytoscape({
container: document.getElementById("cy"),
style: [{
selector: "node",
css: {
"shape": "roundrectangle",
"height": "40px",
"background-color": function(node) {
if (node.data("colored"))
return "#FBFBFB";
else
return "#58D68D";
},
"label": "data(id)",
"text-valign": "center",
"border-width": "2",
"border-color": "black"
}
},
{
selector: ':parent',
css: {
"background-opacity": "0.333",
"text-halign": "center",
"text-valign": "top"
}
},
{
selector: "edge",
css: {
label: "\u2B24",
"curve-style": "bezier",
"target-arrow-shape": "data(arrow)"
}
}
],
elements: {
nodes: [{
data: {
id: "n0",
colored: true,
parent: "n4"
}
},
{
data: {
id: "n1",
colored: false,
parent: "n5"
}
},
{
data: {
id: "n2",
colored: true,
parent: "n5"
}
},
{
data: {
id: "n3",
colored: true,
parent: "n5"
}
},
{
data: {
id: "n4",
colored: false,
parent: "n5"
}
},
{
data: {
id: "n5",
colored: false,
}
}
],
edges: [{
data: {
source: "n0",
target: "n1",
arrow: "triangle"
}
},
{
data: {
source: "n1",
target: "n2",
arrow: "triangle"
}
},
{
data: {
source: "n1",
target: "n3",
arrow: "triangle"
}
}
]
},
layout: {
name: "concentric",
minNodeSpacing: 140
}
}));
body {
font: 14px helvetica neue, helvetica, arial, sans-serif;
}
#cy {
height: 100%;
width: 100%;
left: 0;
top: 0;
float: left;
position: absolute;
}
.cxtmenu-disabled {
opacity: 0.333;
}
<html>
<head>
<meta charset=utf-8 />
<meta name="viewport" content="user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cytoscape.min.js"></script>
</head>
<body>
<div id="cy"></div>
</body>
</html>
Upvotes: 1