Skip to content

Commit a565dc6

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 a565dc6

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

test/jasmine/tests/legend_scroll_test.js

+43-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ describe('The legend', function() {
2020
return gd._fullLayout._topdefs.selectAll('#legend' + uid).size();
2121
}
2222

23+
function getPlotHeight(gd) {
24+
return gd._fullLayout.height - gd._fullLayout.margin.t - gd._fullLayout.margin.b;
25+
}
26+
27+
2328
describe('when plotted with many traces', function() {
2429
beforeEach(function() {
2530
gd = createGraph();
@@ -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;
38+
var legendHeight = getBBox(legend).height;
3539

36-
expect(+legendHeight).toBe(plotHeight);
40+
expect(+legendHeight).toBe(getPlotHeight(gd));
3741
});
3842

3943
it('should insert a scrollbar', function() {
@@ -88,10 +92,30 @@ 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 legendHeight = getBBox(legend).height;
101+
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+
});
113+
*/
91114
});
92115

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

96120
beforeEach(function() {
97121
gd = createGraph();
@@ -122,6 +146,21 @@ describe('The legend', function() {
122146
done();
123147
});
124148
});
149+
150+
it('should resize when traces added', function(done) {
151+
legend = document.getElementsByClassName('legend')[0];
152+
var origLegendHeight = getBBox(legend).height;
153+
/*
154+
Plotly.addTrace(gd, { x: [1,2,3], y: [4,3,2], name: 'Test2' }).then(function() {
155+
var legend = document.getElementsByClassName('legend')[0];
156+
var legendHeight = getBBox(legend).height;
157+
// clippath resized to show new trace
158+
expect(+legendHeight).toBeCloseTo(+origLegendHeight+18, 0);
159+
160+
done();
161+
});
162+
*/
163+
});
125164
});
126165
});
127166

0 commit comments

Comments
 (0)