English 中文(简体)
从预要图形中删除节点
原标题:Removing nodes from a Prefuse graph

我试图创建一个动态更新的前节点图形, 其中节点会添加并定期删除。 我曾经能够添加节点和边缘, 然后删除它们, 但我在试图为下一组节点添加边点时会得到例外。 有人知道在删除预点图中的节点时会有什么陷阱吗? 或者, 有人知道一个更好的方法可以动态地与预点图互动吗?

(注意显示器更新精美; 显示时时刻刻似乎都符合图表的内容 。 这不是< a href=> https:// stackoverflow. com/ questions/ 502763/ prefuse- toolkit- hollowkit- alive- adding- nodes- and- sedges> 预设工具箱: 动态添加节点和边缘 )

《守则》节录:

// 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);

我得到的例外是:

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)

我还没有使用标准图.addNode () 和添加 Edge () 的方法, 因为这样设置边缘信息似乎比较困难 。 (如果有更好的方法的话, 请让我知道! ) 。 删除成功, 在那个图中 。 get NodeCount () 和 图中 。 getEdgeCount () 在删除节点后返回较小数字 。

有什么想法吗?

最佳回答

进行更多调查后, 这似乎在预设时是一个小错误 。 请求添加 Edge 首个初始化源和目标节点编号为 0, 之后图试图更新其度计数, 如果没有节点 0, 则无法更新 。 请参见 错误报告 < a href=" https:// sourceforge. net/ tracker/? func= detail& aid= 3529747& group_ id=98962& atid=622645" rel=" no follow" > 3529747 , 请在 SF 页面上查看更多信息 。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签