Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Inertial dragging? #27

Closed
ncammarata opened this issue Sep 10, 2016 · 10 comments
Closed

Inertial dragging? #27

ncammarata opened this issue Sep 10, 2016 · 10 comments

Comments

@ncammarata
Copy link

ncammarata commented Sep 10, 2016

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

@mbostock
Copy link
Member

mbostock commented Sep 10, 2016

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.

@mbostock mbostock changed the title Drag Acceleration Inertial dragging? Sep 10, 2016
@Fil
Copy link
Member

Fil commented Oct 4, 2017

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

@mbostock
Copy link
Member

mbostock commented Oct 4, 2017

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
Copy link
Member

Fil commented Oct 4, 2017

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.

@mbostock
Copy link
Member

mbostock commented Oct 4, 2017

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
Copy link
Member

Fil commented Oct 4, 2017

Yes! that json file was the culprit!

@Fil
Copy link
Member

Fil commented Nov 6, 2017

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

@mbostock
Copy link
Member

mbostock commented Nov 6, 2017

@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
Copy link
Member

Fil commented Nov 6, 2017

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
Copy link
Member

Fil commented Jun 25, 2020

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

No branches or pull requests

3 participants