コード例 #1
0
    def to_pyvis(self, max_vertices: int = 5000) -> Network:
        """Convert this graph into a PyVis Network object.

        max_vertices specifies the maximum number of vertices that can appear in the graph.

        NOTE: Running this method withough iPython may result in KeyErrors
        """
        graph_pyvis = Network()
        for v in self._vertices.values():
            graph_pyvis.add_node(v.item)

            for u in v.neighbours:
                if graph_pyvis.num_nodes() < max_vertices:
                    graph_pyvis.add_node(u.item)

                if u.item in graph_pyvis.get_nodes():
                    graph_pyvis.add_edge(v.item, u.item)

            if graph_pyvis.num_nodes() >= max_vertices:
                break

        return graph_pyvis
コード例 #2
0
    new_countryname = entry['countryname']
    new_countryname = '{}'.format(new_countryname)
    if new_countryname != "":
        g.add_node(new_countryname, color="#39af8e")

    if new_countryname != "":
        if new_isp != "":
            g.add_edge(new_countryname, new_isp)

    url_number += 1

#Checking for size/value of nodes
neighbor_map = g.get_adj_list()
for node in g.nodes:
    node["value"] = len(neighbor_map[node["id"]])

print("URLs: " + str(url_counter))
print("Nodes: " + str(g.num_nodes()))
print("Edges: " + str(g.num_edges()))

#g.show("network.html")
g.show(column + "_" + compare + "_" + search + "_network.html")
print("File generated: " + column + "_" + compare + "_" + search +
      "_network.html")

#If you don't want to automatically open the current html file in your browser comment the 3 lines below
new_tab = 2
file = "file://" + os.getcwd(
) + "/" + column + "_" + compare + "_" + search + "_network.html"
webbrowser.open(file, new=new_tab)