2

I currently have the following Network Graph. The blue nodes belong to class 'mNodes' and the pink node belongs to class 'vNodes'. Is there a way to change the colour of any node dynamically when the user clicks on it? (e.g. When user clicks on node with label '55315' its colour changes to red.)

enter image description here

The code I used to construct my network graph is as follows:

# Node Elements
default_nodes = (
[{'classes': 'vNodes', 
    'data':{'id': v, 'label': v}} for v in df1.vFamilyID.unique()]+
[{'classes': 'mNodes',
    'data': {'id': m, 'label': m}} for m in df1.mFamilyID]
)

# Edge Elements
default_edges = [{'data': {'source': x, 'target': y}} for x,y in zip(df1.vFamilyID,df1.mFamilyID)]  

default_elements=(default_nodes+default_edges)

default_stylesheet=[
    # Class Selectors
    {
        'selector':'.vNodes',
        'style': {
            'background-color': '#CA8EB0',
            'label': 'data(label)'
        },
    },

    {
        'selector':'.mNodes',
        'style': {
            'background-color': '#5EB5C9',
            'label': 'data(label)'
        },
    },
]

cyto.Cytoscape(id='interaction-overview',
               elements=default_elements,
               stylesheet=default_stylesheet)

Any help will be greatly appreciated.

ta.ng
  • 55
  • 1
  • 8

0 Answers0