MCPcopy Create free account
hub / github.com/breck7/scroll / drag

Function drag

external/.d3.js:2721–2890  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2719}
2720
2721function drag() {
2722 var filter = defaultFilter$2,
2723 container = defaultContainer,
2724 subject = defaultSubject,
2725 touchable = defaultTouchable$2,
2726 gestures = {},
2727 listeners = dispatch("start", "drag", "end"),
2728 active = 0,
2729 mousedownx,
2730 mousedowny,
2731 mousemoving,
2732 touchending,
2733 clickDistance2 = 0;
2734
2735 function drag(selection) {
2736 selection
2737 .on("mousedown.drag", mousedowned)
2738 .filter(touchable)
2739 .on("touchstart.drag", touchstarted)
2740 .on("touchmove.drag", touchmoved, nonpassive)
2741 .on("touchend.drag touchcancel.drag", touchended)
2742 .style("touch-action", "none")
2743 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
2744 }
2745
2746 function mousedowned(event, d) {
2747 if (touchending || !filter.call(this, event, d)) return;
2748 var gesture = beforestart(this, container.call(this, event, d), event, d, "mouse");
2749 if (!gesture) return;
2750 select(event.view)
2751 .on("mousemove.drag", mousemoved, nonpassivecapture)
2752 .on("mouseup.drag", mouseupped, nonpassivecapture);
2753 dragDisable(event.view);
2754 nopropagation$2(event);
2755 mousemoving = false;
2756 mousedownx = event.clientX;
2757 mousedowny = event.clientY;
2758 gesture("start", event);
2759 }
2760
2761 function mousemoved(event) {
2762 noevent$2(event);
2763 if (!mousemoving) {
2764 var dx = event.clientX - mousedownx, dy = event.clientY - mousedowny;
2765 mousemoving = dx * dx + dy * dy > clickDistance2;
2766 }
2767 gestures.mouse("drag", event);
2768 }
2769
2770 function mouseupped(event) {
2771 select(event.view).on("mousemove.drag mouseup.drag", null);
2772 yesdrag(event.view, mousemoving);
2773 noevent$2(event);
2774 gestures.mouse("end", event);
2775 }
2776
2777 function touchstarted(event, d) {
2778 if (!filter.call(this, event, d)) return;

Callers

nothing calls this directly

Calls 3

constant$9Function · 0.85
dispatchFunction · 0.70
filterMethod · 0.45

Tested by

no test coverage detected