import matplotlib.pyplot as plt
import networkx as nx
import anywidget
from pathlib import Path
from traitlets import List
#G = nx.cubical_graph()
#G = nx.tutte_graph()
#G = nx.frucht_graph()
G = nx.icosahedral_graph()
#node_positions = nx.spectral_layout(G, dim=3)
node_positions = nx.spring_layout(G, dim=3)
position_extracted = list(node_positions.values())
position_list = [list(position) for position in position_extracted]
# Extract edges with start and end points
edges = []
for edge in G.edges():
start, end = edge
start_pos = node_positions[start]
end_pos = node_positions[end]
edges.append([list(start_pos), list(end_pos)])
print("Node Positions:", position_list)
print("Type of node_positions:", type(position_list))
print("Edges:", edges)
print("Type of edges:", type(edges))
class HelloWidget(anywidget.AnyWidget):
_esm = Path("widget.js")
node_positions = List().tag(sync=True)
edges = List().tag(sync=True)
three_viewer = HelloWidget()
three_viewer.node_positions = position_list
three_viewer.edges = edges
page = three_viewer