与JGraphx重叠的边缘 [英] Overlapping edges with JGraphx

查看:80
本文介绍了与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重叠的边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆