Ejemplo n.º 1
0
def draw_graph(BR,endpoint,workbook):
    import networkx
    import matplotlib.pyplot as plt
    import fetch
    import layout
    lables = {}
    lables["BR"]= "BR"
    graph_obj = networkx.DiGraph()
    nodes = fetch.get_motes(BR,endpoint)
    graph_obj.add_node("BR")
    for node in nodes:
        graph_obj.add_node(node)

    edges = fetch.get_routes(BR,endpoint)
    for edge in edges:
        edge = edge.split('->')
        source = edge[1]
        destination = edge[0]
        Name = get_name(edge[0],workbook)
        lables[edge[0]]= Name
        if source == destination:
            graph_obj.add_edge("BR",destination)
        else:
            graph_obj.add_edge(source,destination)


    pos = layout.get_pos(graph_obj)
    networkx.draw_networkx_labels(graph_obj, pos,labels=lables,font_color="black", font_size=8,font_weight='bold')
    networkx.draw(graph_obj, pos,nodelist = ["BR"], node_color="Blue", node_size=2000,node_shape="p")
    networkx.draw(graph_obj, pos,nodelist = nodes, node_color="green",node_size=1000,node_shape="s")
    plt.show()
Ejemplo n.º 2
0
def Refresd_graph():
    plt.clf()
    pos = layout.get_pos(graph_obj)
    networkx.draw(graph_obj,pos,nodelist=["BR"],with_labels=True,node_size=800,node_color="blue",node_shape="p")
    networkx.draw(graph_obj,pos,nodelist=node_list,with_labels=True,node_size=600,node_color=color)
    xlim(0,200)
    ylim(0,200)
    plt.show()
Ejemplo n.º 3
0
def Refresd_graph():
    plt.clf()
    pos = layout.get_pos(graph_obj)
    networkx.draw(graph_obj,
                  pos,
                  nodelist=["BR"],
                  with_labels=True,
                  node_size=800,
                  node_color="blue",
                  node_shape="p")
    networkx.draw(graph_obj,
                  pos,
                  nodelist=node_list,
                  with_labels=True,
                  node_size=600,
                  node_color=color)
    xlim(0, 200)
    ylim(0, 200)
    plt.show()
Ejemplo n.º 4
0
    (x, y) = (event.xdata, event.ydata)
    print x, y
    for i in graph_obj.nodes():
        node = pos[i]
        distance = pow(x - node[0], 2) + pow(y - node[1], 2)
        if distance < 20 and i != "BR":
            print "you clicked %s" % (i)

            if color[count] == "red":
                color[count] = "green"
            else:
                color[count] = "red"
        count = count + 1
    print color
    node_list = []
    Refresd_graph()


fig, ax = plt.subplots()
fig.canvas.mpl_connect('button_press_event', onClick)

graph_obj = networkx.DiGraph()
graph_obj.add_node("BR")

for nodes in range(1, 10):
    graph_obj.add_node(nodes)
    graph_obj.add_edge("BR", nodes)
    node_list.append(nodes)
    color.append("red")
pos = layout.get_pos(graph_obj)
Refresd_graph()
Ejemplo n.º 5
0
def onClick(event):
    count = 0
    (x,y)   = (event.xdata, event.ydata)
    print x,y
    for i in graph_obj.nodes():
        node = pos[i]
        distance = pow(x-node[0],2)+pow(y-node[1],2)
        if distance < 20 and i != "BR":
            print "you clicked %s" % (i)

            if color[count] == "red":
                color[count] = "green"
            else:
                color[count] = "red"
        count = count + 1
    print color
    node_list = []
    Refresd_graph()
fig, ax = plt.subplots()
fig.canvas.mpl_connect('button_press_event', onClick)

graph_obj = networkx.DiGraph()
graph_obj.add_node("BR")

for nodes in range(1,10):
    graph_obj.add_node(nodes)
    graph_obj.add_edge("BR",nodes)
    node_list.append(nodes)
    color.append("red")
pos = layout.get_pos(graph_obj)
Refresd_graph()