0
votes

I am using prefuse lately to make some visualizations. What I do is I load some information from a database, make a prefuse table instance for them and make a graph based on that information. This works fine.

My question is how can I create the edges for that graph??

I assume I must create another table to hold the edges but i don't know the way to create that thing... Any help appreciated! Thank you!

That's my code for setting up the data for the graph:

    Table nodeData = null;
    String query1 = "my_select_statement";

    try {
        nodeData = datasrc.getData(query1);

    } catch (DataIOException ex) {
        ex.getMessage();
        ex.printStackTrace();
    }

Graph graph = new Graph(nodeData, true);
1

1 Answers

0
votes

There is a constructor for a prefuse Graph that takes an edge table, as you suggest:

public Graph(Table nodes, Table edges, boolean directed)

I suggest you check out this very simple space delimited matrix reader for reference: https://github.com/brycecr/msmexplorer/blob/master/MSMExplorer/src/edu/stanford/folding/msmexplorer/io/DatGraphReader.java

In short, you do just create a table, but you need "source" and "target" columns where the entries into those columns are 0-indexed indicies into the node table. Creating the columns:

m_edgeTable = new Table();
m_edgeTable.addColumn(Graph.DEFAULT_SOURCE_KEY, int.class); //0th
m_edgeTable.addColumn(Graph.DEFAULT_TARGET_KEY, int.class); //1st

assigning source & target columns:

m_edgeTable.addRow();
m_edgeTable.set(rowNum, 0, sourceNodeIndex);
m_edgeTable.set(rowNum, 1, targetNodeIndex);

You had the right idea!

P.S.: If you're writing a graph reader, as it appears you are, I really recommend subclassing AbstractGraphReader. It will make your life easier down the road, as you can use your new class in the same way as the built in graph readers.