dimanche 9 juillet 2017

Modify the loop in the right way

i got this graphic of a graph below. Now, the every node has a unique id number. My goal is to seperate out and return only the links between the red nodes, beginning from the left one and end at the right one. So the combination of node id's would be: 1-3-9-2. My problem is that i got an Array which returns: 1-3-9-2-5-6-7. That means also with the white nodes. Unfortunally i have to use that array. Each link between the nodes has a source and a target property.

Now here is my problem: When i use the code below

function (d){
if( Array.includes(d.target) && Array.includes(d.source) {
   highlight the links
}

it highlights all links, because the white nodes are also a part of Array. So how can i highlight the connection between 1 and 3, but not between 1 and 5 for example? All based on the the data of Array? I could use a loop for the first 4 elements and stop at the 5th. My plan is to say: only a connection between one element and the one which comes after that. That means only between the first and the second, the second and the third, the third and the fourth and so on. How can i do that? Thanks so much!

enter image description here

Aucun commentaire:

Enregistrer un commentaire