Skip to content

Commit cbbb16c

Browse files
authored
Merge pull request #4827 from plotly/react-legend-title
Fix legend title react
2 parents 5d35b78 + 2502876 commit cbbb16c

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/components/legend/draw.js

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ module.exports = function draw(gd, opts) {
9494
.text(title.text);
9595

9696
textLayout(titleEl, scrollBox, gd, opts); // handle mathjax or multi-line text and compute title height
97+
} else {
98+
scrollBox.selectAll('.legendtitletext').remove();
9799
}
98100

99101
var scrollBar = Lib.ensureSingle(legend, 'rect', 'scrollbar', function(s) {

test/jasmine/tests/legend_test.js

+36
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,42 @@ describe('legend relayout update', function() {
818818
.catch(failTest)
819819
.then(done);
820820
});
821+
822+
it('should be able to clear legend title using react', function(done) {
823+
var data = [{
824+
type: 'scatter',
825+
x: [0, 1],
826+
y: [1, 0]
827+
}];
828+
829+
Plotly.newPlot(gd, {
830+
data: data,
831+
layout: {
832+
showlegend: true,
833+
legend: {
834+
title: {
835+
text: 'legend<br>title'
836+
}
837+
}
838+
}
839+
})
840+
.then(function() {
841+
expect(d3.selectAll('.legendtitletext')[0].length).toBe(1);
842+
})
843+
.then(function() {
844+
Plotly.react(gd, {
845+
data: data,
846+
layout: {
847+
showlegend: true
848+
}
849+
});
850+
})
851+
.then(function() {
852+
expect(d3.selectAll('.legendtitletext')[0].length).toBe(0);
853+
})
854+
.catch(failTest)
855+
.then(done);
856+
});
821857
});
822858

823859
describe('legend orientation change:', function() {

0 commit comments

Comments
 (0)