@@ -10,6 +10,16 @@ describe('The legend', function() {
10
10
11
11
var gd , legend ;
12
12
13
+ function countLegendGroups ( gd ) {
14
+ return gd . _fullLayout . _toppaper . selectAll ( 'g.legend' ) . size ( ) ;
15
+ }
16
+
17
+ function countLegendClipPaths ( gd ) {
18
+ var uid = gd . _fullLayout . _uid ;
19
+
20
+ return gd . _fullLayout . _topdefs . selectAll ( '#legend' + uid ) . size ( ) ;
21
+ }
22
+
13
23
describe ( 'when plotted with many traces' , function ( ) {
14
24
beforeEach ( function ( ) {
15
25
gd = createGraph ( ) ;
@@ -66,22 +76,51 @@ describe('The legend', function() {
66
76
legend . dispatchEvent ( scrollTo ( 10000 ) ) ;
67
77
expect ( + scrollBar . getAttribute ( 'y' ) ) . toBe ( legendHeight - 4 - 20 ) ;
68
78
} ) ;
79
+
80
+ it ( 'should be removed from DOM when \'showlegend\' is relayout\'ed to false' , function ( done ) {
81
+ expect ( countLegendGroups ( gd ) ) . toBe ( 1 ) ;
82
+ expect ( countLegendClipPaths ( gd ) ) . toBe ( 1 ) ;
83
+
84
+ Plotly . relayout ( gd , 'showlegend' , false ) . then ( function ( ) {
85
+ expect ( countLegendGroups ( gd ) ) . toBe ( 0 ) ;
86
+ expect ( countLegendClipPaths ( gd ) ) . toBe ( 0 ) ;
87
+
88
+ done ( ) ;
89
+ } ) ;
90
+ } ) ;
69
91
} ) ;
70
92
71
93
describe ( 'when plotted with few traces' , function ( ) {
72
94
var gd ;
73
95
74
96
beforeEach ( function ( ) {
75
97
gd = createGraph ( ) ;
76
- Plotly . plot ( gd , [ { x : [ 1 , 2 , 3 ] , y : [ 2 , 3 , 4 ] , name : 'Test' } ] , { } ) ;
98
+
99
+ var data = [ { x : [ 1 , 2 , 3 ] , y : [ 2 , 3 , 4 ] , name : 'Test' } ] ;
100
+ var layout = { showlegend : true } ;
101
+
102
+ Plotly . plot ( gd , data , layout ) ;
77
103
} ) ;
78
104
79
105
afterEach ( destroyGraph ) ;
80
106
81
107
it ( 'should not display the scrollbar' , function ( ) {
82
108
var scrollBar = document . getElementsByClassName ( 'scrollbar' ) [ 0 ] ;
83
109
84
- expect ( scrollBar ) . toBeUndefined ( ) ;
110
+ expect ( + scrollBar . getAttribute ( 'width' ) ) . toBe ( 0 ) ;
111
+ expect ( + scrollBar . getAttribute ( 'height' ) ) . toBe ( 0 ) ;
112
+ } ) ;
113
+
114
+ it ( 'should be removed from DOM when \'showlegend\' is relayout\'ed to false' , function ( done ) {
115
+ expect ( countLegendGroups ( gd ) ) . toBe ( 1 ) ;
116
+ expect ( countLegendClipPaths ( gd ) ) . toBe ( 1 ) ;
117
+
118
+ Plotly . relayout ( gd , 'showlegend' , false ) . then ( function ( ) {
119
+ expect ( countLegendGroups ( gd ) ) . toBe ( 0 ) ;
120
+ expect ( countLegendClipPaths ( gd ) ) . toBe ( 0 ) ;
121
+
122
+ done ( ) ;
123
+ } ) ;
85
124
} ) ;
86
125
} ) ;
87
126
} ) ;
0 commit comments