Brush clear
abstractalgo opened this issue · 2 comments
abstractalgo commented
Hello, I've been having issue while trying to clear brush in v4:
var selectRectangle = svg.append("g").attr("class", "brush");
var rectSelectionBehavior = d3.brush();
rectSelectionBehavior.on("end", function() {
selectRectangle.call(rectSelectionBehavior.move, null);
});
selectRectangle.call(rectSelectionBehavior);
I've noticed that "end" handler keeps on firing to infinity, and brush keeps being drawn.
Any help is welcome, as I'm out of ideas. Thanks!
mbostock commented
This is because calling brush.move dispatches brush events, including an end event. You can use d3.event.sourceEvent to tell whether the brush event came from user input or your programmatic call to brush.move.
For an example, see Brush Snapping II.
abstractalgo commented
Thank you, it worked. For some reason I missed those lines from the example. Just for further reference, this is the code I used.
rectSelectionBehavior.on("end", function() {
if(d3.event.sourceEvent.type!="end")
selectRectangle.call(rectSelectionBehavior.move, null);
});