Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid network graph nodes overlapping?

I was using Visjs and displaying rectanglar nodes with text. Some of the nodes can have a couple of lines of text so I added a heuristic algorithm to work out roughly where the line breaks should go to avoid very wide, single line chunks of text in very wide but very short nodes.

The trouble is, even with physics turned on, I still get overlapping nodes.

Is it possible to tell the layout engine that, under no circumstances (or physics models), should any two nodes overlap?

like image 530
Volksman Avatar asked Feb 04 '23 04:02

Volksman


1 Answers

Well, check out the physics configuration example: as you can see, barnesHut solver has avoidOverlap property which prevents overlapping even when springConstant is equal to zero. Try this:

var options = {
  "physics": {
    "barnesHut": {
      "springConstant": 0,
      "avoidOverlap": 0.2
    }
  }
}

and tweak the constants to fit your needs (the example linked above is useful for that).

From its documentation:

Accepted range: [0 .. 1]. When larger than 0, the size of the node is taken into account. The distance will be calculated from the radius of the encompassing circle of the node for both the gravity model. Value 1 is maximum overlap avoidance.

To be noted, though: I've seen a recommendation to start with low values of avoidOverlap (like 0.1) to simplify the task for the solver. I can't recall where exactly I've read this.

like image 67
YakovL Avatar answered Apr 10 '23 10:04

YakovL