jeudi 29 juin 2017

Change style of the element in the middle of an array

i use D3.js and i got another problem. I got this array pat, which let me click 2 nodes and stores the shortest path between those nodes in the array. Now, i created the middle element of pat called mid. My goal is, to change the style of this element, lets say into another color red. but i am struggling to find the right solution. Here you can see my code. How, someone can help me to find a solution.

var mid = null;

     node.on("click", function(d, i){
        var pat = start && start.pat(d) || []

        mid = pat[Math.floor((pat.length - 1) / 2)];

        node.style("fill", function(d) 
                        {
                          if (pat.includes(mid)){ return "red";}

                        });

Aucun commentaire:

Enregistrer un commentaire