Interactive graph visualisation

Question:

Situation

Similar to this question, I’m looking for a way to create a GUI where users are able to see a graph (in the graph theory sense) and interact with it. Vehicles will move across the graph from none to node over time. Users should be able to add nodes and edges and add Vehicles and set their destination.

I have already implemented the underlying graph model and business logic, I just need a GUI for it. This means that I do not need graph algorithm functionality such as Djistra’s algorithm.

If possible, the solution should be platform independent. The underlying model is written in python, so the GUI solution either needs to be python based (which would be preferable), or should easily interface with python (potentially IPC).

Performance is a concern. It doesn’t need to be blindingly fast, but it must be fast enough to keep up with the underlying model. Notionally, there is no limit on the number of nodes, edges and vehicles which may be present in the graph.

Possible approaches

I have looked at various visualisation libraries:

I have contemplated using OpenGL.

I have thought about drawing straight to wxPython.

Problems

I haven’t used any of the graph libraries. I don’t know if they are capable of providing the required functionality. For example, matplotlib appears to have a lot of non graph-theory graphs in the gallery. I can’t find an example of someone implementing a graph with it aside from through NetworkX. For another example, can NetworkX plot objects travelling along edges?

An OpenGL solution would almost certainly take more time to implement. I would have to code functions for moving objects across edges myself. I would have to code a function for drawing the edges in the right place, and drawing labels for all of the edges and nodes and vehicles etc. I would need to implement menus and handle interactions from scratch.

I’m not sure how I would go about implementing this in wxPython. I only know how to use it in conjunction with standard widgets. Update: I found this question which has an answer which points to wx.lib.ogl or wx.lib.floatcanvas as a mechanism for implementing a solution in pure wxPython.

Questions

Do any of the visualisation libraries meet my requirements? Of those that do, which are most suited? Are there other libraries I have missed which would meet my requirements? Something like JGraph but for Python instead of Java would be suitable.

What is your opinion on implementing this in OpenGL or wxPython as opposed to one of these libraries?

Are there other approaches I haven’t considered that you think would be appropriate?

Asked By: Spycho

||

Answers:

My gut says that using something like graphviz to render the graphs themselves and wx to deal with your UI is a good way to go. Reimplementing all the graph drawing bits in OpenGL seems like a huge waste of effort. pyGraphViz is very easy to use, so you could probably get something functional quickly and tune as necessary for performance.

Answered By: nmichaels

You might consider the JavaScript library d3. It has some fantastic interactive graph visualisations, and being written in JavaScript it’s great for Web UI

I’m uncertain of the live graph building capabilities, but presume simple node and edge addition/removal would be trivial to implement on top of your chosen visualisation type.

Of course, you’d require something like pyjs to interface d3 with your python code, so it might not be suitable.

Regarding nmichaels’ answer: having used GraphViz extensively, I wouldn’t recommend it for your purpose. It generates beautiful static diagrams but is strictly non-interactive.

Answered By: KomodoDave

You might also want to consider networkx_viewer:
https://github.com/jsexauer/networkx_viewer

Answered By: jsexauer

I ended up finding that the visualisation libraries that I considered were not able to animate objects travelling along edges.

I experimented with wxPython, and its floatcanvas, and found that fairly straight forward to use (substantially simpler than the OpenGL solution would have been). This gave me the freedom to animate as I needed, but didn’t give me any wrappers around displaying connected nodes – I had to write that myself.

This is quite an old question, so there may be other libraries out there now that fulfil this requirement, or it might be that the libraries I considered have advanced and can now do this. If I had to implement it from scratch today, I would be inclined to experiment with a web based UI, potentially utilising web sockets to keep up with the back end in terms of data rate. I don’t know how well the animation would scale though – I’ve found Canvas and SVG get choppy when animating large numbers of things at once. Maybe WebGL would suit better.

Answered By: Spycho
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.