Coder Social home page Coder Social logo

Inertial dragging? about d3-drag HOT 10 CLOSED

d3 avatar d3 commented on April 27, 2024 1
Inertial dragging?

from d3-drag.

Comments (10)

mbostock avatar mbostock commented on April 27, 2024

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.

from d3-drag.

Fil avatar Fil commented on April 27, 2024

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

from d3-drag.

mbostock avatar mbostock commented on April 27, 2024

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.

from d3-drag.

Fil avatar Fil commented on April 27, 2024

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/[email protected] 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.

from d3-drag.

mbostock avatar mbostock commented on April 27, 2024

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.

from d3-drag.

Fil avatar Fil commented on April 27, 2024

Yes! that json file was the culprit!

from d3-drag.

Fil avatar Fil commented on April 27, 2024

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

from d3-drag.

mbostock avatar mbostock commented on April 27, 2024

@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?

from d3-drag.

Fil avatar Fil commented on April 27, 2024

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 :)

from d3-drag.

Fil avatar Fil commented on April 27, 2024

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

from d3-drag.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.