You will need to reorder the object and make the circle you hover over the last element added. As you can see here: https://gist.github.com/3922684 and, as suggested by nautat , you should define the following before your main script:
d3.selection.prototype.moveToFront = function() { return this.each(function(){ this.parentNode.appendChild(this); }); };
Then you just need to call the moveToFront function on your object (say circles ) when you hover over the mouse:
circles.on("mouseover",function(){ var sel = d3.select(this); sel.moveToFront(); });
Edit: As suggested by Henrik Nordberg , you need to bind data to the DOM using the second .data() argument. This is necessary so as not to lose the binding to the elements. Please read Henrik's answer (and upgrade it!) For more information. As a general tip, always use the second .data() argument when binding data to the DOM to take advantage of the full d3 performance.
Edit: As Clemens Tolboom mentioned, the inverse function would be:
d3.selection.prototype.moveToBack = function() { this.each(function() { this.parentNode.firstChild && this.parentNode.insertBefore(this, firstChild); } }); };
Christopher Chiche Jan 20 '13 at 16:18 2013-01-20 16:18
source share