Hi,
I have a graph G with nodes attributes of date of birth. i want to draw the graph using cytoscape in concentric plot where each circle would correspond to a specific century, such the 18th century, the 19th century, etc.
i am using the following code as a test, but the plot is not showing, saying there is a plot error.
import math
# Initialize Dash app
app = Dash(__name__)
# Sample data: nodes with 'year' attributes
nodes = [
{'data': {'id': 'A', 'year': 1600}},
{'data': {'id': 'B', 'year': 1700}},
{'data': {'id': 'C', 'year': 1650}},
{'data': {'id': 'D', 'year': 1800}},
{'data': {'id': 'E', 'year': 1900}},
# Add more nodes with 'year' attributes
]
# Sample edges
edges = [
{'data': {'source': 'A', 'target': 'B'}},
{'data': {'source': 'B', 'target': 'C'}},
{'data': {'source': 'C', 'target': 'D'}},
{'data': {'source': 'D', 'target': 'E'}},
# Add more edges as needed
]
elements = nodes + edges
# Concentric layout based on the 'year' attribute
concentric_layout = {
'name': 'concentric',
'concentric': lambda node: math.floor(node.data('year') / 100), # Group by century
'levelWidth': lambda nodes: 1, # One level per century
'spacingFactor': 0.5, # Adjust spacing between concentric circles
}
app.layout = html.Div([
cyto.Cytoscape(
id='network',
elements=elements,
layout=concentric_layout,
style={'width': '100%', 'height': '500px'}
)
])
if __name__ == '__main__':
app.run_server(debug=False)
could you please help me in this?
Thanks