jsexauer / networkx_viewer

Interactive GUI for NetworkX graphs
GNU General Public License v3.0
137 stars 27 forks source link

How can I change it to support DiGraph #5

Closed ciaojo closed 9 years ago

ciaojo commented 9 years ago

Hi, thank you for this interesting Library and great project. I want to change it to support direct graph?? where is the main draw that draw the graph in the canvas, is it in the graph_canvas file? I want to do sm like this??? figure_1

thank you in advance

ciaojo commented 9 years ago

mayby I can use convert_to_directed(MultiGraph) to convert it, but I can't understand where is the main draw function that draw the G in canvas?? thank you

ciaojo commented 9 years ago

I saw that you create nodes and lines to draw the graph. I have tried to use arrow but its not working, my code:

G = nx.MultiGraph()
G.add_edge('Arg2','Arg1')
G.add_edge('Arg3','Arg1',0,{'fill':'green', 'arrow':'last'})
G.add_edge('Arg4','Arg2')
G.add_edge('Arg5','Arg2')
G.add_edge('Arg6','Arg3')
G.node['Arg2']['outline'] = 'blue'
G.node['Arg1']['label_fill'] = 'red' 
app = Viewer(G)
app.mainloop()

the result graph is the same (with or without 'arrow'), I dont know where is the problem. i want to have an graph to represent nodes with arrows to show which node attack others.

can you help me??? thank you and sorry for all these questions.

jsexauer commented 9 years ago

You're on the right track. The issue is that the node is a canvas widget, which is drawn over the ends of the lines. The arrow by default is so small that it is hidden by the node.

I've modified the code to support directed graphs, but it's not super pretty. A better way would be to use a bounding box for the nodes and attach the edges to the ends of the bounding box. But that's pretty hard.

Here is what my rudimentary support will give you:

### Example 3 ###
G = nx.MultiDiGraph()
G.add_edge('Arg2','Arg1')
G.add_edge('Arg3','Arg1',0)
G.add_edge('Arg3','Arg1',1)
G.add_edge('Arg4','Arg2')
G.add_edge('Arg5','Arg2')
G.add_edge('Arg6','Arg3')
G.node['Arg2']['outline'] = 'blue'
G.node['Arg1']['label_fill'] = 'red'
app = Viewer(G)
app.mainloop()

image

ciaojo commented 9 years ago

thanks a lot for you help ;) . Now i'm trying to modify it to support add nodes and edges. its pretty hard

jsexauer commented 9 years ago

If you end up writting something to add nodes, feel free to make a PR.