Skip to content

Allow clickable legend group titles when group has no pie-like traces #5771

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

Merged
merged 7 commits into from
Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions draftlogs/5771_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Allow clickable legend group titles when group has no pie-like traces [[#5771](https://github.com/plotly/plotly.js/pull/5771)]

15 changes: 13 additions & 2 deletions src/components/legend/get_legend_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ module.exports = function getLegendData(calcdata, opts) {
legendData[i].forEach(function(a, k) { a._preSort = k; });
legendData[i].sort(orderFn2);

var firstItem = legendData[i][0];
var firstItemTrace = legendData[i][0].trace;

var groupTitle = null;
// get group title text
Expand All @@ -134,12 +134,23 @@ module.exports = function getLegendData(calcdata, opts) {
if(reversed) legendData[i].reverse();

if(groupTitle) {
var hasPieLike = false;
for(j = 0; j < legendData[i].length; j++) {
if(Registry.traceIs(legendData[i][j].trace, 'pie-like')) {
hasPieLike = true;
break;
}
}

// set group title text
legendData[i].unshift({
i: -1,
groupTitle: groupTitle,
noClick: hasPieLike,
trace: {
showlegend: firstItem.trace.showlegend
showlegend: firstItemTrace.showlegend,
legendgroup: firstItemTrace.legendgroup,
visible: firstItemTrace.visible
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/legend/handle_click.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = function handleClick(g, gd, numClicks) {
[];

var legendItem = g.data()[0][0];
if(legendItem.groupTitle) return; // no click on group legends for now
if(legendItem.groupTitle && legendItem.noClick) return;

var fullData = gd._fullData;
var fullTrace = legendItem.trace;
Expand Down