Ok, actually point 2) How to disable zoom function when mouse is scroling and keep only panning? is not working in your exemple. When disabeling the zoom, you cannot pan anymore… ;_)
That’s because the “pan” that you refer to is actually controlled by the zoom behavior, as described in the d3.zoom documentation. Your drag functions are actually not doing anything at all and, if you pull up the Javascript console while working with your original notebook, you’ll notice that all sorts of errors are thrown when you try to drag the black square. So, the easiest way to fix this is to simply remove your call to the drag functions:
// Delete this
g.call(
d3.drag().on("start", dragstarted).on("drag", dragged).on("end", dragended)
);
I guess the definitions of those functions should be removed as well.
If you want to disable the wheel zoom, you should add .on("wheel.zoom", null) when you call zoom on the svg: