-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
DRAFT: add legend.groupclick option #5849
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ module.exports = function handleClick(g, gd, numClicks) { | |
|
||
var itemClick = fullLayout.legend.itemclick; | ||
var itemDoubleClick = fullLayout.legend.itemdoubleclick; | ||
var groupClick = fullLayout.legend.groupclick; | ||
|
||
if(numClicks === 1 && itemClick === 'toggle' && itemDoubleClick === 'toggleothers' && | ||
SHOWISOLATETIP && gd.data && gd._context.showTips | ||
|
@@ -27,6 +28,8 @@ module.exports = function handleClick(g, gd, numClicks) { | |
else if(numClicks === 2) mode = itemDoubleClick; | ||
if(!mode) return; | ||
|
||
var toggleGroup = groupClick === undefined || groupClick === 'togglegroup'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No defined case indeed. (So only if it is possible to change this value manually or in case of a bug.) |
||
|
||
var hiddenSlices = fullLayout.hiddenlabels ? | ||
fullLayout.hiddenlabels.slice() : | ||
[]; | ||
|
@@ -148,10 +151,16 @@ module.exports = function handleClick(g, gd, numClicks) { | |
} | ||
|
||
if(hasLegendgroup) { | ||
for(i = 0; i < fullData.length; i++) { | ||
if(fullData[i].visible !== false && fullData[i].legendgroup === legendgroup) { | ||
setVisibility(fullData[i], nextVisibility); | ||
if(groupClick === false) return; | ||
|
||
if(toggleGroup) { | ||
for(i = 0; i < fullData.length; i++) { | ||
if(fullData[i].visible !== false && fullData[i].legendgroup === legendgroup) { | ||
setVisibility(fullData[i], nextVisibility); | ||
} | ||
} | ||
} else { | ||
setVisibility(fullTrace, nextVisibility); | ||
} | ||
} else { | ||
setVisibility(fullTrace, nextVisibility); | ||
|
@@ -192,7 +201,8 @@ module.exports = function handleClick(g, gd, numClicks) { | |
// N.B. consider traces that have a set legendgroup as toggleable | ||
notInLegend = (fullData[i].showlegend !== true && !fullData[i].legendgroup); | ||
isInGroup = isClicked || (hasLegendgroup && fullData[i].legendgroup === legendgroup); | ||
setVisibility(fullData[i], (isInGroup || notInLegend) ? true : otherState); | ||
if(isInGroup && groupClick === false) continue; | ||
setVisibility(fullData[i], ((isInGroup && toggleGroup) || notInLegend) ? true : otherState); | ||
break; | ||
} | ||
} | ||
|
@@ -219,7 +229,7 @@ module.exports = function handleClick(g, gd, numClicks) { | |
for(i = 0; i < keys.length; i++) { | ||
key = keys[i]; | ||
for(j = 0; j < attrIndices.length; j++) { | ||
// Use hasOwnPropety to protect against falsey values: | ||
// Use hasOwnProperty to protect against falsy values: | ||
if(!attrUpdate[key].hasOwnProperty(j)) { | ||
attrUpdate[key][j] = undefined; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the use case for
groupclick: false
that isn't covered byitemclick: false
? I guess you have some traces in a group and others ungrouped, and you want to allow clicks on the ungrouped traces but not on the groups? That feels weird. Unless I'm missing something, can we removefalse
as an option here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to agree that
false
is not a valid option here, and thatgroupclick
should only determine what happens when you click on a grouped item ANDitemclick
is notfalse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better way to 'lock' certain traces/legendgroups would be with a dedicated feature, so I agree to remove the "false" option here.