在 JUNG 上重绘图表

发布于 2024-11-08 21:04:01 字数 1186 浏览 6 评论 0 原文

我使用 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);

现在,我想向图形添加更多顶点和边。我该怎么做?我应该运行什么指令才能重新绘制图表?谢谢!

I build a graph using JUNG (Java Universal Network/Graph Framework) with the following code:

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

Now, I want to add more vertices and edges to the graph.. how can I do this? What instructions should I run for the graph to be redrawn? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

山田美奈子 2024-11-15 21:04:01

向图形添加边和顶点后,必须调用 vv.repaint() 来绘制更改。

After adding edges and vertices to the graph, you must call vv.repaint() to draw the changes.

自由如风 2024-11-15 21:04:01

如果您希望在用户交互后重绘图形,则必须将 EditingModalGraphMouse 添加到 VisualizationViewer

    EditingModalGraphMouse gm = new EditingModalGraphMouse(vv.getRenderContext(), 
             vertexFactory, edgeFactory); 
    vv.setGraphMouse(gm);

构造函数必须提供 vertexFactoryedgeFactory 派生对象,

Factory<E> and Factory<V>

create() 方法创建边/顶点类的新实例

Factory <BusStop> vertexFactory = new Factory<BusStop>() {
            public BusStop create() {
                return new BusStop();
            }
        };

其工作是通过与 edgeFactory 相同的

If you are looking for redrawing the graph after user interaction, you have to add an EditingModalGraphMouse to your VisualizationViewer

    EditingModalGraphMouse gm = new EditingModalGraphMouse(vv.getRenderContext(), 
             vertexFactory, edgeFactory); 
    vv.setGraphMouse(gm);

the constructor must be fed with vertexFactory and edgeFactory objects derived from

Factory<E> and Factory<V>

whose job is to create a new instance of edge/vertices class via the create() method

Factory <BusStop> vertexFactory = new Factory<BusStop>() {
            public BusStop create() {
                return new BusStop();
            }
        };

same for the edgeFactory

秋日私语 2024-11-15 21:04:01

如果您想添加顶点和边:

//add some Vertex and Edges
g.addVertex((BusStop)obj1);
g.addVertex((BusStop)obj2);
g.addEdge((Travel) trv1, obj1, obj2);

例如,请参阅 addVertex 和 addEdge /JUNG/SimpleGraphView.java" rel="nofollow">SimpleGraphView.java

If you want to add vertices and edges:

//add some Vertex and Edges
g.addVertex((BusStop)obj1);
g.addVertex((BusStop)obj2);
g.addEdge((Travel) trv1, obj1, obj2);

For example see how addVertex and addEdge is being used in SimpleGraphView.java

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文