0

A have a jsfiddle with a simple data structure that adds children to nodes when the node is clicked. I want it to look for existing children of the node clicked. Documentation shows node.children(); - to do this - but it is returning an empty list. Not sure what I'm doing wrong.

Below is a snippet of the where the children function is called.
The GetMoreData is called in the node click handler.

Any suggestions?

function GetMoreData(cy, event)
{
debugger;
    var children = event.cyTarget.children();
  var test = cy.nodes().children();
  var parentID = event.cyTarget.data('id');
  var nodeID = event.timeStamp.toFixed(0) + "x";

  cy.add({group:"nodes", data: {id:nodeID, guid:nodeID,  image:'https://circabc.europa.eu/images/extension/help.png'},
  position:{x:event.cyPosition.x, y:event.cyPosition.y}});
  var edgeID = parentID+"x"+nodeID;
  cy.add({group:"edges", data: {id:edgeID, source:parentID, target:nodeID}});
  var nodex = cy.elements('node[id="x"]');
  var layout = cy.makeLayout({ name: 'breadthfirst', animate: true,  animationDuration: 500, fit: false });

layout.run();
}
Mike Weber
  • 311
  • 2
  • 16

1 Answers1

0

Cytoscape.js supports compound graphs. Unfortunately, "parent" and "child" are words often used in directed, non-compound graphs (usually DAGs or trees) for incomers and outgoers -- creating ambiguity.

As an aside: Make sure your graph and layout are directed, with sources and targets defined in the proper direction.

maxkfranz
  • 11,896
  • 1
  • 27
  • 36