@@ -22,6 +22,7 @@ var defaultColors = require('@src/components/color/attributes').defaults;
22
22
23
23
var drag = require ( '../assets/drag' ) ;
24
24
var checkOverlap = require ( '../assets/check_overlap' ) ;
25
+ var delay = require ( '../assets/delay' ) ;
25
26
26
27
describe ( 'sankey tests' , function ( ) {
27
28
@@ -1150,6 +1151,80 @@ describe('sankey tests', function() {
1150
1151
} ) ;
1151
1152
} ) ;
1152
1153
} ) ;
1154
+
1155
+ describe ( 'in relation to uirevision' , function ( ) {
1156
+ var gd ;
1157
+
1158
+ beforeEach ( function ( ) {
1159
+ gd = createGraphDiv ( ) ;
1160
+ } ) ;
1161
+
1162
+ afterEach ( function ( ) {
1163
+ Plotly . purge ( gd ) ;
1164
+ destroyGraphDiv ( ) ;
1165
+ } ) ;
1166
+
1167
+ [ '0' , '1' ] . forEach ( function ( finalUIRevision ) {
1168
+ it ( 'on Plotly.react, it preserves the position of nodes depending on layout.uirevision' , function ( done ) {
1169
+ var nodes , node , positionBeforeDrag , positionAfterDrag ;
1170
+ var move = [ - 50 , 100 ] ;
1171
+ var uirevisions = [ '0' , finalUIRevision ] ;
1172
+
1173
+ // Use a freeform arrangement
1174
+ var mockCircularFreeform = Lib . extendDeep ( { } , mockCircular ) ;
1175
+ mockCircularFreeform . data [ 0 ] . arrangement = 'freeform' ;
1176
+
1177
+ var mockCopy = Lib . extendDeep ( { } , mockCircularFreeform ) ;
1178
+ mockCopy . layout . uirevision = uirevisions [ 0 ] ;
1179
+
1180
+ Plotly . plot ( gd , mockCopy )
1181
+ . then ( function ( ) {
1182
+ // move a node around
1183
+ nodes = document . getElementsByClassName ( 'sankey-node' ) ;
1184
+ node = Array . prototype . slice . call ( nodes ) . find ( function ( n ) { return n . textContent === '0' ; } ) ;
1185
+ positionBeforeDrag = getNodeCoords ( node ) ;
1186
+ positionBeforeDrag = [ positionBeforeDrag . x , positionBeforeDrag . y ] ;
1187
+ positionAfterDrag = [ positionBeforeDrag [ 0 ] + move [ 0 ] , positionBeforeDrag [ 1 ] + move [ 1 ] ] ;
1188
+ return drag ( node , move [ 0 ] , move [ 1 ] , false , false , false , 10 , false , 1000 ) ;
1189
+ } )
1190
+ . then ( function ( ) {
1191
+ // Check that the node was really moved
1192
+ nodes = document . getElementsByClassName ( 'sankey-node' ) ;
1193
+ node = Array . prototype . slice . call ( nodes ) . find ( function ( n ) { return n . textContent === '0' ; } ) ;
1194
+ var newPosition = getNodeCoords ( node ) ;
1195
+ expect ( newPosition . x ) . toBeCloseTo ( positionAfterDrag [ 0 ] , 2 , 'final x position is off' ) ;
1196
+ expect ( newPosition . y ) . toBeCloseTo ( positionAfterDrag [ 1 ] , 2 , 'final y position is off' ) ;
1197
+
1198
+ // Change color of nodes
1199
+ var mockCopy = Lib . extendDeep ( { } , mockCircularFreeform ) ;
1200
+ mockCopy . data [ 0 ] . node . color = 'orange' ;
1201
+ mockCopy . layout . uirevision = uirevisions [ 1 ] ;
1202
+ return Plotly . react ( gd , mockCopy ) ;
1203
+ } )
1204
+ . then ( delay ( 1000 ) )
1205
+ . then ( function ( ) {
1206
+ nodes = document . getElementsByClassName ( 'sankey-node' ) ;
1207
+ node = Array . prototype . slice . call ( nodes ) . find ( function ( n ) { return n . textContent === '0' ; } ) ;
1208
+ var newPosition = getNodeCoords ( node ) ;
1209
+
1210
+ var pos , msg ;
1211
+ if ( uirevisions [ 0 ] === uirevisions [ 1 ] ) {
1212
+ // If uirevision is the same, the node should stay where it is
1213
+ pos = positionAfterDrag ;
1214
+ msg = 'should stay the same because uirevision did not change' ;
1215
+ } else {
1216
+ // If uirevision changed, the node should go back to its default position
1217
+ pos = positionBeforeDrag ;
1218
+ msg = 'should go back to its default because uirevision changed' ;
1219
+ }
1220
+ expect ( newPosition . x ) . toBeCloseTo ( pos [ 0 ] , 2 , 'x position ' + msg ) ;
1221
+ expect ( newPosition . y ) . toBeCloseTo ( pos [ 1 ] , 2 , 'y position ' + msg ) ;
1222
+ } )
1223
+ . catch ( failTest )
1224
+ . then ( done ) ;
1225
+ } ) ;
1226
+ } ) ;
1227
+ } ) ;
1153
1228
} ) ;
1154
1229
1155
1230
it ( 'emits a warning if node.pad is too large' , function ( done ) {
0 commit comments