是的,您可以为cyto.Cytoscape 对象的elements 参数中列出的任何节点设置一个[n 唯一] ID 值字典键“classes”*。
例如:
cyto.Cytoscape(
id="network-output",
elements=[
{
"data": {"id": "A", "label": "A"},
"position": {"x": 75, "y": 75},
"classes": "A", # ← *This node now can be referenced ".A"
},
{
"data": {"id": "B", "label": "B"},
"position": {"x": 200, "y": 200},
"classes": "B",
},
{"data": {"source": "A", "target": "B"}},
],
layout=my_layout,
style=my_style,
stylesheet=[
{"selector": "node", "style": {"width": "50px", "height": "50px"}}
],
)
然后在stylesheet参数中:
stylesheet = [
{
"selector": f".{value}",
"style": {
"background-color": "#FD8008",
"background-opacity": "0.8",
"border-color": "#00C1FF",
"border-width": "2",
"width": "55px",
"height": "55px",
"label": "data(label)",
},
}
]
其中变量value 可以是“A”或“B”,或者您根据类键分配给元素中任何节点的任何其他名称。这样,每个节点的样式都可以根据需要进行唯一处理。包括通过回调,其中输出是任何 Cytoscape 的样式表。