与JGraphx重叠的边缘

编程入门 行业动态 更新时间:2024-10-25 00:31:24
本文介绍了与JGraphx重叠的边缘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用JgraphX构建图形.有向图表示道路和交叉路口.我为每条路线定义了两条边,每个方向一条.

I'm building a graph with JgraphX. The directed graph represent roads and intersections. For every route I define two edges, one for each direction.

结果,图形的图像的两个边缘(代表道路)重叠.如何避免这种情况?顶点是否有诸如边缘的锚点之类的东西?如果是这样,我该如何定义它们?

As result, the image of the graph has the two edges (representing the road) overlapped. How can I avoid this? Does the vertex have some things like anchor points for the edges? If so, how can I define them?

这是我用来显示图形的代码

This is the code I use to display graph

package it.rex.view; import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import org.jgrapht.ListenableGraph; import org.jgrapht.ext.JGraphXAdapter; import org.jgrapht.graph.ListenableDirectedGraph; import com.mxgraph.layout.mxCircleLayout; import com.mxgraph.layout.mxIGraphLayout; import com.mxgraph.swing.mxGraphComponent; //import grafotest1.DemoWeightedGraph.MyEdge; import it.rex.model.Incrocio; import it.rex.model.Strada; import javax.swing.JScrollPane; public class StradarioView extends JFrame { /** * Create the frame. */ public StradarioView(ListenableGraph<Incrocio, Strada> listenableGraph) { // Graph come from JgraphT JGraphXAdapter<Incrocio, Strada> graphAdapter = new JGraphXAdapter<Incrocio, Strada>(listenableGraph); mxIGraphLayout layout = new mxCircleLayout(graphAdapter); layout.execute(graphAdapter.getDefaultParent()); mxGraphComponent graphComponent = new mxGraphComponent(graphAdapter); getContentPane().add(graphComponent, BorderLayout.CENTER); setTitle("Stradario"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); pack(); add(graphComponent); } }

这是边缘重叠的结果:

推荐答案

您已在此处使用圆形布局".

You have used the Circle Layout here.

mxIGraphLayout layout = new mxCircleLayout(graphAdapter);

圆形布局将节点放置在一个圆形中,但是它与两个方向相反的节点之间的边缘重叠.相反,您可以尝试使用mxParallelEdgeLayout.如果两个边缘重叠,则会将其分开.

Circle Layout places the nodes in a circle but it overlaps the edges between two nodes which are in opposite direction. Instead you can try using the mxParallelEdgeLayout. This will separate the two edges if they are overlapping.

尝试一下:

mxParallelEdgeLayout layout = new mxParallelEdgeLayout(graphAdapter);

下图显示了两个连接的节点,它们在e和b之间有两个沿相反方向的边缘.这就是mxParallelEdgeLayout以相同的方向显示相同两个节点之间的两个边缘的方法

The following picture shows two connected nodes which has two edges between e and b, which are in opposite directions. That is how the mxParallelEdgeLayout displays two edges between the same two nodes in opposite directions

希望这会有所帮助!

更多推荐

与JGraphx重叠的边缘

本文发布于:2023-10-13 17:20:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1488608.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:边缘   JGraphx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!