Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 42c40f6

Browse files
committed
Replace null value with early continue and skip non-displayed traces
1 parent 3a1336f commit 42c40f6

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/components/legend/handle_click.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ exports.handleTitleClick = function handleTitleClick(gd, legendObj, mode) {
303303
});
304304

305305
toggleThisLegend = !anyVisibleHere;
306-
toggleOtherLegends = null;
307306
} else {
308307
// isolate this legend or set all legends to visible
309308
const anyVisibleElsewhere = allLegendItems.some(function(item) {
@@ -321,11 +320,20 @@ exports.handleTitleClick = function handleTitleClick(gd, legendObj, mode) {
321320

322321
for(var i = 0; i < allLegendItems.length; i++) {
323322
const item = allLegendItems[i];
324-
const shouldShow = isInLegend(item) ? toggleThisLegend : toggleOtherLegends;
323+
const inThisLegend = isInLegend(item);
324+
325+
// If item is not in this legend, skip if in toggle mode
326+
// or if item is not displayed in the legend
327+
if(!inThisLegend) {
328+
const notDisplayed = (item.showlegend !== true && !item.legendgroup);
329+
if(mode === 'toggle' || notDisplayed) continue;
330+
}
331+
332+
const shouldShow = inThisLegend ? toggleThisLegend : toggleOtherLegends;
325333
const newVis = shouldShow ? true : 'legendonly';
326334

327-
// Only update if the item is visible and the visibility is different from the new visibility
328-
if ((item.visible !== false) && (shouldShow !== null) && (item.visible !== newVis)) {
335+
// Only update if visibility would actually change
336+
if((item.visible !== false) && (item.visible !== newVis)) {
329337
if(item._isShape) {
330338
updatedShapes[item._index].visible = newVis;
331339
shapesUpdated = true;

0 commit comments

Comments
 (0)