@@ -11,7 +11,7 @@ var mock = require('../../image/mocks/legend_scroll.json');
11
11
describe ( 'The legend' , function ( ) {
12
12
'use strict' ;
13
13
14
- var gd , legend ;
14
+ var gd , legend , bg ;
15
15
16
16
function countLegendGroups ( gd ) {
17
17
return gd . _fullLayout . _toppaper . selectAll ( 'g.legend' ) . size ( ) ;
@@ -27,6 +27,9 @@ describe('The legend', function() {
27
27
return gd . _fullLayout . height - gd . _fullLayout . margin . t - gd . _fullLayout . margin . b ;
28
28
}
29
29
30
+ function getLegendHeight ( ) {
31
+ return gd . _fullLayout . legend . borderwidth + getBBox ( bg ) . height ;
32
+ }
30
33
31
34
describe ( 'when plotted with many traces' , function ( ) {
32
35
beforeEach ( function ( done ) {
@@ -36,14 +39,15 @@ describe('The legend', function() {
36
39
37
40
Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( function ( ) {
38
41
legend = document . getElementsByClassName ( 'legend' ) [ 0 ] ;
42
+ bg = document . getElementsByClassName ( 'bg' ) [ 0 ] ;
39
43
done ( ) ;
40
44
} ) ;
41
45
} ) ;
42
46
43
47
afterEach ( destroyGraph ) ;
44
48
45
49
it ( 'should not exceed plot height' , function ( ) {
46
- var legendHeight = getBBox ( legend ) . height ;
50
+ var legendHeight = getLegendHeight ( ) ;
47
51
48
52
expect ( + legendHeight ) . toBe ( getPlotHeight ( gd ) ) ;
49
53
} ) ;
@@ -57,7 +61,7 @@ describe('The legend', function() {
57
61
58
62
it ( 'should scroll when there\'s a wheel event' , function ( ) {
59
63
var scrollBox = legend . getElementsByClassName ( 'scrollbox' ) [ 0 ] ,
60
- legendHeight = getBBox ( legend ) . height ,
64
+ legendHeight = getLegendHeight ( ) ,
61
65
scrollBoxYMax = gd . _fullLayout . legend . height - legendHeight ,
62
66
scrollBarYMax = legendHeight -
63
67
constants . scrollBarHeight -
@@ -87,7 +91,7 @@ describe('The legend', function() {
87
91
88
92
it ( 'should scale the scrollbar movement from top to bottom' , function ( ) {
89
93
var scrollBar = legend . getElementsByClassName ( 'scrollbar' ) [ 0 ] ,
90
- legendHeight = getBBox ( legend ) . height ;
94
+ legendHeight = getLegendHeight ( ) ;
91
95
92
96
// The scrollbar is 20px tall and has 4px margins
93
97
@@ -111,10 +115,10 @@ describe('The legend', function() {
111
115
} ) ;
112
116
113
117
it ( 'should resize when relayout\'ed with new height' , function ( done ) {
114
- var origLegendHeight = getBBox ( legend ) . height ;
118
+ var origLegendHeight = getLegendHeight ( ) ;
115
119
116
120
Plotly . relayout ( gd , 'height' , gd . _fullLayout . height / 2 ) . then ( function ( ) {
117
- var legendHeight = getBBox ( legend ) . height ;
121
+ var legendHeight = getLegendHeight ( ) ;
118
122
119
123
//legend still exists and not duplicated
120
124
expect ( countLegendGroups ( gd ) ) . toBe ( 1 ) ;
@@ -164,14 +168,15 @@ describe('The legend', function() {
164
168
} ) ;
165
169
166
170
it ( 'should resize when traces added' , function ( done ) {
167
- var origLegend = document . getElementsByClassName ( 'legend' ) [ 0 ] ;
168
- var origLegendHeight = getBBox ( origLegend ) . height ;
171
+ legend = document . getElementsByClassName ( 'legend' ) [ 0 ] ;
172
+ bg = document . getElementsByClassName ( 'bg' ) [ 0 ] ;
173
+ var origLegendHeight = getLegendHeight ( ) ;
169
174
170
175
Plotly . addTraces ( gd , { x : [ 1 , 2 , 3 ] , y : [ 4 , 3 , 2 ] , name : 'Test2' } ) . then ( function ( ) {
171
- var legend = document . getElementsByClassName ( 'legend' ) [ 0 ] ;
172
- var legendHeight = getBBox ( legend ) . height ;
176
+ legend = document . getElementsByClassName ( 'legend' ) [ 0 ] ;
177
+ bg = document . getElementsByClassName ( 'bg' ) [ 0 ] ;
178
+ var legendHeight = getLegendHeight ( ) ;
173
179
174
- // clippath resized to show new trace
175
180
expect ( + legendHeight ) . toBeCloseTo ( + origLegendHeight + 19 , 0 ) ;
176
181
177
182
done ( ) ;
0 commit comments