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

Add "toggle legend" button #4042

Closed
AdnanBoota opened this issue Jul 12, 2019 · 8 comments · Fixed by #4305
Closed

Add "toggle legend" button #4042

AdnanBoota opened this issue Jul 12, 2019 · 8 comments · Fixed by #4305
Assignees
Labels
feature something new
Milestone

Comments

@AdnanBoota
Copy link

Hi Team Plotly,

I was wondering if it is possible to add a "legend minimize/maximize (show/hide)" feature in Piecharts. I want to show/hide legend with a button (screenshots attached), so that I can use the space for the chart and also see legend whenever needed.

This feature would be very useful in cases where we have simply too many items in the legend or legend items have long text. In such cases, the user would like to resolve the label by simply hovering over the item, instead of looking for it in the legend.

I actually got this idea from Kibana dashboard (https://demo.elastic.co/app/kibana#/dashboard/edf84fe0-e1a0-11e7-b6d5-4dc382ef7f5b). They have legend minimization in their pie charts.

I'm using this library in ReactJS, will the Plotly.js also update the ReactJS package, any suggestion on this?

Thank you very much for your help.

Regards,
Adnan
pie-chart-btn-2
pie-chart-btn-1

@etpinard
Copy link
Contributor

etpinard commented Jul 12, 2019

Hi @AdnanBoota

I'm a little confused here. But it sounds like you can get the desired result by toggling layout.showlegend

https://plot.ly/javascript/reference/#layout-showlegend

for example:

var fig = {
  data: [/* */],
  layout: {}
}

Plotly.react('graph', fig)

fig.layout.showlegend = false
Plotly.react('graph, fig)

fig.layout.showlegend = true
Plotly.react('graph, fig)

@AdnanBoota
Copy link
Author

AdnanBoota commented Jul 15, 2019

Hi @etpinard,

Again, thanks for quick response!
Yes, main idea is to show/hide with a button, i was wondering if there could be anything built-in, but if not Will definitely try updating showlegend using ReactJS.
fig.layout.showlegend = false|true

Regards,
Adnan

@etpinard
Copy link
Contributor

etpinard commented Jul 17, 2019

i was wondering if there could be anything built-in

We could potentially add this. That said, personally, I don't think this would be a valuable addition to the library. But, I can be convinced otherwise.

@etpinard etpinard changed the title PieChart: legend toggle minimize/maximize (show/hide) Add "toggle legend" button Jul 17, 2019
@etpinard
Copy link
Contributor

etpinard commented Jul 17, 2019

What could be interesting is to add a way to make "toggle" updatemenu buttons. For example,

Plotly.newPlot('graph', [{
  type: 'pie',
  labels: ['a', 'b', 'c'],
  values: [1, 2, 3]
}], {
  updatemenus: [{
    type: 'buttons',
    buttons: [{
      label: '≡',
      method: 'relayout',
      args: ['showlegend', false],
      args2: ['showlegend', true]   // NEW attribute !
    }]
  }]
}

would be enough to effectively close this ticket.

@AdnanBoota
Copy link
Author

AdnanBoota commented Jul 17, 2019

Hi @etpinard

Yes that also sounds good, button in updatemenus would be a good approach to control the legend toggle.

Thanks!

@alexcjohnson
Copy link
Collaborator

cc @catherinezucker - this would allow us to create trace visibility buttons as well, for traces that don't have this functionality in the legend.

@etpinard etpinard added the feature something new label Sep 19, 2019
@etpinard etpinard added this to the v1.51.0 milestone Sep 19, 2019
@nicolaskruchten
Copy link
Contributor

The trace-visibility thing could also be addressed via #2642

@raushan9jnv
Copy link

Thank you very much! you saved me! @etpinard @AdnanBoota This worked for me. Facing similar issue

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

Successfully merging a pull request may close this issue.

5 participants