I am working with a chord diagram, right now I am only able to select the text label and the grey border that the chords connect to.
I would like to select individual chords however, when I add my mouse function, it selects a random one in the diagram.
//works
svg.append("g")
.selectAll("path")
.data(chord.groups)
.enter().append("path")
.style("fill", function(d) {
return fill(d.index);
})
.style("stroke", function(d) {
return fill(d.index);
})
.attr("d", d3.svg.arc().innerRadius(innerRadius).outerRadius(outerRadius))
.on("mouseover", fade(.1))
.on("mouseout", fade(1));
//doesn't work w/ mouseover
svg.append("g")
.attr("class", "chord")
.selectAll("path")
.data(chord.chords)
.enter().append("path")
.style("fill", function(d) {
//console.log(d.target.subindex)
return fill(d.target.subindex);
})
.attr("d", d3.svg.chord().radius(innerRadius))
//.style("opacity", 1)
.on("mouseover", fade(.1))
.on("mouseout", fade(1));
function fade(opacity) {
return function(g, i) {
svg.selectAll("g.chord path")
.filter(function(d) {
return d.source.index != i && d.target.index != i;
})
.transition()
.style("opacity", opacity);
};
}
The following works fine for me with d3 version 6.5. Note the differences in the event handler function signature, and in the filtering condition:
Parameter
i
in OP should be the chord index, whereas the chord source and target indexes refer to chord groups.