removing the brushed area after brushing

2,270 views
Skip to first unread message

Gopal Vaswani

unread,
Mar 22, 2012, 3:16:40 AM3/22/12
to d3...@googlegroups.com
I am using d3.svg.brush() to select an area in a graph and zooming in on the selected area.
Is there a way to clear the brushed rectangle in the 'brushend' method so that I can rebrush.
Right now you have to click outside the brushed area to rebrush again.
I tried using .clear() method but that doesn't seem to be working.

Thanks
Gopal

Gopal Vaswani

unread,
Mar 22, 2012, 4:09:06 AM3/22/12
to d3...@googlegroups.com
I had this working with following (after looking at the d3.svg.brush source code)

Adding this in the end of brushend listener.
        d3.select("g.brush").style("pointer-events", "all").selectAll(".resize").style("display", "none");
        d3.select("g.brush").select(".extent").style("display", "none");
        d3.select("body").style("cursor", null);

And displaying back the extent in the brushstart.
       d3.select("g.brush").select(".extent").style("display", "block");

Don't know if this is the best method.

-Gopal


--
Gopal vaswani


Mike Bostock

unread,
Mar 22, 2012, 12:32:44 PM3/22/12
to d3...@googlegroups.com
The brush does not redraw automatically; if you modify the extent
(which is what the clear method does), you still need to redraw it.
Typically, that looks something like this:

d3.select(".brush").call(brush.clear());

This first clears the brush, and then tells it to redraw.

Mike

Gopal Vaswani

unread,
Mar 22, 2012, 5:06:38 PM3/22/12
to d3...@googlegroups.com
Thanks Mike.
--
Gopal vaswani


Brian Hernandez

unread,
Jul 18, 2014, 2:48:38 PM7/18/14
to d3...@googlegroups.com, mbos...@cs.stanford.edu
Thanks Mike! 
Reply all
Reply to author
Forward
0 new messages