-1

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

user3775998
  • 1,393
  • 3
  • 13
  • 22

1 Answers1

0

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

cordback
  • 11
  • 3