Adrian Guerrero
Adrian Guerrero

Reputation: 21

Brush d3.js with right click

I want to do brush with the right click on my chart. I have a brush when I use the left click but i want to use other functions when i use the right click. Now I am using this code for the left click:

let brush = d3.brush()               
        .extent( [ [0,0], [width,height] ] )
        .on("start", function () {(scatter.attr("pointer-events","none"))})  
        .on("end", updateChart)

I want to do something similar, with differentes actions for the right click. Is it possible?

Upvotes: 1

Views: 464

Answers (1)

Adrian Guerrero
Adrian Guerrero

Reputation: 21

Brush interaction has been improved in d3 v4 . By default, brushes now ignore right-clicks intended for the context menu; you can change this behavior using brush.filter.

If filter is specified, sets the filter to the specified function and returns the brush. If filter is not specified, returns the current filter, which defaults to:

function filter() {
  return !d3.event.ctrlKey && !d3.event.button;
}

If the filter returns falsey, the initiating event is ignored and no brush gesture is started. Thus, the filter determines which input events are ignored. The default filter ignores mousedown events on secondary buttons, since those buttons are typically intended for other purposes, such as the context menu.

Upvotes: 1

Related Questions