简体   繁体   English

从Prefuse图中删除节点

[英]Removing nodes from a Prefuse graph

I'm trying to create a dynamically-updated Prefuse graph, where nodes are added and deleted regularly. 我正在尝试创建动态更新的Prefuse图,其中定期添加和删除节点。 I've been able to add nodes and edges fine, and then delete them, but I get exceptions when I try to add edges to the next set of nodes. 我已经能够很好地添加节点和边,然后删除它们,但是当我尝试将边添加到下一组节点时,我得到了例外。 Does anyone know of any pitfalls in removing nodes from a Prefuse graph? 有人知道从Prefuse图中删除节点有什么陷阱吗? Or, does anyone know a better way to interact with a Prefuse graph dynamically? 或者,没有人知道更好的与Prefuse图动态交互的方法吗?

(Note that the display is updating fine; at all times the display seems to match the contents of the graph. This isn't a dupe of Prefuse Toolkit: dynamically adding nodes and edges ) (请注意,显示正在良好地更新;在任何时候,显示似乎都与图的内容匹配。这并不是Prefuse Toolkit复制品:动态添加节点和边

Code excerpts: 代码摘录:

// Set up edge and node tables
Schema node_schema = new Schema();
Schema edge_schema = new Schema();
node_schema.addColumn("node_info", NodeInfo.class);
edge_schema.addColumn("source", int.class, 0);
edge_schema.addColumn("target", int.class, 0);
edge_schema.addColumn("edge_info", EdgeInfo.class);
graph_nodes = node_schema.instantiate();
graph_edges = edge_schema.instantiate();

...

// Set up visualization
graph = new Graph(graph_nodes, graph_edges, false);
vis_panel = new MyVisPanel(graph);

...

// Add nodes & edges
int new_node_1 = graph_nodes.addRow();
graph_nodes.set(new_node_1, "node_info", new NodeInfo());
int new_node_2 = graph_nodes.addRow();
graph_nodes.set(new_node_2, "node_info", new NodeInfo());
int new_edge = graph_edges.addRow();
graph_edges.set(new_edge, "target", new_node_1);
graph_edges.set(new_edge, "source", new_node_2);

... 

// Remove nodes
TupleSet nodes = graph.getNodes();
Iterator iter = nodes.tuples(my_predicate);
while(iter.hasNext())
{
    int row_to_delete = ((Tuple) iter.next()).getRow();
    if(graph.removeNode(row_to_delete))
    {
        System.out.println("Removed row " + row_to_delete);
    }
}

...

// Add nodes & edges again
int new_node_1 = graph_nodes.addRow();
graph_nodes.set(new_node_1, "node_info", new NodeInfo());
int new_node_2 = graph_nodes.addRow();
graph_nodes.set(new_node_2, "node_info", new NodeInfo());
int new_edge = graph_edges.addRow(); // <<-- Exception is thrown here
graph_edges.set(new_edge, "target", new_node_1);
graph_edges.set(new_edge, "source", new_node_2);

The exception I get is: 我得到的异常是:

java.lang.IllegalArgumentException: Row index out of bounds: -1
    at prefuse.data.column.IntColumn.getInt(Unknown Source)
    at prefuse.data.Table.getInt(Unknown Source)
    at prefuse.data.Graph.updateDegrees(Unknown Source)
    at prefuse.data.Graph.updateDegrees(Unknown Source)
    at prefuse.data.Graph$Listener.tableChanged(Unknown Source)
    at prefuse.data.Table.fireTableEvent(Unknown Source)
    at prefuse.data.Table.addRow(Unknown Source)
    at my_pkg.addSomeNodesFunction(my_code.java:99)

I have not used the standard Graph.addNode() and addEdge() methods, because it seemed harder to set edge information that way. 我没有使用标准的Graph.addNode()和addEdge()方法,因为用这种方法设置边缘信息似乎更加困难。 (if there's a better way to do this, let me know!) The delete is succeeding, in that graph.getNodeCount() and graph.getEdgeCount() return smaller numbers after deleting the nodes. (如果有更好的方法,请告诉我!)删除成功,因为在删除节点之后,graph.getNodeCount()和graph.getEdgeCount()返回的数字较小。

Any ideas? 有任何想法吗?

After more investigation this appears to be a minor bug in prefuse. 经过更多调查后,这似乎是一个很小的错误。 Calls to addEdge first initialize the source and target node numbers to 0, after which the graph tries to update its degree counts, which fails if node 0 does not exist. 调用addEdge首先将源和目标节点号初始化为0,此后图形尝试更新其度数计数,如果节点0不存在则失败。 See bug report 3529747 on their SF page for more information. 有关更多信息,请参见其 SF页面上的错误报告3529747

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM