d3/d3-drag

Inertial dragging?

ncammarata opened this issue · 10 comments

is there any method for adding acceleration to d3's drag, which in my opinion can make many interactive pieces seem more natural. For instance, Google Maps [0] allows you to "throw" the map.

Excellent work all around on drag so far.

[0] https://v.usetapes.com/IdX0dPuvD9

This was filed long ago at d3/d3#2096 but I have not gotten around to implementing it, largely because it adds complexity to some of the most complex code in D3 (because of inconsistency across browsers, the need to support multiple input modalities, and the inherently complex nature of interpreting sequences of input events as gestures). All that said I welcome this feature if the implementation can be made simple enough that it’s reasonable for me to maintain (i.e., it doesn’t introduce more bugs in the part of D3 that is already the most likely to receive bug reports). But the other difficulty is that if you add inertial dragging to d3-drag you’ll also want to implement it for d3-zoom.

Fil commented

I wanted this for the versor.js rotation of the globe.

It appears that you don't need to modify d3.drag internally.

During dragging, one can keep track of the gesture's last few positions, and on drag end, start a timer that will extend this movement during a certain (eased) time. One also has to take care of interruptions, such as when you start a new gesture during the extended movement.

To use it with versor rotation, you need a modified version of versor.js that will compute the rotation (A) * (B^alpha), where:

  • A is your final rotation at dragended
  • B is the delta rotation during the last few events of the drag gesture
  • alpha is the eased time

The code could probably be nicer but hey.
https://bl.ocks.org/Fil/f48de8e9207799017093a169031adb02

Cool! That’s fun!

Side note: I am seeing a lot of flickering in that big lake in Russia, probably a winding order detection problem. I have also gotten reports of new winding order problems on Twitter and am concerned our change to decouple rotation from clipping has introduced winding order bugs.

Fil commented

I think the flickering on that big lake was always there — I remember seeing it more than once (but was pursuing something else so never stopped to create an issue). However I have it on this example with https://unpkg.com/d3@4.10.0 as well (just try with .rotate([107.1,-78.6,-162]))

But it would be good to have precise reports. Moving this to d3-geo #121.

Thanks for investigating the unrelated d3-geo issue. Another question was whether it is a problem with the data file in this gist, vs. the latest world-atlas.

Fil commented

Yes! that json file was the culprit!

Fil commented

I have just published a d3-inertia module that solves this, with example(s).

@Fil That looks to be specific to rotating geographic projections, rather than generic 2D dragging. Maybe rename it to d3-geo-inertia, or d3-trackball or some such?

Fil commented

Your remark makes me realize that the geo helper should be called geo-something. However, the plugin is not meant to be specific to geo.

I just made a complicated planar example, it's clear we still need a helper for such a use case. Contributions welcome :)

Fil commented

Closing this issue due to inactivity. The discussion continues at https://github.com/Fil/d3-inertia/issues