This is document gives a few insights on how to add brushing with d3.js. It is composed by several interactive examples, allowing to play with the code to understand better how it works.
d3.brush().d3.brush.
.extent() property specify the area where
it is possible to brush: top left and bottom right corners
of the rectangle.
d3.brushX() and
d3.brushY().
d3.brushX instead of
d3.brush and you get a 1 dimensional brush.
.on("start end", ...).on("start end", ...) when the brush is
created. This will trigger the function
updateChart each time a new brush is made.
d3.event.selection
.classedselected class is added to the circle if it
is in the selection.
.classed function is very handy since it
automatically removes the class if elements are not in the
selection anymore.
!important in the css part is
necessary to overwrite a feature that specified in the
javascript part.
clipPath is used to avoid displaying the
circle outside the chart area.
all(brush.move, null) is used to dismiss the
grey brushing area once the selection has been done.