Skip to content

Instantly share code, notes, and snippets.

@adrielTosi
Created September 23, 2019 16:42
Show Gist options
  • Save adrielTosi/51a453dba1b8b4e1e928f3c2f82517f9 to your computer and use it in GitHub Desktop.
Save adrielTosi/51a453dba1b8b4e1e928f3c2f82517f9 to your computer and use it in GitHub Desktop.
Creating the node and links array
@Watch("relationships")
private watchRelationships(relations) {
if (!isEmpty(relations)) {
// WHERE THE NODES ARE CREATED
this.d3NodesData = relations.map(val => {
return {
name: val.userName,
id: val.userId
};
});
relations.forEach(val => {
const thisUserId = val.userId;
val.relatedTo.forEach(id => {
const hasLinkAlready = this.d3LinksData.some(node => {
if (node.source === id && node.target === thisUserId) {
return true;
}
});
// IF THE LINK IS NOT ALREADY CREATED
if (!hasLinkAlready) {
this.d3LinksData.push(
{
source: thisUserId,
target: id
}
);
}
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment