1
+ var attributes = require ( '@src/traces/sankey/attributes' ) ;
1
2
var Lib = require ( '@src/lib' ) ;
3
+ var mock = require ( '@mocks/energy.json' ) ;
4
+ var Plots = require ( '@src/plots/plots' ) ;
2
5
var Sankey = require ( '@src/traces/sankey' ) ;
3
- var attributes = require ( '@src/traces/sankey/attributes' ) ;
4
6
5
7
describe ( 'sankey tests' , function ( ) {
6
8
@@ -46,48 +48,6 @@ describe('sankey tests', function() {
46
48
} ) ;
47
49
} ) ;
48
50
49
- describe ( 'remove nodes if encountering circularity' , function ( ) {
50
-
51
- it ( 'removing a single self-pointing node' , function ( ) {
52
- var fullTrace = _supply ( {
53
- node : {
54
- label : [ 'a' ]
55
- } ,
56
- link : {
57
- value : [ 1 ] ,
58
- source : [ 0 ] ,
59
- target : [ 0 ]
60
- }
61
- } ) ;
62
-
63
- expect ( fullTrace . node . label ) . toEqual ( [ ] , 'node label(s) removed' ) ;
64
- expect ( fullTrace . link . value ) . toEqual ( [ ] , 'link value(s) removed' ) ;
65
- expect ( fullTrace . link . source ) . toEqual ( [ ] , 'link source(s) removed' ) ;
66
- expect ( fullTrace . link . target ) . toEqual ( [ ] , 'link target(s) removed' ) ;
67
-
68
- } ) ;
69
-
70
- it ( 'removing everything if detecting a circle' , function ( ) {
71
- var fullTrace = _supply ( {
72
- node : {
73
- label : [ 'a' , 'b' , 'c' , 'd' , 'e' ]
74
- } ,
75
- link : {
76
- value : [ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ,
77
- source : [ 0 , 1 , 2 , 3 ] ,
78
- target : [ 1 , 2 , 0 , 4 ]
79
- }
80
- } ) ;
81
-
82
- expect ( fullTrace . node . label ) . toEqual ( [ ] , 'node label(s) removed' ) ;
83
- expect ( fullTrace . link . value ) . toEqual ( [ ] , 'link value(s) removed' ) ;
84
- expect ( fullTrace . link . source ) . toEqual ( [ ] , 'link source(s) removed' ) ;
85
- expect ( fullTrace . link . target ) . toEqual ( [ ] , 'link target(s) removed' ) ;
86
10000
-
87
- } ) ;
88
-
89
- } ) ;
90
-
91
51
describe ( 'log warning if issue is encountered with graph structure' ,
92
52
function ( ) {
93
53
@@ -111,31 +71,20 @@ describe('sankey tests', function() {
111
71
112
72
expect ( warnings . length ) . toEqual ( 1 ) ;
113
73
} ) ;
74
+ } ) ;
114
75
115
- it ( 'circularity is detected' , function ( ) {
116
-
117
- var errors = [ ] ;
118
- spyOn ( Lib , 'error' ) . and . callFake ( function ( msg ) {
119
- errors . push ( msg ) ;
120
- } ) ;
121
-
122
- _supply ( {
123
- node : {
124
- label : [ 'a' , 'b' , 'c' ]
125
- } ,
126
- link : {
127
- value : [ 1 , 1 , 1 ] ,
128
- source : [ 0 , 1 , 2 ] ,
129
- target : [ 1 , 2 , 0 ]
130
- }
131
- } ) ;
76
+ describe ( 'sankey global defaults' , function ( ) {
132
77
133
- expect ( errors . length ) . toEqual ( 1 ) ;
134
- } ) ;
78
+ it ( 'should not coerce trace opacity' , function ( ) {
79
+ var gd = Lib . extendDeep ( { } , mock ) ;
135
80
81
+ Plots . supplyDefaults ( gd ) ;
136
82
83
+ expect ( gd . _fullData [ 0 ] . opacity ) . toBeUndefined ( ) ;
137
84
} ) ;
138
85
86
+ } ) ;
87
+
139
88
describe ( 'sankey defaults' , function ( ) {
140
89
141
90
it ( '\'Sankey\' specification should have proper arrays where mandatory' ,
@@ -223,4 +172,80 @@ describe('sankey tests', function() {
223
172
} ) ;
224
173
225
174
} ) ;
175
+
176
+ describe ( 'sankey calc' , function ( ) {
177
+
178
+ function _calc ( trace ) {
179
+ var gd = { data : [ trace ] } ;
180
+
181
+ Plots . supplyDefaults ( gd ) ;
182
+ var fullTrace = gd . _fullData [ 0 ] ;
183
+ Sankey . calc ( gd , fullTrace ) ;
184
+ return fullTrace ;
185
+ }
186
+
187
+ var base = { type : 'sankey' } ;
188
+
189
+ it ( 'circularity is detected' , function ( ) {
190
+
191
+ var errors = [ ] ;
192
+ spyOn ( Lib , 'error' ) . and . callFake ( function ( msg ) {
193
+ errors . push ( msg ) ;
194
+ } ) ;
195
+
196
+ _calc ( Lib . extendDeep ( { } , base , {
197
+ node : {
198
+ label : [ 'a' , 'b' , 'c' ]
199
+ } ,
200
+ link : {
201
+ value : [ 1 , 1 , 1 ] ,
202
+ source : [ 0 , 1 , 2 ] ,
203
+ target : [ 1 , 2 , 0 ]
204
+ }
205
+ } ) ) ;
206
+
207
+ expect ( errors . length ) . toEqual ( 1 ) ;
208
+ } ) ;
209
+
210
+ describe ( 'remove nodes if encountering circularity' , function ( ) {
211
+
212
+ it ( 'removing a single self-pointing node' , function ( ) {
213
+ var fullTrace = _calc ( Lib . extendDeep ( { } , base , {
214
+ node : {
215
+ label : [ 'a' ]
216
+ } ,
217
+ link : {
218
+ value : [ 1 ] ,
219
+ source : [ 0 ] ,
220
+ target : [ 0 ]
221
+ }
222
+ } ) ) ;
223
+
224
+ expect ( fullTrace . node . label ) . toEqual ( [ ] , 'node label(s) removed' ) ;
225
+ expect ( fullTrace . link . value ) . toEqual ( [ ] , 'link value(s) removed' ) ;
226
+ expect ( fullTrace . link . source ) . toEqual ( [ ] , 'link source(s) removed' ) ;
227
+ expect ( fullTrace . link . target ) . toEqual ( [ ] , 'link target(s) removed' ) ;
228
+
229
+ } ) ;
230
+
231
+ it ( 'removing everything if detecting a circle' , function ( ) {
232
+ var fullTrace = _calc ( Lib . extendDeep ( { } , base , {
233
+ node : {
234
+ label : [ 'a' , 'b' , 'c' , 'd' , 'e' ]
235
+ } ,
236
+ link : {
237
+ value : [ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ,
238
+ source : [ 0 , 1 , 2 , 3 ] ,
239
+ target : [ 1 , 2 , 0 , 4 ]
240
+ }
241
+ } ) ) ;
242
+
243
+ expect ( fullTrace . node . label ) . toEqual ( [ ] , 'node label(s) removed' ) ;
244
+ expect ( fullTrace . link . value ) . toEqual ( [ ] , 'link value(s) removed' ) ;
245
+ expect ( fullTrace . link . source ) . toEqual ( [ ] , 'link source(s) removed' ) ;
246
+ expect ( fullTrace . link . target ) . toEqual ( [ ] , 'link target(s) removed' ) ;
247
+
248
+ } ) ;
249
+ } ) ;
250
+ } ) ;
226
251
} ) ;
0 commit comments