在 JUNG 上重绘图表
我使用 JUNG(Java 通用网络/图形框架)构建一个图形,代码如下:
g = new SparseMultigraph<BusStop, Travel>();
//add some Vertex and Edges
Layout<String, String> layout1 = new CircleLayout(g);
layout1.setSize(new Dimension(300,300)); // sets the initial size of the layout space
VisualizationViewer vv = new VisualizationViewer(layout1);
vv.setPreferredSize(new Dimension(350,350)); //Sets the viewing area size
Transformer<BusStop,Paint> vertexPaint = new Transformer<BusStop,Paint>() {
public Paint transform(BusStop b) {
return Color.GREEN;
}
};
Transformer<BusStop,Shape> vertexShape = new Transformer<BusStop,Shape>() {
public Shape transform(BusStop b) {
return new Rectangle(-20, -10, 40, 20);
}
};
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
vv.getRenderContext().setVertexShapeTransformer(vertexShape);
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
GraphViewerForm = new edu.uci.ics.jung.visualization.GraphZoomScrollPane(vv);
现在,我想向图形添加更多顶点和边。我该怎么做?我应该运行什么指令才能重新绘制图表?谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
向图形添加边和顶点后,必须调用 vv.repaint() 来绘制更改。
After adding edges and vertices to the graph, you must call
vv.repaint()
to draw the changes.如果您希望在用户交互后重绘图形,则必须将 EditingModalGraphMouse 添加到 VisualizationViewer
构造函数必须提供 vertexFactory 和edgeFactory 派生对象,
create() 方法创建边/顶点类的新实例
其工作是通过与 edgeFactory 相同的
If you are looking for redrawing the graph after user interaction, you have to add an EditingModalGraphMouse to your VisualizationViewer
the constructor must be fed with vertexFactory and edgeFactory objects derived from
whose job is to create a new instance of edge/vertices class via the create() method
same for the edgeFactory
如果您想添加顶点和边:
例如,请参阅 addVertex 和 addEdge /JUNG/SimpleGraphView.java" rel="nofollow">SimpleGraphView.java
If you want to add vertices and edges:
For example see how addVertex and addEdge is being used in SimpleGraphView.java