qazwsxedc111
qazwsxedc111

Reputation: 21

How to set the concentric circle layout parameters in python dash_cytoscape?

I have my elements defined like where level refers to the circle layer I want that node.

 elements = [{'data': {'id': 'a', 'label': 'a', 'level': 1},
             {'data': {'id': 'b', 'label': 'b', 'level': 1},
             {'data': {'id': 'c', 'label': 'c', 'level': 2},
             .......]

I have tried the following which doesnt work (error loading layout)

app.layout = html.Div([
    cyto.Cytoscape(
        id='cytoscape',
        elements= elements,
        layout={'name': 'concentric', 'concentric': lambda x: x['data']['level']}
    )
])

The javascript documentation is here https://js.cytoscape.org/#layouts and specifies

let options = {
  name: 'concentric',
  concentric: function( node ){ // returns numeric value for each node, placing higher nodes in levels towards the centre
  return node.degree();
  }

How do I set this concentric parameter?

Cheers

Upvotes: 2

Views: 654

Answers (1)

xhluca
xhluca

Reputation: 1046

Unfortunately it's not possible to pass python functions to the layout parameter in a cyto.Cytoscape component. This is because the function will not be transpiled to a JS function, which is what is needed for the concentric key to work inside options.

Alternatives would be:

  1. Use a python network library (e.g. networkX) to assign the x/y positions based on the concentric algorithm, then return the exact position using a custom layout in dash-cytoscape (rather than a concentric layout).
  2. Modify the source code of cyto.Cytoscape and hard code the JS function you'd like to use for the concentric layout. You'd need to follow the contributing instructions to build and create a custom installation.

Upvotes: 2

Related Questions