如何获取 JUNG 中的边缘标签和值?

发布于 2024-12-16 17:49:45 字数 1686 浏览 1 评论 0原文

我对 JUNG 和边缘(顶点)标签有疑问。

我的应用程序是基于 JUNG 的。它需要从给定的图表中计算一些值。图表需要“手动”淹没,并且在该图表上我需要设置“起始值”。我正在考虑使用该值的标签(顶点的名称,边的长度)。

现在,我可以画一个图表了;我可以获取顶点和边的数量,但我不知道如何获取标签和值。

我尝试对边和顶点使用自定义类,但我根本不知道如何设置标签。

这是我的代码的一部分。它取自文档。有人可以告诉我要更改什么,以便我可以在绘制图形时设置标签,然后检索值吗?

graph = new SparseMultigraph<Number, Number>();

    this.layout = new StaticLayout<Number, Number>(graph,
            new Dimension(600, 600));

    vv = new VisualizationViewer<Number, Number>(layout);
    vv.setBackground(Color.white);

    vv.getRenderContext().setVertexLabelTransformer(
            MapTransformer.<Number, String>getInstance(LazyMap.<Number, String>decorate(
            new HashMap<Number, String>(),
            new ToStringLabeller<Number>())));

    vv.getRenderContext().setEdgeLabelTransformer(
            MapTransformer.<Number, String>getInstance(LazyMap.<Number, String>decorate(
            new HashMap<Number, String>(),
            new ToStringLabeller<Number>())));

    vv.setVertexToolTipTransformer(vv.getRenderContext().getVertexLabelTransformer());

    Container content = getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);
    Factory<Number> vertexFactory = new VertexFactory();
    Factory<Number> edgeFactory = new EdgeFactory();

    final EditingModalGraphMouse<Number, Number> graphMouse = new EditingModalGraphMouse<Number, Number>(
            vv.getRenderContext(), vertexFactory, edgeFactory);

    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

I have problem with JUNG and edge (vertex) labels.

My application is based on JUNG. It needs to calculate some values from given graph. Graph needs to be drown "by hand", and on that graph I need to set "starting values". I was thinking to use labels for that values (names for vertex, length for edges).

Now, I can draw a graph; I can get the number of vertexes and edges, but I don't know how to get the labels and values.

I tried using custom classes for edges and vertexes, but than I don't know how to set labels at all.

This is part of my code. It is taken from documentation. Can somebody tell me what to change so I can set labels while drawing graph and after that retrieve values?

graph = new SparseMultigraph<Number, Number>();

    this.layout = new StaticLayout<Number, Number>(graph,
            new Dimension(600, 600));

    vv = new VisualizationViewer<Number, Number>(layout);
    vv.setBackground(Color.white);

    vv.getRenderContext().setVertexLabelTransformer(
            MapTransformer.<Number, String>getInstance(LazyMap.<Number, String>decorate(
            new HashMap<Number, String>(),
            new ToStringLabeller<Number>())));

    vv.getRenderContext().setEdgeLabelTransformer(
            MapTransformer.<Number, String>getInstance(LazyMap.<Number, String>decorate(
            new HashMap<Number, String>(),
            new ToStringLabeller<Number>())));

    vv.setVertexToolTipTransformer(vv.getRenderContext().getVertexLabelTransformer());

    Container content = getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);
    Factory<Number> vertexFactory = new VertexFactory();
    Factory<Number> edgeFactory = new EdgeFactory();

    final EditingModalGraphMouse<Number, Number> graphMouse = new EditingModalGraphMouse<Number, Number>(
            vv.getRenderContext(), vertexFactory, edgeFactory);

    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

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

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

发布评论

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

评论(1

幸福%小乖 2024-12-23 17:49:45

您可以使用此方法在 jung 中设置边缘标签。

edgeName : your edge name

vv.getRenderContext().setEdgeLabelRenderer(new Transformer<String, String>()  {
    @Override
    public String transform(String edgeName) {
       String label;                
       //map your label to your edgeName
       return label;
    }
});

对于顶点依此类推

you can use this method to set labels in jung for edges.

edgeName : your edge name

vv.getRenderContext().setEdgeLabelRenderer(new Transformer<String, String>()  {
    @Override
    public String transform(String edgeName) {
       String label;                
       //map your label to your edgeName
       return label;
    }
});

and so on for vertex

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