如何获取 JUNG 中的边缘标签和值?
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用此方法在 jung 中设置边缘标签。
对于顶点依此类推
you can use this method to set labels in jung for edges.
and so on for vertex