Reputation: 6186
Having a selector with two handlers for selecting a range, I'm using d3.brush in order to get that range.
The problem that appears is when both selectors are on the same value (e.g. 0) the array containing the identical values [0, 0] becomes null
.
I don't know why is this happening and how should it be avoided.
const brush = d3.brushX()
.extent([[0, 0], [100, 100]])
.on('brush.drag', () => {
const selection = d3.event.selection;
updateSomethingFromSelection(selection);
})
.on('end', () => {
const selection = d3.event.selection;
updateSomethingFromSelection(selection);
})
.on('brush.heatmap', () => {
const selection = d3.event.selection;
updateSomethingElse(selection);
});
What I want to avoid is having the selection null. Can you somehow tell d3 brush to never have null selection?
Any suggestions?
Upvotes: 0
Views: 508
Reputation: 3777
You're correct, if the range in the brush is 0 d3 will consider it "empty". As you can see here in the source, this will set the selection back to null. The only way to force d3 to draw on "empty" is by providing a very small value to d3 and having it draw that first.
Upvotes: 1