4


I'm facing a "strange" problem I'm not able to solve looking at vis.js documentation.
I created a network with a fixed hierarchy defining a specific level for each node.
Total number of nodes 51. This is the result:
enter image description here

If I add another node at the bottom of the network scheme (total 52) the layout changes, the spacial disposition of the nodes totally move trying to fill white space as you can see:
enter image description here

I tried several options without any success.
These are the options I'm using at the moment:

 options = {
  layout: {
   improvedLayout: false,
   hierarchical: {
    enabled: true,
    levelSeparation: 150,
    nodeSpacing: 110,
    treeSpacing: 200,
    blockShifting: false,
    edgeMinimization: true,
    parentCentralization: true,
    direction: "LR",
    sortMethod: "directed",
    shakeTowards: "roots"
   }
  },
  interaction:{
   tooltipDelay: 100
  },
  edges: {
   font: {
    size: 0
   }
  },
  nodes: {
   shape: 'circle'
  },
  physics: false
 };

I hope you can give me some suggestion.
Thank you!

neoben
  • 743
  • 12
  • 30

1 Answers1

0

you can try to add a randonSeed to the layout in the options object.

layout: {
    randomSeed: 1,
    improvedLayout: false,
    hierarchical: {
        enabled: true,
        levelSeparation: 150,
        nodeSpacing: 110,
        treeSpacing: 200,
        blockShifting: false,
        edgeMinimization: true,
        parentCentralization: true,
        direction: "LR",
        sortMethod: "directed",
        shakeTowards: "roots"
    }
}

you can change the number (randomSeed: 1) until you get the requested layout. hope it will help.

TERMIN
  • 824
  • 8
  • 18
  • I've already tested several values of randomSeed without any success. I'm afraid that this workaround is not working for my case. – neoben Feb 06 '20 at 13:51
  • Anyway I think that randomSeed has effect when NOT using the hierarchical layout. https://visjs.github.io/vis-network/docs/network/layout.html – neoben Feb 06 '20 at 13:53
  • Hi, what is randomSeed use for? – mastersuse Sep 25 '20 at 00:14
  • Randon seed will define the way the nodes will spread. once you defined it, in every load the spread will be the same. https://visjs.github.io/vis-network/examples/network/layout/randomSeed.html – TERMIN Oct 01 '20 at 05:50