Skip to content

Instantly share code, notes, and snippets.

@Ellisande
Created March 26, 2015 17:42
Show Gist options
  • Save Ellisande/155e4411f9c9cc399c2a to your computer and use it in GitHub Desktop.
Save Ellisande/155e4411f9c9cc399c2a to your computer and use it in GitHub Desktop.
Add Secondary Edges
data.relations.forEach(function(relation){
console.log(typeof(relation) + "and " + relation.first_name);
graphData.nodes[relation.person_id] = {
color: 'green',
shape: 'dot',
label: relation.first_name + " " + relation.middle_name + " " + relation.last_name
}
// This line right here always adds the edge to data.person_id...
//but when you move to a new relation we need to add a new node to relations
// Since we always add to the graphData.edges[data.person_id] the new nodes will always be connected to just that person.
graphData.edges[data.person_id][relation.person_id] = {};
//Example for a new relation
graphData.edges[data.new_relation][relation.person_id] = {}
});
// need a placeholder for 1.
var buildPersonNode = function(person) {
graphData.nodes[data.person_id] = {
color: "red",
shape: "dot",
label: data.first_name + " " + data.middle_name + " " + data.last_name
};
graphData.edges[data.person_id] = {};
data.relations.forEach(function(relation){
console.log(typeof(relation) + "and " + relation.first_name);
graphData.nodes[relation.person_id] = {
color: 'green',
shape: 'dot',
label: relation.first_name + " " + relation.middle_name + " " + relation.last_name
}
graphData.edges[data.person_id][relation.person_id] = {};
});
buildPersonNode(relation);
}
}
$.get('api/1').success(function(data){
buildPersonNode(data);
sys.graft(graphData);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment