@@ -19,6 +19,11 @@ describe('The legend', function() {
19
19
20
20
return gd . _fullLayout . _topdefs . selectAll ( '#legend' + uid ) . size ( ) ;
21
21
}
22
+
23
+ function getPlotHeight ( gd ) {
24
+ return gd . _fullLayout . height - gd . _fullLayout . margin . t - gd . _fullLayout . margin . b ;
25
+ }
26
+
22
27
23
28
describe ( 'when plotted with many traces' , function ( ) {
24
29
beforeEach ( function ( ) {
@@ -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 ;
35
-
36
- expect ( + legendHeight ) . toBe ( plotHeight ) ;
38
+ var legendHeight = getBBox ( legend ) . height ;
39
+
40
+ expect ( + legendHeight ) . toBe ( getPlotHeight ( gd ) ) ;
37
41
} ) ;
38
42
39
43
it ( 'should insert a scrollbar' , function ( ) {
@@ -88,10 +92,28 @@ 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 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
+ } ) ;
91
113
} ) ;
92
114
93
115
describe ( 'when plotted with few traces' , function ( ) {
94
- var gd ;
116
+ var gd , legend ;
95
117
96
118
beforeEach ( function ( ) {
97
119
gd = createGraph ( ) ;
@@ -100,6 +122,8 @@ describe('The legend', function() {
100
122
var layout = { showlegend : true } ;
101
123
102
124
Plotly . plot ( gd , data , layout ) ;
125
+
126
+ legend = document . getElementsByClassName ( 'legend' ) [ 0 ]
103
127
} ) ;
104
128
105
129
afterEach ( destroyGraph ) ;
@@ -122,6 +146,17 @@ describe('The legend', function() {
122
146
done ( ) ;
123
147
} ) ;
124
148
} ) ;
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
+ } ) ;
125
160
} ) ;
126
161
} ) ;
127
162
0 commit comments