Skip to content
mbostock edited this page Feb 29, 2012 · 11 revisions

API ReferenceSVG

Brush

# d3.svg.brush()

# brush(selection)

The selection can also be a transition.

# brush.x([scale])

Gets or sets the x-scale associated with the brush. If scale is specified, sets the x-scale to the specified scale and returns the brush; if scale is not specified, returns the current x-scale, which defaults to null. The scale is typically defined as a quantitative scale, in which case the extent is in data space from the scale's domain; however, it may instead be defined as an ordinal scale, where the extent is in pixel space from the scale's range extent.

# brush.y([scale])

Gets or sets the y-scale associated with the brush. If scale is specified, sets the y-scale to the specified scale and returns the brush; if scale is not specified, returns the current y-scale, which defaults to null. The scale is typically defined as a quantitative scale, in which case the extent is in data space from the scale's domain; however, it may instead be defined as an ordinal scale, where the extent is in pixel space from the scale's range extent.

# brush.extent([values])

Gets or sets the current brush extent. If values is specified, sets the extent to the specified values and returns the brush; if values is not specified, returns the current extent. The definition of the extent depends on the associated scales. If both an x- and y-scale are available, then the extent is the two-dimensional array [‍[x0, y0], [x1, y1]], where x0 and y0 are the lower bounds of the extent, and x1 and y1 are the upper bounds of the extent. If only the x-scale is available, then the extent is defined as the one-dimensional array [x0, x1]; likewise, if only the y-scale is available, then the extent is [y0, y1]. In neither scale is available, then the extent is null.

When the extent is set to values, the resulting extent is preserved exactly. However, as soon as the brush is moved by the user (on mousemove following a mousedown), then the extent must be recomputed by calling scale.invert. Note that the values may be slightly imprecise due to the limited precision of pixels.

Note that this does not automatically redraw the brush or dispatch any events to listeners. To redraw the brush, call brush on a selection or transition.

# brush.clear()

# brush.empty()

# brush.on(type[, listener])

Clone this wiki locally