Is it possible to have a brush that is a static width ie a brush that is not resizable? It would still need to be draggable. There doesn't seem to be anything indicating whether it's possible in the documentation.
6 Answers
Resize can be prevented by hiding the resize handles via css
g.brush>.resize {
display: none;
}

- 81
- 1
- 3
There's no explicit option for that, but all you need to do is reset the domain in the brush event handler, for example
var brush = d3.svg.brush().on("brush", brushed);
function brushed() {
brush.extent(desiredDomain);
}

- 107,425
- 16
- 204
- 204
In D3.js v4.0 you can disable the pointer events in CSS for the SVG elements (handle rectangle).
.handle {
pointer-events: none;
}

- 41
- 2
Actually, manually resetting the extent does not seem to work well.
The solution I've found, which is hidden in the slider example, is to remove the resize element altogether:
// Create the brush normally.
var brush = d3.svg.brush()
.x(xScale)
.on("brush", brushed);
// Add it to a SVG group
var slider = context.append("g")
.attr("class", "x brush")
.call(brush);
// Remove the resize control
slider.selectAll(".resize").remove();

- 382
- 2
- 7
I encountered exactly the same problem. I was using D3 4.0 and need to implement a fixed size brush along the x axis. I used drag.filter()
function and modified elements inside .brush
to achieve this:
var brush = d3.brushX()
.filter(function () {return d3.mouse(this)[0] > brushStart && d3.mouse(this)[0] < brushStart + brushWidth})
.extent([[0, 0], [width, height]])
.on("end", brushended)
.on('brush', beingBrushed);
svg.append('g')
.attr('class', 'brush')
.call(brush)
.call(brush.move, [0, brushWidth]); //initial position
d3.selectAll('.brush>.handle').remove();
function brushended() {
var s = d3.event.selection;
if (s!== null) {
brushStart = s[0];
}
}
This way the brush allows dragging but not resizing.

- 105
- 1
- 8
I just removed the .handle
elements from graph with the brush:
contextGraph.selectAll('.handle').remove();

- 313
- 6
- 18