Skip to content

do not return with empty legend items to clear old legends #6695

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 1 commit into from
Aug 2, 2023
Merged
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: 1 addition & 1 deletion src/components/legend/draw.js
Original file line number Diff line number Diff line change
@@ -113,7 +113,7 @@ function drawOne(gd, opts) {

calcdata.push([{ trace: shapeLegend }]);
}
if(!calcdata.length) return;

legendData = fullLayout.showlegend && getLegendData(calcdata, legendObj, fullLayout._legends.length > 1);
} else {
if(!legendObj.entries) return;
30 changes: 30 additions & 0 deletions test/jasmine/tests/legend_test.js
Original file line number Diff line number Diff line change
@@ -1204,6 +1204,36 @@ describe('legend relayout update', function() {
.then(done, done.fail);
});

it('should clear an empty legend & add legend using react', function(done) {
var fig1 = {
data: [{y: [1, 2]}],
layout: {showlegend: true}
};

var fig2 = {
data: [],
layout: {showlegend: true}
};

Plotly.newPlot(gd, fig1)
.then(function() {
expect(d3SelectAll('.legend')[0].length).toBe(1);
})
.then(function() {
return Plotly.react(gd, fig2);
})
.then(function() {
expect(d3SelectAll('.legend')[0].length).toBe(0);
})
.then(function() {
return Plotly.react(gd, fig1);
})
.then(function() {
expect(d3SelectAll('.legend')[0].length).toBe(1);
})
.then(done, done.fail);
});

it('should be able to add & clear multiple legends using react', function(done) {
var fig1 = {
data: [{