Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable panning on left click in d3

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

How can I disable panning on left click?

Thanks.

like image 784
Pixelord Avatar asked Nov 08 '22 20:11

Pixelord


1 Answers

Add check on mouse down in 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!

like image 76
Cyril Cherian Avatar answered Nov 15 '22 06:11

Cyril Cherian