getConnectedNodes方向参数

 收藏

I have a small issue with the parameter direction of the function getConnectedNodes() based on the Vis.js documentation (search for "getConnectedNodes" in the link)

任何想法使用参数获取边缘的方向(我不知道如何)?

JSON范例

[ 
  { "x": 0, "y": 0, "id": "0", "connections": [ 2 ] // i think here should be a from?},
  { "x": 200, "y": 0, "id": "1", "connections": [ 3, 2 ] },
  { "x": 500, "y": 500, "id": "2", "connections": [ 0, 1 ] },
  { "x": 300, "y": -200, "id": "3", "connections": [ 1 ] } 
]

这是部分代码

google.script.run.withSuccessHandler(([nodes, edges]) => new vis.Network(container, {nodes: nodes, edges: edges}, options)).sample();

let network;

function init() {
  container = document.getElementById('mynetwork');
  exportArea = document.getElementById('input_output');
  network = google.script.run.withSuccessHandler(([nodes, edges]) => {network = new vis.Network(container, {nodes: nodes, edges: edges}, options);}).sample();
};

function addConnections(elem, index) {
  elem.connections = network.getConnectedNodes(index);               < I THINK THE PROBLEM IS HERE
}

function exportNetwork() {
  var nodes = objectToArray(network.getPositions());
  nodes.forEach(addConnections);
  var exportValue = JSON.stringify(nodes, undefined, 2);
  exportArea.innerHTML = exportValue;
}

function objectToArray(obj) {
  return Object.keys(obj).map(function(key) {
    obj[key].id = key;
    return obj[key];
  });
}

在此之前,非常感谢!

回复
  • index is the index of the array like 0, 1, 2,,,. The start index is 0. On the other hand, elem is the object like {x: ###, y: ###, id: ###}. From these situation, I thought that index of getConnectedNodes(index) might be elem.id. So how about the following modification?

    从:

    elem.connections = network.getConnectedNodes(index);
    

    至:

    elem.connections = network.getConnectedNodes(elem.id);
    

    如果我误解了您的问题,而这不是您想要的结果,我深表歉意。