My objective is to change the opacity of a specific path.
This is where I am adding a path for each slice in the chart:
h = f.selectAll("path").data(o);
h.enter().append("path")
.attr("id", function (t, n) { return "path-" + n})
.attr("d", x).attr("fill-rule", "evenodd").style("fill", n).on("click", l)
.on("mouseover", function(t,n) {mouseover("path-" + n)});
inside of the mouseover function here is what I have tried:
function mouseover(d){
// d is the id of the path that was hovered over
// d looks like 'path-20'
d3.selectAll("path").style("opacity", 0.3); // changes opacity for entire sunburst chart
d3.selectAll(d).style("opacity", 0.3); // does nothing
d3.selectAll("path-20").style("opacity", 0.3); // does nothing
d3.select(d).style("opacity", 0.3); // does nothing
d3.select("path-20").style("opacity", 0.3); // does nothing
}
Firstly, if you want to select by a class, use
.<class-name>
instead. If you want to select by an ID, use#<id>
. These are universal selectors from CSS, jQuery, vanilla JavaScript, and also D3.Much easier, though, is that for the function
on("mouseover", function() { ... })
, on the place of the dots,this
now points to the HTMLElement you want to select.That makes the following function perfect for what you want: