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

Zoom Behaviour: disabling zoom.click and zoom.dblclick doesn't actually stop zoom behaviour from firing. #273

Open
michealroberts opened this issue Nov 29, 2023 · 0 comments

Comments

@michealroberts
Copy link

Really not sure exactly how to explain this one, but when tapping on a trackpad or similar, the click and double click events still trigger the zooming behaviour.

I'm using d3-zoom with Vue 3 in the following:

const isClicking = ref(false);

  const isDragging = ref(false);

  const zoomBehavior = computed(() => {
    return zoom()
      .scaleExtent([min, max])
      .on('start', (event) => {
        isDragging.value = event.sourceEvent?.type === 'mousedown';
      })
      .on('zoom.click', () => {
        isClicking.value = true;
      })
      .on('zoom.dblclick', () => {
        isClicking.value = true;
      })
      .on('zoom.wheel', (event) => {
        if (!transformContainer.value) {
          return;
        }

        setTransformation(transformContainer.value, event.transform.k, {
          x: event.transform.x,
          y: event.transform.y,
        });
      })
      .on('zoom.touchstart', (event) => {
        if (!transformContainer.value) {
          return;
        }

        setTransformation(transformContainer.value, event.transform.k, {
          x: event.transform.x,
          y: event.transform.y,
        });
      })
      .on('zoom.touchmove', (event) => {
        if (!transformContainer.value) {
          return;
        }

        setTransformation(transformContainer.value, event.transform.k, {
          x: event.transform.x,
          y: event.transform.y,
        });
      })
      .on('end', () => {
        isDragging.value = false;
        isClicking.value = false;
      });
  });

Essentially, what is the process to only allow zooming on either the swipe gesture or mouse scroll?

I've tried multiple different iterations of the above, but when clicking on an element inside the transformContainer, the container still transforms and zooms ...

Any pro-tips would be greatly received ... unless this is actually a bug.

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

No branches or pull requests

1 participant