Problem:
I'm attempting to bring the inner circle elements to the forefront on mouseover, and then restore them on mouseout.
Fiddle:
https://jsfiddle.net/jo8xd3mo/1/
Code:
var dataset = {
inside: [53245, 28479, 19697, 24037, 40245],
outside: [40245, 25203, 65232, 53092, 12035]
};
var $container = $('.modular-chart'),
width = $container.width(),
height = $container.height(),
cwidth = 80;
var color = d3.scale.category20c();
var pie = d3.layout.pie()
.sort(null);
var arc = d3.svg.arc();
var svg = d3.select(".pie-chart").append("svg")
.attr("width", "100%")
.attr("height", "100%")
.attr('viewBox', '0 0 ' + Math.min(width, height) + ' ' + Math.min(width, height))
.attr('preserveAspectRatio', 'xMinYMin')
.append("g")
.attr("transform", "translate(" + Math.min(width, height) / 2 + "," + Math.min(width, height) / 2 + ")")
var gs = svg.selectAll("g").data(d3.values(dataset)).enter().append("g");
var path = gs.selectAll("path")
.data(function(d) {
return pie(d);
})
.enter().append("path")
.attr("fill", function(d, i) {
return color(i);
})
.attr("d", function(d, i, j) {
return arc.innerRadius(cwidth + 280).outerRadius(cwidth * (j + 2.5))(d);
})
.on("mouseover", function(d, i, j) {
d3.select(this)
.transition()
.duration(500)
.style("fill", "white")
.attr("d", d3.svg.arc().innerRadius(cwidth + 300).outerRadius(cwidth * (j + 2.5)))
})
.on("mouseout", function(d, i, j) {
d3.select(this)
.transition()
.duration(500)
.style("fill", color(i))
.attr("d", d3.svg.arc().innerRadius(cwidth + 280).outerRadius(cwidth * (j + 2.5)))
});
Analysis:
I understand that z-index does not exist for SVG elements and items are layered according to their order in the DOM. I've located various solutions that don't seem to work for my use-case. If anyone has any suggestions or insights, I'm all ears. I've been struggling with this for a few hours and could use another pair of eyes. Thank you!