gojs

Prevent overlapping of nodes in GoJs


I have a graph with details of its node positions.

First graph

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

Second graph

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.


Solution

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