Ruby + Graph Visualization
August 4, 2008 9:21 AM   Subscribe

Graph Visualization Filter: I need to generate a list of coordinates for the nodes in a large directed, weighted graph from Ruby, given a list of nodes, edges and weights.

I have a list of nodes, edges, and edge weights that describe a graph. I need to generate a list of coordinates for each node, as determined by some graph layout algorithm. I'm looking for something like GraphR or ruby-graphviz but that generate just the intermediate data (coordinates of the nodes) rather than an image. Also, graphviz doesn't handle weighted edges. I know about JUNG, and I know it is possible to make Java and Ruby play nicely together, but doing so exceeds my current level of programming knowledge. One option I've considered is to write the input data to a file from Ruby, run a command-line application to process the data with JUNG from the Ruby app, and then read the JUNG output from a file back into Ruby to generate the output. This involves a lot of disk I/O, though, and I worry that it would not scale well beyond a trivial demo.

Any suggestions for other packages or approaches? I'm a grad student, so commercial tools are probably out.
posted by Alterscape to Computers & Internet (3 answers total)
How important is scalability now? Implmenting your write to disk, process and read system may beef up your programming chops enough to build out the 'real' solution.
posted by askmehow at 9:44 AM on August 4, 2008

I know you said Ruby, but NetworkX (a Python graphing package) does what you need trivially.
Hey, if you know Ruby, it shouldn't take you more than a morning to get up to speed in Python.
posted by signal at 10:21 AM on August 4, 2008

A simple example, assuming you have a file called "graph_nodes.txt" containing:
1 2
2 3
3 1
4 5
4 6
7 1
Then this code:
import networkx as nx

nodelist = file('graph_nodes.txt','r')
for line in nodelist:

layout = nx.spring_layout(G)
for node in layout:
    print node, layout[node]
will output:
1 [ 2.0715818   1.10708002]
3 [ 1.98734639  0.59606008]
2 [ 2.0007399   0.08072112]
5 [-2.02714229  0.46607642]
4 [-1.99032438  0.05927689]
7 [ 2.21386643  1.54009729]
6 [-2.07799444 -0.34268007]

posted by signal at 11:09 AM on August 4, 2008

« Older How many books can an IVAR boo...   |  Is there a way for a hyperlink... Newer »
This thread is closed to new comments.