使用 Python Dash Cytoscapes 更改节点标签的颜色

Changing the color of node-labels using Python Dash Cytoscapes

我想更改节点标签的颜色,并按照文档描述的方式进行了更改。但是,如果我为标签添加样式表元素,它们就会从我的细胞景观元素中消失。我想念什么?我使用单独的 .css 文件来进行样式设置。我是否也必须将此部分添加到 .css 文件中?

stylesheet=[{
                 'selector': 'label',
                 'style': {
                    'color': 'red'
                 }
           }],

Cytoscape 选择器和样式有点“不同”:由于标签内容 一种样式,您需要在样式字典中(再次)指定它,否则它会丢失应用样式时的内容。

这对我来说听起来像是一个错误,因为任何小的覆盖都需要为元素重新应用整个样式,而我们不一定知道这些样式。

我认为还有一个问题是 'label'、'[label]' 和 'node' 选择器的行为似乎完全相同(应用于 'node'如文档中所述。

无论如何,一旦你知道你可以做到:

stylesheet=[{
    'selector': 'label',             # as if selecting 'node' :/
    'style': {
        'content': 'data(label)',    # not to loose label content
        'color': 'red',
        'background-color': 'pink'   # applies to node which will remain pink if selected :/
    }
}],

@查看有关 cytoscape 的更多详细信息 selectors and style mappers