英文:
Prevent overlapping of nodes in GoJs
问题
我有一个包含节点位置详细信息的图表。
我尝试通过简单地扩大节点大小来创建另一个图表。
一切都运行正常,但新图表中的节点重叠在一起。我理解这是因为现在的节点更大,但是否有一种GoJs方式可以按照我给定的位置点来防止重叠?
注意:我只是使用了面板、形状和文本块。我没有使用部件、布局等。
英文:
I have a graph with details of its node positions.
I am trying to create another graph by simply expanding the node size.
Everything works fine but the nodes in new graph are overlapping each other. I understand the reason is because of the nodes which are now bigger, but is there a GoJs way to prevent overlapping by following the location points I've given?
Note: I've just used panels, shapes and textblocks. I've not used Parts, Layouts, etc.
答案1
得分: 0
我建议你将每个节点的 Node.location 的 x 和 y 值按照你已经扩大节点尺寸的比例进行扩大。
const ratio = ...; // 每个节点的新缩放因子
myDiagram.commit(d => {
d.nodes.each(n => {
n.scale *= ratio;
n.location = n.location.copy().scale(ratio, ratio);
});
})
英文:
I suggest that you scale up the x and y values of each node's Node.location by the ratio that you have scaled up the sizes of the nodes.
const ratio = ...; // the new scale factor for each node
myDiagram.commit(d => {
d.nodes.each(n => {
n.scale *= ratio;
n.location = n.location.copy().scale(ratio, ratio);
});
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论