Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Implement momentum panning #280

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

zmeeeeeva
Copy link

@zmeeeeeva zmeeeeeva commented Feb 6, 2025

#67

Demo: https://jsfiddle.net/zmeeva/6urw1s9d/

Usage:

let myZoom = zoom()
  .momentum(true)
  .on('zoom', handleZoom)

@zmeeeeeva zmeeeeeva marked this pull request as draft February 6, 2025 18:31
Copy link

@curran curran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great concept! I took a quick look through the code and noticed some minor formatting issues.

In your demo, I notice some unexpected behavior:

  • If I drag, then stop moving, then release the mouse, the momentum is way higher than I would expect
  • If I drag, then stop moving, then release the mouse, I would expect that the momentum should be zero

Perhaps a time component is needed here, as in, when the drag starts, start monitoring the movement with a setInterval or similar, then take the average motion over the last 3 intervals, or something like that.

src/zoom.js Outdated
startX = x0;
startY = y0;

cancelMomentumTracking();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor formatting inconsistency

Suggested change
cancelMomentumTracking();
cancelMomentumTracking();

@@ -387,7 +442,7 @@ export default function() {
if (g.taps === 2) {
t = pointer(t, this);
if (Math.hypot(touchfirst[0] - t[0], touchfirst[1] - t[1]) < tapDistance) {
var p = select(this).on("dblclick.zoom");
var p = select(this).on('dblclick.zoom');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var p = select(this).on('dblclick.zoom');
var p = select(this).on("dblclick.zoom");

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

Successfully merging this pull request may close these issues.

2 participants