Skip to content

Fix double clicking one item in a legend hides traces in other legends #6655

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 2 commits into from
Jun 30, 2023
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
1 change: 1 addition & 0 deletions draftlogs/6655_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix double clicking one item in a legend hides traces in other legends [[#6655](https://github.com/plotly/plotly.js/pull/6655)]
5 changes: 3 additions & 2 deletions src/components/legend/handle_click.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ module.exports = function handleClick(g, gd, numClicks) {
}
}

var thisLegend = fullTrace.legend;
for(i = 0; i < fullData.length; i++) {
// False is sticky; we don't change it.
if(fullData[i].visible === false) continue;
// False is sticky; we don't change it. Also ensure we don't change states of itmes in other legend
if(fullData[i].visible === false || fullData[i].legend !== thisLegend) continue;

if(Registry.traceIs(fullData[i], 'notLegendIsolatable')) {
continue;
Expand Down
56 changes: 56 additions & 0 deletions test/jasmine/tests/legend_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,62 @@ describe('legend interaction', function() {
});
});

describe('traces in different legends', function() {
beforeEach(function(done) {
Plotly.newPlot(gd, [
{x: [1, 2], y: [0, 1], visible: false},
{x: [1, 2], y: [1, 2], visible: 'legendonly'},
{x: [1, 2], y: [2, 3]},
{x: [1, 2], y: [0, 1], yaxis: 'y2', legend: 'legend2', visible: false},
{x: [1, 2], y: [1, 2], yaxis: 'y2', legend: 'legend2', visible: 'legendonly'},
{x: [1, 2], y: [2, 3], yaxis: 'y2', legend: 'legend2'}
], {
yaxis: {
domain: [0.55, 1]
},
yaxis2: {
anchor: 'x',
domain: [0, 0.45]
},
legend2: {
y: 0.5
}
}).then(done);
});

it('clicking once toggles legendonly -> true', function(done) {
Promise.resolve()
.then(assertVisible([false, 'legendonly', true, false, 'legendonly', true]))
.then(click(0))
.then(assertVisible([false, true, true, false, 'legendonly', true]))
.then(done, done.fail);
});

it('clicking once toggles true -> legendonly', function(done) {
Promise.resolve()
.then(assertVisible([false, 'legendonly', true, false, 'legendonly', true]))
.then(click(1))
.then(assertVisible([false, 'legendonly', 'legendonly', false, 'legendonly', true]))
.then(done, done.fail);
});

it('double-clicking isolates a visible trace ', function(done) {
Promise.resolve()
.then(click(0))
.then(assertVisible([false, true, true, false, 'legendonly', true]))
.then(click(0, 2))
.then(assertVisible([false, true, 'legendonly', false, 'legendonly', true]))
.then(done, done.fail);
});

it('double-clicking an isolated trace shows all non-hidden traces', function(done) {
Promise.resolve()
.then(click(0, 2))
.then(assertVisible([false, true, true, false, 'legendonly', true]))
.then(done, done.fail);
});
});

describe('legendgroup visibility', function() {
beforeEach(function(done) {
Plotly.newPlot(gd, [{
Expand Down