I am trying to select nodes in my d3 tree on mousemove using a rectangle select box(using this example). It is working fine when the svg is in normal scale . If I increase or decrease the scale value it is not working as expected.
var translateCoords = d3.transform(d3.select("#svgGroup").attr("transform"));
translateX = translateCoords.translate[0];
translateY = translateCoords.translate[1];
scaleX = translateCoords.scale[0];
scaleY = translateCoords.scale[1];
//where svgGroup is the main svg g element,
radius is radius of inner nodes
d3.selectAll( 'g.node-element >circle.inner').each( function( state_data, i) {
var tCoords = d3.transform(d3.select( this.parentNode).attr("transform"));
tX = tCoords.translate[0];
tY = tCoords.translate[1];
if(
!d3.select( this).classed( "selectedNode") &&
tX+translateX*scaleX -radius>=d.x && tX+translateX*scaleX -radius<=parseInt(d.x)+parseInt(d.width)&&
tY+translateY*scaleY-radius>=d.y && tY+translateY*scaleY+radius<=d.y+d.height
) {
d3.select( this.parentNode)
.classed( "selection", true)
.classed( "selectedNode", true);
}
});
Here is the jsFiddle demo