@@ -20,6 +20,11 @@ describe('The legend', function() {
20
20
return gd . _fullLayout . _topdefs . selectAll ( '#legend' + uid ) . size ( ) ;
21
21
}
22
22
23
+ function getPlotHeight ( gd ) {
24
+ return gd . _fullLayout . height - gd . _fullLayout . margin . t - gd . _fullLayout . margin . b ;
25
+ }
26
+
27
+
23
28
describe ( 'when plotted with many traces' , function ( ) {
24
29
beforeEach ( function ( ) {
25
30
gd = createGraph ( ) ;
@@ -30,10 +35,9 @@ describe('The legend', function() {
30
35
afterEach ( destroyGraph ) ;
31
36
32
37
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 ;
35
39
36
- expect ( + legendHeight ) . toBe ( plotHeight ) ;
40
+ expect ( + legendHeight ) . toBe ( getPlotHeight ( gd ) ) ;
37
41
} ) ;
38
42
39
43
it ( 'should insert a scrollbar' , function ( ) {
@@ -88,10 +92,30 @@ describe('The legend', function() {
88
92
done ( ) ;
89
93
} ) ;
90
94
} ) ;
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
+ */
91
114
} ) ;
92
115
116
+
93
117
describe ( 'when plotted with few traces' , function ( ) {
94
- var gd ;
118
+ var gd , legend ;
95
119
96
120
beforeEach ( function ( ) {
97
121
gd = createGraph ( ) ;
@@ -122,6 +146,21 @@ describe('The legend', function() {
122
146
done ( ) ;
123
147
} ) ;
124
148
} ) ;
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
+ } ) ;
125
164
} ) ;
126
165
} ) ;
127
166
0 commit comments