I'm building a network with d3js (basically nodes and links)
When I mouseouver one node, I want to highlight the associated links and make them top of parentNode to make them really visible
On mouseover, I've made something like this
// get links to highlight given the selected node
var highlightLinks = nodeLinks(id);
lines.each(function(index){
// if index is in selected links
if (highlightLinks.include(index)){
// highlight link with yellow color
this.setAttribute('style',"stroke:#ffc900")
// raise the link on top of parent node
d3.select(this).raise()
}
else {
// else grey
this.setAttribute('style',"stroke:#1B1B1B")
}
}
It's working fine with the first mouseouver. But when I get out, my lines aren't ordered the same way anymore, and the if clause is highlighting random links for other mouseovers
I think the solution should be to re-order back the links when exiting mouseover, but I can't find a way to do this. I've stored the movedIndex as an array
What I would like :
- (state 1) My links before first mouseover :
[0,1,2,3,4,5] - (action 1) Enter mouseover highlighting 1 and 2, raising them, stored the
movedIndex=[1,2] - (state 2) My links after mouseover :
[0,3,4,5,1,2] - (action 2) Exit mouseover highlighting 1 and 2, do some magic with
movedIndexto "unraise" them - (state 3) My links should be again :
[0,1,2,3,4,5]