The following filter is the same, but it result applied for two different element:
mNode.filter(function(otherNode) {
return connectedNodes.indexOf(otherNode.id) > -1
}).select("image").style("opacity", BACKGROUND_OPACITY);
mNode.filter(function (otherNode) {
return connectedNodes.indexOf(otherNode.id) > -1;
}).select("circle").style("stroke", "#f6f6f6");
how can I combine it to one filter without duplicate the code?
second, is there a way to apply to opposite more efficient?
mNode.filter(function(otherNode) {
return connectedNodes.indexOf(otherNode.id) > -1
}).select("image").style("opacity", BACKGROUND_OPACITY);
mNode.filter(function(otherNode) {
return connectedNodes.indexOf(otherNode.id) == -1
}).select("image").style("opacity", DEFAULT_OPACITY);
Like if the condition is satisfied apply 1st style otherwise apply the 2nd style.
Thanks!
forto iterate overmNode, inside it, useif...elseand apply styles.mNodeis not an array and that filter is notArray.prototype.filter, that's a different method with the same name (that's confusing, I know...). So, theforwon't work here.