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

V2 double click event #1153

Closed
avenzi opened this issue Nov 5, 2021 · 6 comments
Closed

V2 double click event #1153

avenzi opened this issue Nov 5, 2021 · 6 comments
Milestone

Comments

@avenzi
Copy link
Contributor

avenzi commented Nov 5, 2021

Hello,

I may be mistaken, but it doesn't appear that doubleClick events are available yet in V2. In the source it looks like the mouse captor handleDoubleClick() method does not emit any events, and no double click events exist for the sigma class itself, like 'doubleClickNode' or 'doubleClickStage'.

What I've ended up doing in my project to change the default double click behavior is just redefine the captor handler, like so:

sigma.getMouseCaptor().handleDoubleClick = function(event) { console.log("Double Click!") }

Is this the intended way to handle double click events, or will this emitted event be added at some point?

Thanks!

@jacomyal
Copy link
Owner

jacomyal commented Nov 5, 2021

Hi @aeviox,

You are right, the double click events are missing, and it shouldn't be too hard to add.

We will try to add that soon, probably at the same time we tackle issue #1142. Thanks for the report, I'll keep you updated here as soon as we have something.

@avenzi
Copy link
Contributor Author

avenzi commented Nov 5, 2021

Worth nothing that the wheel events don't look like they are there either, but again correct me if I'm wrong.

Thanks again!

@jacomyal
Copy link
Owner

jacomyal commented Nov 9, 2021

Indeed, I never thought of it, but it's easy to add and I can imagine this feature being useful sometime.

@gajicdev
Copy link

Would love the doubleclick and wheel events aswell 😄

jacomyal added a commit that referenced this issue Nov 23, 2021
This commit implements the four new different events:
- wheelNode
- wheelStage
- doubleClickNode
- doubleClickStage
@jacomyal
Copy link
Owner

I just pushed a commit implementing the wheel and double-click events.

However, there are two things to note:

  1. At the moment, the events are just emitted, and there is no way to use that to cancel the default event behavior. For instance, there's no way right now to cancel normal sigma zoom when the user uses the mouse-wheel on a node.
  2. The double-click events are dispatched in addition the the click events. If you need to catch a double-click that would cancel the single-click, you will need to implement this the application side.

This should be deployed within the upcoming v2.1.0 release.

@jacomyal jacomyal added this to the v2.1.0 milestone Nov 23, 2021
@avenzi
Copy link
Contributor Author

avenzi commented Nov 23, 2021

I just submitted a pull request that I believe fixes the first of your concerns, allowing wheel and doubleClick event handlers to prevent the default behavior defined in the MouseCaptor. The usage looks like this (where renderer is a reference to the Sigma renderer):

renderer.getMouseCaptor().on("doubleClick", (event) => {
    console.log("default double click")
})

renderer.on("doubleClickNode", (event) => {
    event.event.preventDefault()
    console.log("double clicked a node", event.event)
})

renderer.getMouseCaptor().on('wheel', (event) => {
    console.log("default wheel")
})

renderer.on('wheelNode', (event) => {
    event.event.preventDefault()
    console.log("wheeled on a node")
})

Another option could be to make the preventDefault() method available to the Node and Stage events by simply adding it as a property to the returned object here and bind it to the MouseCoords event. This would just have the benefit of avoiding the "event.event...".

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

No branches or pull requests

3 participants