Getintersectionlist From A D3.js Html
Solution 1:
The Firefox error is to be expected since that browser doesn't yet support getInsectionList
method: https://bugzilla.mozilla.org/show_bug.cgi?id=501421
Regarding Chrome, I think you have a timing issue where the svg nodes aren't rendered at the time you execute your getIntersectionList
call. If you push the code to the end of the event loop it should work:
window.setTimeout(function(){
// your original code as-is:var root = document.getElementById("svgBox");
var rpos = root.createSVGRect();
rpos.x = 150;
rpos.y = 150;
rpos.width = rpos.height = 1;
var list = root.getIntersectionList(rpos, null);
console.info(list);
},0)
Probably you're going to have this inside some other event (e.g. mouse click) anyway, but the above should let you prove out the concept.
Regarding alternate approach to intersection testing (which you'll probably need unless you support only Chrome), see this question: d3 - see what is at a particular x,y position
And one other unrelated suggestion on the efficiency of your code: d3 has a node() method which gives you the underlying DOM node of the selection. Since you already have a reference to d3's svg object, you can change this:
var root = document.getElementById("svgBox");
to this:
var root = svg.node();
Post a Comment for "Getintersectionlist From A D3.js Html"