Skip to content

[Feature Request] Allow custom function for nodeRepulsion attribute in cose layout #209

Open
@jlalbers

Description

@jlalbers

Description

I am currently using the cose layout for a project to present a large number of nodes in a small space. Depending on the user actions within the app, the style of different nodes are updated via callbacks. I would also like to use a custom function for the nodeRepulsion property of the cose layout that can be modified via a callback. This is how the Cytoscape JS cose layout works, as referenced here, and would allow me to dynamically alter the repulsion for a subset of nodes based on user input. However, Dash Cytoscape currently only allows a static numeric value to be used which is applied to all nodes.

Steps/Code to Reproduce

import dash
import dash_cytoscape as cyto
from dash import html

def custom_nodeRepulsion_func(node):
    # Logic for returning a numeric repulsion value for the node
    return 2048

app = dash.Dash(__name__)

app.layout = html.Div([
    ...
    cyto.Cytoscape(
        id='cytoscape',
        elements=[ ... ],
        layout={'name': 'cose', 'nodeRepulsion': custom_nodeRepulsion_func}
    )
    ...
])

if __name__ == '__main__':
    app.run_server(debug=True)

Expected Results

Ideally, the custom function would calculate the node repulsion for each node while building the cose layout. This would allow for a dynamic physics-based node layout based on the user input.

Actual Results

Dash app displays "Error loading layout".

Versions

Dash 2.15.0
Dash Cytoscape 1.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions