In [1]:
from IPython.html import widgets
from IPython.display import display
from d3networkx import ForceDirectedGraph, EventfulGraph, empty_eventfulgraph_hook
Hook into the random_graphs NetworkX code.
In [2]:
from networkx.generators import random_graphs
from networkx.generators import classic
# Add a listener to the eventful graph's construction method.
# If an eventful graph is created, build and show a widget
# for the graph.
def handle_graph(graph):
print(graph.graph._sleep)
graph_widget = ForceDirectedGraph(graph)
display(graph_widget)
EventfulGraph.on_constructed(handle_graph)
# Replace the empty graph of the networkx classic module with
# the eventful graph type.
random_graphs.empty_graph = empty_eventfulgraph_hook(sleep=0.2)
In [3]:
random_graphs.barabasi_albert_graph(15, 1)
Out[3]:
In [4]:
random_graphs.barabasi_albert_graph(15, 2)
Out[4]:
In [5]:
random_graphs.barabasi_albert_graph(10, 5)
Out[5]:
In [6]:
random_graphs.newman_watts_strogatz_graph(15, 3, 0.25)
Out[6]:
In [7]:
classic.barbell_graph(5,0,create_using=EventfulGraph(sleep=0.1))
Out[7]:
In [8]:
classic.circular_ladder_graph(5,create_using=EventfulGraph(sleep=0.1))
Out[8]:
In [9]:
classic.circular_ladder_graph(10,create_using=EventfulGraph(sleep=0.1))
Out[9]:
In [10]:
classic.ladder_graph(10,create_using=EventfulGraph(sleep=0.1))
Out[10]:
In [ ]:
classic.star_graph(10,create_using=EventfulGraph(sleep=0.1))