Skip to content

Feature Request: It is not possible to disable default click/doubleclick behavior for legends #52

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
Schmaga opened this issue Mar 24, 2019 · 3 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@Schmaga
Copy link

Schmaga commented Mar 24, 2019

From the official plotly documentation and when using simple JavaScript, it is possible to do something like this to disable the default behavior for legend clicking:
myPlot.on('plotly_legendclick', function(data){ return false; });

After looking into your code, the angular wrapper seems to simply register a corresponding EventEmitter for every plot event and does not provide a way to disable those events at all. It would be nice to be able to disable the legend click or double-click behavior. Maybe it is possible to build a property like [disableLegendClick] and [disableLegendDoubleClick] or something? Or transfer the 'return false' approach to the Angular wrapper, if technically possible.

My next approach would be to somehow get the underlying plotly div from the template through whatever means and manually overwrite the two events. But I am not sure which side-effects that might have and it also somehow defeats the purpose of the wrapper by working around it.

Any ideas? Is there a way I have not yet tried? I am not sure if this is actually a bug or a feature request. After I had a look into the code I simply assumed the latter. I am using version 1.1.0 of the wrapper and plotly.js 1.45.3.

@andrefarzat
Copy link
Collaborator

@Schmaga this is a very specific scenario. I don't like the idea of using properties like [disableLegendClick] for it doesn't scale well (imagine having a property like this for each event?).

As a quick solution (while we wonder about a good api), you could use the initialized event to get the current plotlyInstance and set the event manually. Like this:

<plotly-plot divId="my-div" ... ></plotly-plot>

and

export class SomeComponent {
    constructor(public plotlyService: PlotlyService) { }

    public onInitialized() {
        const div = this.plotlyService.getInstanceByDivId('my-div');
        div.on('plotly_legendclick', () => false);
    }
}

If this solves, we can then discuss an API 😸

@Schmaga
Copy link
Author

Schmaga commented Mar 25, 2019

@andrefarzat I totally agree that the disable properties are not a scalable design. It was just a quick thought.

And your workaround did the trick. Thanks alot!

Maybe instead of a disable property per event, it would be possible to bind a list of disabled events? Another more or less bad design. No better idea has popped up, yet :) I'm quite sure it's not possible to pass any Angular event return values to the underlying JavaScript event, so that's probably a no-go.

So maybe, just maybe... It might be enough to document this workaround somewhere and keep it that way? I think it's not that bad. What do you think?

@andrefarzat
Copy link
Collaborator

@Schmaga I like the idea of documenting this for future reference. Maybe creating a FAQ on the README.md ?
I will create a PR with it later 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants