防止GoJs中节点的重叠。

huangapple go评论89阅读模式
英文:

Prevent overlapping of nodes in GoJs

问题

我有一个包含节点位置详细信息的图表。

防止GoJs中节点的重叠。

我尝试通过简单地扩大节点大小来创建另一个图表。

防止GoJs中节点的重叠。

一切都运行正常,但新图表中的节点重叠在一起。我理解这是因为现在的节点更大,但是否有一种GoJs方式可以按照我给定的位置点来防止重叠?

注意:我只是使用了面板、形状和文本块。我没有使用部件、布局等。

英文:

I have a graph with details of its node positions.

防止GoJs中节点的重叠。

I am trying to create another graph by simply expanding the node size.

防止GoJs中节点的重叠。

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);
  });
})

huangapple
  • 本文由 发表于 2023年1月6日 10:36:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75026400.html
  • gojs
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定