Visjs 网上商城节点固定在右下角

Visjs network place node fixed at bottom right

我想在visjs框架的网络插件中创建一个节点,让它固定在底部。

让它保持固定是没有问题的,但是其余节点似乎对 x 和 y 坐标有某种算法。

执行 { x: 0, y: 0 } 似乎不起作用,因为 x 和 y 是相对于其他节点的坐标。

我认为(如果我没看错的话),你应该:

  1. 将物理设置为 false
  2. 为所有节点true提供固定位置,
  3. 根据需要设置节点位置。
  4. 绘制网络后(在下一个刻度中)从所有其他节点移除固定位置。

请参阅下面的代码段。 (固定位置停留在节点号 5 上)。

// create an array with nodes
  var nodes = new vis.DataSet([
    {id: 1, label: 'Node 1', fixed: true, group: 1, x:0, y:0},
    {id: 2, label: 'Node 2', fixed: true, group: 2, x:10, y:110},
    {id: 3, label: 'Node 3', fixed: true, group: 1, x:120, y:20},
    {id: 4, label: 'Node 4', fixed: true, group: 2, x:-110, y:-110},
    {id: 5, label: 'Node 5', fixed: true, group: 2, x:220, y:220}
  ]);

  // create an array with edges
  var edges = new vis.DataSet([
    {from: 1, to: 3},
    {from: 2, to: 4},
    {from: 3, to: 4},
    {from: 2, to: 5}
  ]);

  // create a network
  var container = document.getElementById('mynetwork');
  var data = {
    nodes: nodes,
    edges: edges
  };
  var options = {
    physics: false
  };
  var network = new vis.Network(container, data, options);
  
  setTimeout(function(){
    nodes.forEach(node => {
      if(node.id !== 5){
        nodes.update({id: node.id, fixed: false});
      }
    })
  })
#mynetwork {
      width: 600px;
      height: 400px;
      border: 1px solid lightgray;
    }

    p {
      max-width: 600px;
    }
<!doctype html>
<html>
<head>
  <title>Network | Basic usage</title>
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.20.0/vis.min.js"></script>
  <link href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.20.0/vis.min.css" rel="stylesheet" type="text/css"/>
</head>
<body>
  <div id="mynetwork"></div>
</body>
</html>