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

Does not receive "end" event after pressing right mouse button during drag & drop with left button #198

Closed
kapulkin opened this issue Dec 29, 2019 · 8 comments · Fixed by d3/d3-brush#84

Comments

@kapulkin
Copy link

kapulkin commented Dec 29, 2019

I bind brush tool to zoom events with left mouse button. Also I bind drag & drop logic to zoom events with right button pressed. You could look here: https://viete.io/a170102c-e7b6-11e9-b4f9-9600001cf28e

To reproduce:

  1. Open https://viete.io/a170102c-e7b6-11e9-b4f9-9600001cf28e
  2. Start make selection by moving mouse on white space with left button pressed.
  3. Don't release mouse left button and press right button additionally
  4. Release right button and move mouse with left button pressed little more.
  5. Release mouse left button.
  6. Zoom end or start events will not occur anymore. And selection and drag & drop functionality become broken.

2019-12-30_00-46-05

I use code below to initialize zoom:

  async mounted () {
    const self = this

    select(this.selectionToolSelector)
      .call(
        this.zoomTool = zoom()
          .scaleExtent([1 / 20, 5])
          .filter(() => { return !event.ctrlKey })
          .on('start', self.zoomStart)
          .on('zoom', self.zoomed)
          .on('end', self.zoomEnd)
          // TODO: listen zoom on end to open contextMenu
      )

I use nuxt and d3 of versions:
"nuxt": "^2.9.2"
"d3": "^5.11.0"

@kapulkin
Copy link
Author

I applied already my fork https://github.com/kapulkin/d3-zoom at https://viete.io/a170102c-e7b6-11e9-b4f9-9600001cf28e, so you will not be able to reproduce the bug there.

@SilverIrbis
Copy link

SilverIrbis commented Mar 20, 2020

Hi!
@kapulkin Excuse me, may I ask, how do you combined zoom with the brush? I mean - how did you bind brush on left mouse button? I have a similar task now, but Im new at d3 and kinda stuck with it

@Fil
Copy link
Member

Fil commented May 29, 2020

I'm sorry I'm not able to reproduce the issue. Could you try and isolate it in a simple page (a block or notebook?).

I'm also surprised that .filter(() => { return !event.ctrlKey }) works, as variable event doesn't appear to be defined.

To read the mouse buttons and filter the zoom start accordingly, you might want to test d3.event.buttons (https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons).

@kapulkin
Copy link
Author

kapulkin commented May 31, 2020

  1. Look, please, on suggested change in pull request. The fix really improve logic, so it is acceptable to merge it.

  2. I import d3.event as event, that's why the code works.

@Fil
Copy link
Member

Fil commented Jun 1, 2020

It would really help to be able to reproduce the issue with readable code. I've spent quite some time on it now, but I wasn't able to figure out how to make the gesture's "active" count go beyond 1. I can only suppose that there is a conflict between event listeners.

Also, I don't dispute that your patch helps in your case, and that it makes sense to unregister mouseup only if the active count is down to 0, but I'm not sure why we would unregister mousemove.zoom and restore drag if active > 0? In other words, if the gesture has somehow not been closed by that mouseup event, then everything should wait for the real end of the gesture?

@amannn
Copy link

amannn commented Sep 2, 2020

(moved to #222)

@Fil Fil mentioned this issue Sep 2, 2020
@Fil
Copy link
Member

Fil commented Sep 2, 2020

@amannn I'm promoting your question to its own separate issue in #222

@amannn
Copy link

amannn commented Sep 2, 2020

@Fil Thank you for your help!

Fil added a commit to d3/d3-brush that referenced this issue Mar 12, 2021
mbostock pushed a commit to d3/d3-brush that referenced this issue Jun 9, 2021
mbostock added a commit to d3/d3-brush that referenced this issue Jun 10, 2021
* create emit before we use it; make move accept an event.

This seems to:
- fix #83
- possibly fix d3/d3-zoom#198
- help with d3/d3-zoom#222

* update dependencies

* brush.clear event

Co-authored-by: Mike Bostock <mbostock@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

4 participants