Skip to content

Commit 5c0168c

Browse files
committed
simplify handling shape legends in click
1 parent 6111aba commit 5c0168c

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

src/components/legend/defaults.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ function groupDefaults(legendId, layoutIn, layoutOut, fullData) {
4141
var legendReallyHasATrace = false;
4242
var defaultOrder = 'normal';
4343

44-
var shapes = (layoutOut.shapes || []).filter(function(d) { return d.showlegend; });
44+
var shapesWithLegend = (layoutOut.shapes || []).filter(function(d) { return d.showlegend; });
4545

46-
var allLegendItems = fullData.concat(shapes).filter(function(d) {
46+
var allLegendItems = fullData.concat(shapesWithLegend).filter(function(d) {
4747
return legendId === (d.legend || 'legend');
4848
});
4949

src/components/legend/handle_click.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,9 @@ module.exports = function handleClick(g, gd, numClicks) {
3838
var legendItem = g.data()[0][0];
3939
if(legendItem.groupTitle && legendItem.noClick) return;
4040

41-
var i, j;
4241
var fullData = gd._fullData;
43-
var allLegendItems = fullData.slice();
44-
if(fullLayout.shapes) {
45-
for(i = 0; i < fullLayout.shapes.length; i++) {
46-
var shapeLegend = fullLayout.shapes[i]; // TODO: make a copy instead!
47-
if(shapeLegend.visible) {
48-
shapeLegend.index = i;
49-
shapeLegend._fullInput = shapeLegend;
50-
allLegendItems.push(shapeLegend);
51-
}
52-
}
53-
}
42+
var shapesWithLegend = (fullLayout.shapes || []).filter(function(d) { return d.showlegend; });
43+
var allLegendItems = fullData.concat(shapesWithLegend);
5444

5545
var fullTrace = legendItem.trace;
5646
if(fullTrace._isShape) {
@@ -59,7 +49,7 @@ module.exports = function handleClick(g, gd, numClicks) {
5949

6050
var legendgroup = fullTrace.legendgroup;
6151

62-
var kcont, key, keys, val;
52+
var i, j, kcont, key, keys, val;
6353
var dataUpdate = {};
6454
var dataIndices = [];
6555
var carrs = [];
@@ -96,9 +86,10 @@ module.exports = function handleClick(g, gd, numClicks) {
9686
function setVisibility(fullTrace, visibility) {
9787
if(legendItem.groupTitle && !toggleGroup) return;
9888

99-
var fullInput = fullTrace._fullInput;
89+
var fullInput = fullTrace._fullInput || fullTrace;
10090
var isShape = fullInput._isShape;
10191
var index = fullInput.index;
92+
if(index === undefined) index = fullInput._index;
10293

10394
if(Registry.hasTransform(fullInput, 'groupby')) {
10495
var kcont = carrs[index];

0 commit comments

Comments
 (0)