How to disable left-click panning in d3

In D3, panning works both to the left, and in the right mouse click + drag. However, in my case, I want to reserve (left click + drag) for other actions while (right click + drag) performs panning.

How to disable panning on the left click?

Thanks.

+4
source share
2 answers

I solved this problem as follows:

function doDrag() {
   if (d3.event.button === 0) {
       d3.event.stopImmediatePropagation();
  }
  //other drag work
}

I call this function in the mousedown event.

0
source

Add a mouse control button to your function where you handle the drag.

function doDrag(){
   if(d3.event.sourceEvent.button == 0){
     d3.event.stopImmediatePropagation();
     return;
   }

   //other drag work
 }

Hope this helps!

+1
source

Source: https://habr.com/ru/post/1628433/


All Articles