JointJS 曼哈顿路由器不将标签视为障碍。如何在标签不重叠的情况下路由 link?

JointJS Manhattan Router not counting labels as obstacles. How to route link without overlapping labels?

我的应用程序使用 jointjs's manhattan router 自动路由一些连接线。我遇到的问题是:

我认为我需要编辑的文件是:

https://github.com/clientIO/joint/blob/master/plugins/routers/joint.routers.manhattan.js

请查看这些图片以更好地了解我在说什么:

之前曼哈顿路线:

曼哈顿路线之后:

我的目标是什么:

我试过使用其他路由器,但它们对我的特定应用来说要差得多。

我的配置如下:

        link.set('router', {
            name: 'manhattan',
            args: {
                startDirections: ['bottom']
            }
        });

我一直在看 joint.routers.manhattan.js 但它很复杂...

有谁知道我可以在 joint.routers.manhattan.js 中修改什么,以便 标签被视为障碍

可能的解决方案:

我学到的一些东西对我有帮助:

  • 链接不是元素。当您执行 graph.getElements() 时,列表将不包含任何链接。在 javascript 控制台中尝试 运行 这个:

        var map = graph.getElements()
        for(var m=0; m<map.length; m++)
        {
            console.log("Type: "+map[m].get('type')+", Bounding Box: "+map[m].getBBox());
        }
    
  • 更改 stepmaximumLoops 选项可能会有所帮助:

        link.set('router', {
            name: 'manhattan',
            args: {
                startDirections: ['bottom'],
                step: 10, 
                maximumLoops: 500
            }
        });
    
  • 解决此问题的一种方法是 增加链接太近的元素的 getBBox
  • 另一种增加障碍物大小的方法是增加曼哈顿路由器的opt.paddingBox变量。如果您查看源代码,它正是在做我需要的:

        // expand elements boxes by specific padding
        .invoke('moveAndExpand', opt.paddingBox)
    

我最终使用上面列出的最后一个建议向 manhattan 文件添加了额外的填充。