Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

d3js overlapping elements: how to "pass through" clicks to "lower" element?

Using d3js, I draw some elements after/ on top of one another. Such as:

 // draw rectangle from dataset "d"
 svg.selectAll(".rect").append("rect")
            .attr("y", 10)
            .attr("x", 10)
            .attr("height", 5)
            .attr("width", 5)
            .on("click", function (d, i) {  
        // react on clicking
     });

  // slightly bigger frame overlapping first one
  var c=1.02;
  svg.append("rect")
                .attr("x", 10)
                .attr("y", 10)
                .attr("width", 5 * c)
                .attr("height", 5 * c)
                .attr("stroke", "blue")
                .attr("stroke-width", 1)
                .attr("fill-opacity", 0)

Obviosuly when second element is drawn overlapping first one, it is blocking the mouse events. I would like to bypass clicks, double-clicks and right clicks transparently through the second object. How I can do that?

like image 335
onkami Avatar asked Jan 27 '26 17:01

onkami


1 Answers

The easiest way is to set the object to receive no pointer events:

svg.append("rect").attr("pointer-events", "none");
like image 124
Lars Kotthoff Avatar answered Jan 30 '26 05:01

Lars Kotthoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!