1
1
var Plotly = require ( '@lib/index' ) ;
2
+ var Lib = require ( '@src/lib' ) ;
3
+
2
4
var createGraph = require ( '../assets/create_graph_div' ) ;
3
5
var destroyGraph = require ( '../assets/destroy_graph_div' ) ;
4
6
var getBBox = require ( '../assets/get_bbox' ) ;
@@ -26,10 +28,15 @@ describe('The legend', function() {
26
28
27
29
28
30
describe ( 'when plotted with many traces' , function ( ) {
29
- beforeEach ( function ( ) {
31
+ beforeEach ( function ( done ) {
30
32
gd = createGraph ( ) ;
31
- Plotly . plot ( gd , mock . data , mock . layout ) ;
32
- legend = document . getElementsByClassName ( 'legend' ) [ 0 ] ;
33
+
34
+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
35
+
36
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( function ( ) {
37
+ legend = document . getElementsByClassName ( 'legend' ) [ 0 ] ;
38
+ done ( ) ;
39
+ } ) ;
33
40
} ) ;
34
41
35
42
afterEach ( destroyGraph ) ;
@@ -96,7 +103,7 @@ describe('The legend', function() {
96
103
it ( 'should resize when relayout\'ed with new height' , function ( done ) {
97
104
var origLegendHeight = getBBox ( legend ) . height ;
98
105
99
- Plotly . relayout ( gd , { 'height' : gd . _fullLayout . height / 2 } ) . then ( function ( ) {
106
+ Plotly . relayout ( gd , 'height' , gd . _fullLayout . height / 2 ) . then ( function ( ) {
100
107
var legendHeight = getBBox ( legend ) . height ;
101
108
102
109
//legend still exists and not duplicated
@@ -114,7 +121,7 @@ describe('The legend', function() {
114
121
115
122
116
123
describe ( 'when plotted with few traces' , function ( ) {
117
- var gd , legend ;
124
+ var gd ;
118
125
119
126
beforeEach ( function ( ) {
120
127
gd = createGraph ( ) ;
@@ -147,14 +154,15 @@ describe('The legend', function() {
147
154
} ) ;
148
155
149
156
it ( 'should resize when traces added' , function ( done ) {
150
- legend = document . getElementsByClassName ( 'legend' ) [ 0 ] ;
151
- var origLegendHeight = getBBox ( legend ) . height ;
157
+ var origLegend = document . getElementsByClassName ( 'legend' ) [ 0 ] ;
158
+ var origLegendHeight = getBBox ( origLegend ) . height ;
152
159
153
- Plotly . addTrace ( gd , { x : [ 1 , 2 , 3 ] , y : [ 4 , 3 , 2 ] , name : 'Test2' } ) . then ( function ( ) {
160
+ Plotly . addTraces ( gd , { x : [ 1 , 2 , 3 ] , y : [ 4 , 3 , 2 ] , name : 'Test2' } ) . then ( function ( ) {
154
161
var legend = document . getElementsByClassName ( 'legend' ) [ 0 ] ;
155
162
var legendHeight = getBBox ( legend ) . height ;
163
+
156
164
// clippath resized to show new trace
157
- expect ( + legendHeight ) . toBeCloseTo ( + origLegendHeight + 18 , 0 ) ;
165
+ expect ( + legendHeight ) . toBeCloseTo ( + origLegendHeight + 19 , 0 ) ;
158
166
159
167
done ( ) ;
160
168
} ) ;
0 commit comments