@@ -52,8 +52,22 @@ describe('one-to-one transforms:', function() {
52
52
} ] ) ;
53
53
} ) ;
54
54
55
- it ( 'supplyDataDefaults should apply the transform' , function ( ) {
55
+ it ( 'supplyTraceDefaults should not bail if transform module is not found' , function ( ) {
56
+ var traceIn = {
57
+ y : [ 2 , 1 , 2 ] ,
58
+ transforms : [ { type : 'invalid' } ]
59
+ } ;
60
+
61
+ var traceOut = Plots . supplyTraceDefaults ( traceIn , 0 , { } ) ;
62
+
63
+ expect ( traceOut . y ) . toBe ( traceIn . y ) ;
64
+ } ) ;
65
+
66
+ it ( 'supplyDataDefaults should apply the transform while' , function ( ) {
56
67
var dataIn = [ {
68
+ x : [ - 2 , - 2 , 1 , 2 , 3 ] ,
69
+ y : [ 1 , 2 , 2 , 3 , 1 ] ,
70
+ } , {
57
71
x : [ - 2 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ,
58
72
y : [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ,
59
73
transforms : [ {
@@ -67,47 +81,55 @@ describe('one-to-one transforms:', function() {
67
81
var dataOut = [ ] ;
68
82
Plots . supplyDataDefaults ( dataIn , dataOut , { } , [ ] ) ;
69
83
70
- // does not mutate user data
71
- expect ( dataIn [ 0 ] . x ) . toEqual ( [ - 2 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ) ;
72
- expect ( dataIn [ 0 ] . y ) . toEqual ( [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ) ;
73
- expect ( dataIn [ 0 ] . transforms ) . toEqual ( [ {
84
+ var msg ;
85
+
86
+ msg = 'does not mutate user data' ;
87
+ expect ( dataIn [ 1 ] . x ) . toEqual ( [ - 2 , - 1 , - 2 , 0 , 1 , 2 , 3 ] , msg ) ;
88
+ expect ( dataIn [ 1 ] . y ) . toEqual ( [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] , msg ) ;
89
+ expect ( dataIn [ 1 ] . transforms ) . toEqual ( [ {
74
90
type : 'filter' ,
75
91
operation : '>' ,
76
92
value : '0' ,
77
93
filtersrc : 'x'
78
- } ] ) ;
94
+ } ] , msg ) ;
79
95
80
- // applies transform
81
- expect ( dataOut [ 0 ] . x ) . toEqual ( [ 1 , 2 , 3 ] ) ;
82
- expect ( dataOut [ 0 ] . y ) . toEqual ( [ 2 , 3 , 1 ] ) ;
96
+ msg = ' applies transform' ;
97
+ expect ( dataOut [ 1 ] . x ) . toEqual ( [ 1 , 2 , 3 ] , msg ) ;
98
+ expect ( dataOut [ 1 ] . y ) . toEqual ( [ 2 , 3 , 1 ] , msg ) ;
83
99
84
- // TODO what is the expected behavior ???
85
- // expect(dataOut[0].transforms).toEqual([]);
100
+ msg = 'supplying the transform defaults' ;
101
+ expect ( dataOut [ 1 ] . transforms [ 0 ] ) . toEqual ( {
102
+ type : 'filter' ,
103
+ operation : '>' ,
104
+ value : 0 ,
105
+ filtersrc : 'x'
106
+ } , msg ) ;
86
107
87
- // keep ref to user data
88
- expect ( dataOut [ 0 ] . _input . x ) . toEqual ( [ - 2 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ) ;
89
- expect ( dataOut [ 0 ] . _input . y ) . toEqual ( [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ) ;
90
- expect ( dataOut [ 0 ] . _input . transforms ) . toEqual ( [ {
108
+ msg = 'keeping refs to user data' ;
109
+ expect ( dataOut [ 1 ] . _input . x ) . toEqual ( [ - 2 , - 1 , - 2 , 0 , 1 , 2 , 3 ] , msg ) ;
110
+ expect ( dataOut [ 1 ] . _input . y ) . toEqual ( [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] , msg ) ;
111
+ expect ( dataOut [ 1 ] . _input . transforms ) . toEqual ( [ {
91
112
type : 'filter' ,
92
113
operation : '>' ,
93
114
value : '0' ,
94
115
filtersrc : 'x'
95
- } ] ) ;
116
+ } ] , msg ) ;
96
117
97
- // keep ref to full transforms array
98
- expect ( dataOut [ 0 ] . _fullInput . transforms ) . toEqual ( [ {
118
+ msg = 'keeping refs to full transforms array' ;
119
+ expect ( dataOut [ 1 ] . _fullInput . transforms ) . toEqual ( [ {
99
120
type : 'filter' ,
100
121
operation : '>' ,
101
122
value : 0 ,
102
123
filtersrc : 'x'
103
- } ] ) ;
124
+ } ] , msg ) ;
104
125
105
- // set index w.r.t. fullData
106
- expect ( dataOut [ 0 ] . index ) . toEqual ( 0 ) ;
126
+ msg = 'setting index w.r.t user data' ;
127
+ expect ( dataOut [ 0 ] . index ) . toEqual ( 0 , msg ) ;
128
+ expect ( dataOut [ 1 ] . index ) . toEqual ( 1 , msg ) ;
107
129
108
- // TODO do we really need this ???
109
- // set _index w.r.t. user data
110
- expect ( dataOut [ 0 ] . index ) . toEqual ( 0 ) ;
130
+ msg = 'setting _expandedIndex w.r.t full data' ;
131
+ expect ( dataOut [ 0 ] . _expandedIndex ) . toEqual ( 0 , msg ) ;
132
+ expect ( dataOut [ 1 ] . _expandedIndex ) . toEqual ( 1 , msg ) ;
111
133
} ) ;
112
134
113
135
it ( 'Plotly.plot should plot the transform trace' , function ( done ) {
@@ -130,22 +152,34 @@ describe('one-to-one transforms:', function() {
130
152
var gd = createGraphDiv ( ) ;
131
153
var dims = [ 3 ] ;
132
154
155
+ var uid ;
156
+ function assertUid ( gd ) {
157
+ expect ( gd . _fullData [ 0 ] . uid )
158
+ . toEqual ( uid + '0' , 'should preserve uid on restyle' ) ;
159
+ }
160
+
133
161
Plotly . plot ( gd , data ) . then ( function ( ) {
162
+ uid = gd . data [ 0 ] . uid ;
163
+
134
164
expect ( gd . _fullData [ 0 ] . marker . color ) . toEqual ( 'red' ) ;
165
+ assertUid ( gd ) ;
135
166
assertStyle ( dims , [ 'rgb(255, 0, 0)' ] , [ 1 ] ) ;
136
167
137
168
return Plotly . restyle ( gd , 'marker.color' , 'blue' ) ;
138
169
} ) . then ( function ( ) {
139
170
expect ( gd . _fullData [ 0 ] . marker . color ) . toEqual ( 'blue' ) ;
171
+ assertUid ( gd ) ;
140
172
assertStyle ( dims , [ 'rgb(0, 0, 255)' ] , [ 1 ] ) ;
141
173
142
174
return Plotly . restyle ( gd , 'marker.color' , 'red' ) ;
143
175
} ) . then ( function ( ) {
144
176
expect ( gd . _fullData [ 0 ] . marker . color ) . toEqual ( 'red' ) ;
177
+ assertUid ( gd ) ;
145
178
assertStyle ( dims , [ 'rgb(255, 0, 0)' ] , [ 1 ] ) ;
146
179
147
180
return Plotly . restyle ( gd , 'transforms[0].value' , 2.5 ) ;
148
181
} ) . then ( function ( ) {
182
+ assertUid ( gd ) ;
149
183
assertStyle ( [ 1 ] , [ 'rgb(255, 0, 0)' ] , [ 1 ] ) ;
150
184
151
185
done ( ) ;
@@ -251,6 +285,34 @@ describe('one-to-many transforms:', function() {
251
285
252
286
afterEach ( destroyGraphDiv ) ;
253
287
288
+ it ( 'supplyDataDefaults should apply the transform while' , function ( ) {
289
+ var dummyTrace0 = {
290
+ x : [ - 2 , - 2 , 1 , 2 , 3 ] ,
291
+ y : [ 1 , 2 , 2 , 3 , 1 ] ,
292
+ } ;
293
+
294
+ var dummyTrace1 = {
295
+ x : [ - 1 , 2 , 3 ] ,
296
+ y : [ 2 , 3 , 1 ] ,
297
+ } ;
298
+
299
+ var dataIn = [
300
+ dummyTrace0 ,
301
+ Lib . extendDeep ( { } , mockData0 [ 0 ] ) ,
302
+ dummyTrace1 ,
303
+ Lib . extendDeep ( { } , mockData1 [ 0 ] )
304
+ ] ;
305
+
306
+ var dataOut = [ ] ;
307
+ Plots . supplyDataDefaults ( dataIn , dataOut , { } , [ ] ) ;
308
+
309
+ expect ( dataOut . map ( function ( trace ) { return trace . index ; } ) )
310
+ . toEqual ( [ 0 , 1 , 1 , 2 , 3 , 3 ] , 'setting index w.r.t user data' ) ;
311
+
312
+ expect ( dataOut . map ( function ( trace ) { return trace . _expandedIndex ; } ) )
313
+ . toEqual ( [ 0 , 1 , 2 , 3 , 4 , 5 ] , 'setting index w.r.t full data' ) ;
314
+ } ) ;
315
+
254
316
it ( 'Plotly.plot should plot the transform traces' , function ( done ) {
255
317
var data = Lib . extendDeep ( [ ] , mockData0 ) ;
256
318
@@ -428,6 +490,34 @@ describe('multiple transforms:', function() {
428
490
429
491
afterEach ( destroyGraphDiv ) ;
430
492
493
+ it ( 'supplyDataDefaults should apply the transform while' , function ( ) {
494
+ var dummyTrace0 = {
495
+ x : [ - 2 , - 2 , 1 , 2 , 3 ] ,
496
+ y : [ 1 , 2 , 2 , 3 , 1 ] ,
497
+ } ;
498
+
499
+ var dummyTrace1 = {
500
+ x : [ - 1 , 2 , 3 ] ,
501
+ y : [ 2 , 3 , 1 ] ,
502
+ } ;
503
+
504
+ var dataIn = [
505
+ dummyTrace0 ,
506
+ Lib . extendDeep ( { } , mockData0 [ 0 ] ) ,
507
+ Lib . extendDeep ( { } , mockData1 [ 0 ] ) ,
508
+ dummyTrace1
509
+ ] ;
510
+
511
+ var dataOut = [ ] ;
512
+ Plots . supplyDataDefaults ( dataIn , dataOut , { } , [ ] ) ;
513
+
514
+ expect ( dataOut . map ( function ( trace ) { return trace . index ; } ) )
515
+ . toEqual ( [ 0 , 1 , 1 , 2 , 2 , 3 ] , 'setting index w.r.t user data' ) ;
516
+
517
+ expect ( dataOut . map ( function ( trace ) { return trace . _expandedIndex ; } ) )
518
+ . toEqual ( [ 0 , 1 , 2 , 3 , 4 , 5 ] , 'setting index w.r.t full data' ) ;
519
+ } ) ;
520
+
431
521
it ( 'Plotly.plot should plot the transform traces' , function ( done ) {
432
522
var data = Lib . extendDeep ( [ ] , mockData0 ) ;
433
523
@@ -625,6 +715,34 @@ describe('multiple traces with transforms:', function() {
625
715
626
716
afterEach ( destroyGraphDiv ) ;
627
717
718
+ it ( 'supplyDataDefaults should apply the transform while' , function ( ) {
719
+ var dummyTrace0 = {
720
+ x : [ - 2 , - 2 , 1 , 2 , 3 ] ,
721
+ y : [ 1 , 2 , 2 , 3 , 1 ] ,
722
+ } ;
723
+
724
+ var dummyTrace1 = {
725
+ x : [ - 1 , 2 , 3 ] ,
726
+ y : [ 2 , 3 , 1 ] ,
727
+ } ;
728
+
729
+ var dataIn = [
730
+ dummyTrace0 ,
731
+ Lib . extendDeep ( { } , mockData0 [ 0 ] ) ,
732
+ Lib . extendDeep ( { } , mockData0 [ 1 ] ) ,
733
+ dummyTrace1
734
+ ] ;
735
+
736
+ var dataOut = [ ] ;
737
+ Plots . supplyDataDefaults ( dataIn , dataOut , { } , [ ] ) ;
738
+
739
+ expect ( dataOut . map ( function ( trace ) { return trace . index ; } ) )
740
+ . toEqual ( [ 0 , 1 , 2 , 2 , 3 ] , 'setting index w.r.t user data' ) ;
741
+
742
+ expect ( dataOut . map ( function ( trace ) { return trace . _expandedIndex ; } ) )
743
+ . toEqual ( [ 0 , 1 , 2 , 3 , 4 ] , 'setting index w.r.t full data' ) ;
744
+ } ) ;
745
+
628
746
it ( 'Plotly.plot should plot the transform traces' , function ( done ) {
629
747
var data = Lib . extendDeep ( [ ] , mockData0 ) ;
630
748
0 commit comments