Skip to content
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
2 changes: 1 addition & 1 deletion src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions test/jasmine/tests/legend_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [{
Expand Down