@@ -11,7 +11,7 @@ var mock = require('../../image/mocks/legend_scroll.json');
1111describe ( 'The legend' , function ( ) {
1212 'use strict' ;
1313
14- var gd , legend ;
14+ var gd , legend , bg ;
1515
1616 function countLegendGroups ( gd ) {
1717 return gd . _fullLayout . _toppaper . selectAll ( 'g.legend' ) . size ( ) ;
@@ -27,6 +27,9 @@ describe('The legend', function() {
2727 return gd . _fullLayout . height - gd . _fullLayout . margin . t - gd . _fullLayout . margin . b ;
2828 }
2929
30+ function getLegendHeight ( ) {
31+ return gd . _fullLayout . legend . borderwidth + getBBox ( bg ) . height ;
32+ }
3033
3134 describe ( 'when plotted with many traces' , function ( ) {
3235 beforeEach ( function ( done ) {
@@ -36,14 +39,15 @@ describe('The legend', function() {
3639
3740 Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( function ( ) {
3841 legend = document . getElementsByClassName ( 'legend' ) [ 0 ] ;
42+ bg = document . getElementsByClassName ( 'bg' ) [ 0 ] ;
3943 done ( ) ;
4044 } ) ;
4145 } ) ;
4246
4347 afterEach ( destroyGraph ) ;
4448
4549 it ( 'should not exceed plot height' , function ( ) {
46- var legendHeight = getBBox ( legend ) . height ;
50+ var legendHeight = getLegendHeight ( ) ;
4751
4852 expect ( + legendHeight ) . toBe ( getPlotHeight ( gd ) ) ;
4953 } ) ;
@@ -57,7 +61,7 @@ describe('The legend', function() {
5761
5862 it ( 'should scroll when there\'s a wheel event' , function ( ) {
5963 var scrollBox = legend . getElementsByClassName ( 'scrollbox' ) [ 0 ] ,
60- legendHeight = getBBox ( legend ) . height ,
64+ legendHeight = getLegendHeight ( ) ,
6165 scrollBoxYMax = gd . _fullLayout . legend . height - legendHeight ,
6266 scrollBarYMax = legendHeight -
6367 constants . scrollBarHeight -
@@ -87,7 +91,7 @@ describe('The legend', function() {
8791
8892 it ( 'should scale the scrollbar movement from top to bottom' , function ( ) {
8993 var scrollBar = legend . getElementsByClassName ( 'scrollbar' ) [ 0 ] ,
90- legendHeight = getBBox ( legend ) . height ;
94+ legendHeight = getLegendHeight ( ) ;
9195
9296 // The scrollbar is 20px tall and has 4px margins
9397
@@ -111,10 +115,10 @@ describe('The legend', function() {
111115 } ) ;
112116
113117 it ( 'should resize when relayout\'ed with new height' , function ( done ) {
114- var origLegendHeight = getBBox ( legend ) . height ;
118+ var origLegendHeight = getLegendHeight ( ) ;
115119
116120 Plotly . relayout ( gd , 'height' , gd . _fullLayout . height / 2 ) . then ( function ( ) {
117- var legendHeight = getBBox ( legend ) . height ;
121+ var legendHeight = getLegendHeight ( ) ;
118122
119123 //legend still exists and not duplicated
120124 expect ( countLegendGroups ( gd ) ) . toBe ( 1 ) ;
@@ -164,14 +168,15 @@ describe('The legend', function() {
164168 } ) ;
165169
166170 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 ( ) ;
169174
170175 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 ( ) ;
173179
174- // clippath resized to show new trace
175180 expect ( + legendHeight ) . toBeCloseTo ( + origLegendHeight + 19 , 0 ) ;
176181
177182 done ( ) ;
0 commit comments