The example above already does that.
/* Now, let's create invisibile anchor nodes to pull the nodes by aura together */
var anchors = {};
for (var x = 0; x < jsonData.nodes.length; x++){
var node = jsonData.nodes[x];
if (node.auras && node.auras.length > 0){
for (var y = 0; y < node.auras.length; y++){
var aura = node.auras[y];
var anchor_id = "anchor" + aura;
if (typeof(anchors[anchor_id]) == "undefined"){
anchors[anchor_id] = {
id: anchor_id,
extra: {type: "anchor"},
style: {fillColor: "limegreen", radius: 100}
};
}
jsonData.links.push({
id: node.id + ":" + anchor_id,
from: node.id,
to: anchor_id
});
}
}
}
var anchor_array = [];
for (var x in anchors){
if (anchors.hasOwnProperty(x)){
jsonData.nodes.push(anchors[x]);
anchor_array.push(anchors[x].id);
}
}
console.log(anchor_array);
/**/