Skip to content

Commit f4baaf6

Browse files
authored
Merge pull request #6695 from plotly/fix6694-legend-update
do not return with empty legend items to clear old legends
2 parents cdcd86e + fd11108 commit f4baaf6

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/components/legend/draw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function drawOne(gd, opts) {
113113

114114
calcdata.push([{ trace: shapeLegend }]);
115115
}
116-
if(!calcdata.length) return;
116+
117117
legendData = fullLayout.showlegend && getLegendData(calcdata, legendObj, fullLayout._legends.length > 1);
118118
} else {
119119
if(!legendObj.entries) return;

test/jasmine/tests/legend_test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,36 @@ describe('legend relayout update', function() {
12041204
.then(done, done.fail);
12051205
});
12061206

1207+
it('should clear an empty legend & add legend using react', function(done) {
1208+
var fig1 = {
1209+
data: [{y: [1, 2]}],
1210+
layout: {showlegend: true}
1211+
};
1212+
1213+
var fig2 = {
1214+
data: [],
1215+
layout: {showlegend: true}
1216+
};
1217+
1218+
Plotly.newPlot(gd, fig1)
1219+
.then(function() {
1220+
expect(d3SelectAll('.legend')[0].length).toBe(1);
1221+
})
1222+
.then(function() {
1223+
return Plotly.react(gd, fig2);
1224+
})
1225+
.then(function() {
1226+
expect(d3SelectAll('.legend')[0].length).toBe(0);
1227+
})
1228+
.then(function() {
1229+
return Plotly.react(gd, fig1);
1230+
})
1231+
.then(function() {
1232+
expect(d3SelectAll('.legend')[0].length).toBe(1);
1233+
})
1234+
.then(done, done.fail);
1235+
});
1236+
12071237
it('should be able to add & clear multiple legends using react', function(done) {
12081238
var fig1 = {
12091239
data: [{

0 commit comments

Comments
 (0)