예제 #1
0
 def load_data(self, graph, positions=None):
     "Load and draw a graph and positions to the network display."
     if positions is None:
         self.info_area.value = "Computing default layout: " + repr(graph.sizes())
         fit = self.fit_heuristic(graph)
         positions = dLayout.group_layout(graph, fit=fit)
     self.data_positions = positions
     self.display_positions = positions.copy()
     self.data_graph = graph
     self.display_graph = graph.clone()
     ew = graph.edge_weights
     maxw = max(abs(ew[e]) for e in ew) + 1.0
     self.threshhold_slider.max = maxw
     self.do_threshhold()
     self.draw()
예제 #2
0
 def layout_click(self, b):
     "Apply the current layout to the viewable graph."
     self.info_area.value = "layout clicked"
     if not self.loaded:
         self.info_area.value = "Cannot layout: no graph loaded"
     dG = self.display_graph
     fit = self.fit_heuristic(dG)
     layout_selection = self.layout_dropdown.value
     try:
         if layout_selection == "skeleton":
             self.display_positions = dLayout.group_layout(dG, fit=fit)
         else:
             self.display_positions = dLayout.iGraphLayout(dG, layout_selection, fit)
     except Exception as e:
         self.info_area.value = repr(layout_selection) + " layout failed: " + repr(e)
     else:
         self.svg.empty()
         self.draw()
예제 #3
0
def display_network(filename, N=None, threshhold=20.0, save_layout=True, show=True):
    import dLayout
    import getData
    assert os.path.exists(filename)
    print ("Reading network", filename)
    G = getData.read_network(filename)
    layoutpath = filename + ".layout.json"
    if os.path.exists(layoutpath):
        print ("Loading saved layout", layoutpath)
        layout = dLayout.load(layoutpath)
    else:
        print ("Computing layout")
        layout = dLayout.group_layout(G)
        if save_layout:
            print ("Saving layout", layoutpath)
            dLayout.dump(layout, layoutpath)
    if N is None:
        N = NetworkDisplay()
    if threshhold:
        N.threshhold_slider.value = threshhold
    N.load_data(G, layout)
    if show:
        N.show()
    return N