简体   繁体   English

荣-带有图标的边缘

[英]JUNG - Edges with icons

I am using JUNG for displaying network devices as graphs. 我正在使用JUNG将网络设备显示为图形。 Each edge is a link between two network elements. 每个边缘是两个网络元素之间的链接。 I want to add a picture exactly in the middle of the link. 我想在链接的正中间添加图片。 Currently my link looks like this: enter image description here 目前,我的链接如下所示: 在此处输入图片描述

The code for it is: 它的代码是:

vv.getRenderContext().setEdgeLabelTransformer(new Function<GraphLink,String>() {
            URL url = getClass().getResource("/icons/model/conn.radio.png");
            public String apply(GraphLink input) {
                return "<html><img src="+url+" height=14 width=14>";
            }});

As you can see the icon is adjacent with the link. 如您所见,该图标与链接相邻。 Is there any option so the link could split the icon in two equals parts? 是否有任何选择,以便链接可以将图标分为两个相等的部分?

tl;dr You want to tweak the edge label offset. tl; dr您想调整边缘标签的偏移量。

The position of the edge label is specified by a couple of properties, both accessible via the RenderContext : 边缘标签的位置由几个属性指定,这两个属性均可通过RenderContext访问:

  • The EdgeLabelClosenessTransformer, which should return a value in the range [0, 1], specifies the position of the label along the edge, that is, whether it should be closer to the source node (0) or the target node (1). EdgeLabelClosenessTransformer应返回[0,1]范围内的值,它指定标签沿边缘的位置,即是否应更靠近源节点(0)或目标节点(1)。
  • The edge label offset, which should return the distance from the edge to its label. 边缘标签偏移量,应返回从边缘到其标签的距离。

You can see how these properties are used (by default) in BasicEdgeLabelRenderer . 您可以在BasicEdgeLabelRenderer中查看如何使用这些属性(默认情况下)。

By default, the edge label offset is set to 10, which should make the edge label fairly close to, but not on top of, the edge. 默认情况下,边缘标签的偏移量设置为10,这将使边缘标签相当接近但不在边缘上方。 If you set it to 0: 如果将其设置为0:

vv.getRenderContext().setLabelOffset(0);

Then that should do what you want. 那应该做你想要的。

You may find it useful to experiment with EdgeLabelDemo . 您可能会发现尝试使用EdgeLabelDemo很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM