Skip to content

Commit 43d430c

Browse files
add tests for legend resize and this forum [post](http://community.plot.ly/t/default-showlegend-changed-with-update/708)
1 parent 94bd5ff commit 43d430c

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

test/jasmine/tests/legend_scroll_test.js

+40-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ describe('The legend', function() {
1919

2020
return gd._fullLayout._topdefs.selectAll('#legend' + uid).size();
2121
}
22+
23+
function getPlotHeight(gd){
24+
return gd._fullLayout.height - gd._fullLayout.margin.t - gd._fullLayout.margin.b;
25+
}
26+
2227

2328
describe('when plotted with many traces', function() {
2429
beforeEach(function() {
@@ -30,10 +35,9 @@ describe('The legend', function() {
3035
afterEach(destroyGraph);
3136

3237
it('should not exceed plot height', function() {
33-
var legendHeight = getBBox(legend).height,
34-
plotHeight = gd._fullLayout.height - gd._fullLayout.margin.t - gd._fullLayout.margin.b;
35-
36-
expect(+legendHeight).toBe(plotHeight);
38+
var legendHeight = getBBox(legend).height;
39+
40+
expect(+legendHeight).toBe(getPlotHeight(gd));
3741
});
3842

3943
it('should insert a scrollbar', function() {
@@ -88,10 +92,28 @@ describe('The legend', function() {
8892
done();
8993
});
9094
});
95+
96+
it('should resize when relayout\'ed with new height', function(done) {
97+
var origLegendHeight = getBBox(legend).height;
98+
99+
Plotly.relayout(gd, {'height':gd._fullLayout.height/2}).then(function() {
100+
var legend = document.getElementsByClassName('legend')[0];
101+
var legendHeight = getBBox(legend).height;
102+
//legend still exists and not duplicated
103+
expect(countLegendGroups(gd)).toBe(1);
104+
expect(countLegendClipPaths(gd)).toBe(1);
105+
106+
// clippath resized to new height less than new plot height
107+
expect(+legendHeight).toBe(getPlotHeight(gd));
108+
expect(+legendHeight).toBeLessThan(+origLegendHeight);
109+
110+
done();
111+
});
112+
});
91113
});
92114

93115
describe('when plotted with few traces', function() {
94-
var gd;
116+
var gd, legend;
95117

96118
beforeEach(function() {
97119
gd = createGraph();
@@ -100,6 +122,8 @@ describe('The legend', function() {
100122
var layout = { showlegend: true };
101123

102124
Plotly.plot(gd, data, layout);
125+
126+
legend = document.getElementsByClassName('legend')[0]
103127
});
104128

105129
afterEach(destroyGraph);
@@ -122,6 +146,17 @@ describe('The legend', function() {
122146
done();
123147
});
124148
});
149+
150+
it('should resize when traces added', function(done) {
151+
var origLegendHeight = getBBox(legend).height;
152+
153+
Plotly.addTraces(gd, { x: [1,2,3], y: [4,3,2], name: 'Test2' }).then(function() {
154+
// clippath resized to show new trace
155+
expect(+legendHeight).toBeGreaterThan(+origLegendHeight);
156+
157+
done();
158+
});
159+
});
125160
});
126161
});
127162

0 commit comments

Comments
 (0)