Baflora
Baflora

Reputation: 119

Changing the color of node-labels using Python Dash Cytoscapes

I want to change the color of the labels of nodes and did that the way the documentation describes it. However, if I add a stylesheet element for the labels they are disappearing of my cytoscapes element. What do I miss? Im using a seperate .css file for styling purposes. Do I have to add this part to the .css file too?

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

Upvotes: 1

Views: 1758

Answers (1)

EricLavault
EricLavault

Reputation: 16095

Cytoscape selectors and styling are a bit "different" : since the label content is a style, you need to specify it (again) in the style dictionary, otherwise it looses its content when applying styles.

This sounds like a bug to me, because any little override requires to reapply the whole styles for the elements, and we don't necessarily know these styles.

There is another buggy thing in my opinion which is that 'label', '[label]' and 'node' selectors seems to behave exactly the same (that is applying to 'node' as described in the doc).

Anyway, once you know that you can do :

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 :/
    }
}],

@see more details about cytoscape selectors and style mappers.

Upvotes: 1

Related Questions