Skip to content

The (click) output of plotly-plot fires twice #63

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

Closed
jjmurre opened this issue May 14, 2019 · 3 comments · Fixed by #78
Closed

The (click) output of plotly-plot fires twice #63

jjmurre opened this issue May 14, 2019 · 3 comments · Fixed by #78
Assignees
Labels
bug Something isn't working
Milestone

Comments

@jjmurre
Copy link

jjmurre commented May 14, 2019

I am using the (click) output of <plotly-plot>. The associated component method fires twice. I use $event as argument from the html template. This argument has the associated ploytly plot data for the first invocation. The second invocation only has a regular MouseEvent.

@andrefarzat
Copy link
Collaborator

You really pointed a big issue. Once you use (click) it adds an event listener for both core's angular and the plotly-plot element. That's why it triggers twice ... I am studying if it would be possible to remove only the core's somehow (tried using @HostListener canceling/stopping the event, but no success) ... A second solution would be prefixing the event like (plotlyClick) so this would avoid the conflict.

In this meanwhile, a simple solution to avoid executing the click twice: Check if the given $event is instance of MouseEvent, if yes it is the native event, if not, it is the plotly-plot event.

Will be back soon with a possible fix 😺

@andrefarzat andrefarzat self-assigned this May 14, 2019
@andrefarzat andrefarzat added the bug Something isn't working label May 14, 2019
@andrefarzat andrefarzat added this to the 1.3.0 milestone May 14, 2019
@andrefarzat
Copy link
Collaborator

@jjmurre I could not find a good way to avoid the event being emitted twice. The best I could figure was to deprecated the (click) and ask the developers to use (plotly_click). I added this explanation to the FAQ

@jjmurre
Copy link
Author

jjmurre commented Sep 2, 2019

@andrefarzat Sounds like a good solution to me! Thanks for fixing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants