[英]Prefuse API java creating edges
I am using prefuse lately to make some visualizations. 我最近正在使用prefuse进行一些可视化。 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);
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 我建议您检查一下这个非常简单的用空格分隔的矩阵阅读器,以供参考: 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. 简而言之,您只是创建一个表,但是需要“源”和“目标”列,其中这些列中的条目是节点表中的0索引索引。 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! 您有正确的主意!
PS: If you're writing a graph reader, as it appears you are, I really recommend subclassing AbstractGraphReader
. PS:如果您正在编写一个图形阅读器,看起来确实是这样,那么我真的建议对AbstractGraphReader
子类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. 这将使您的生活更轻松,因为您可以像使用内置图形阅读器一样使用新类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.