如何防止节点重叠

发布于 2025-01-10 11:40:53 字数 363 浏览 5 评论 0原文

如何防止图中的节点相互堆叠?我希望节点之间有一个最小距离,如果有人将一个节点拖到另一个节点上,图表会向用户抛出错误。我看到了这个解决方案并尝试了它,但它不起作用 防止 JGraphX 中的节点重叠

我会很感激任何想法。

节点重叠

How do I prevent nodes in a graph from stacking on each other? I want there to be a minimum distance between nodes and if someone was to drag a node over another the graph throws an error to the user. I saw this solution and tried it but it doesnt work Prevent node overlap in JGraphX

I'll appreciate any ideas.

Nodes overlapping

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

℉絮湮 2025-01-17 11:40:53

要自动重新排列图表并使其之间有一定距离,您可以尝试使用类似以下的方法:

let layout = new mxHierarchicalLayout(this.graph, mxConstants.DIRECTION_WEST);
layout.intraCellSpacing = 50; //horizontal
layout.interRankCellSpacing = 200; //vertical
layout.execute(this.parent);

mxHierarchicalLayout 方法将自动重新排列当前节点。其他两个设置将在它们之间提供间距(水平和垂直)

此外,在渲染屏幕之前运行此设置,或者如果您想在显示已经渲染后进行更改,只需 this.graph.refresh() (如果需要)

For rearranging your diagram automatically with some distance between them you can try to use something like this:

let layout = new mxHierarchicalLayout(this.graph, mxConstants.DIRECTION_WEST);
layout.intraCellSpacing = 50; //horizontal
layout.interRankCellSpacing = 200; //vertical
layout.execute(this.parent);

The mxHierarchicalLayout method will automatically rearrange your current nodes. The other two settings will give spacing between them ( horizontally and vertically )

Also, run this before rendering the screen or if you want to change after the display has already rendered, just this.graph.refresh() if needed

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文