@@ -1279,6 +1279,147 @@ describe('Test select box and lasso per trace:', function() {
12791279 } ) ;
12801280} ) ;
12811281
1282+ describe ( 'Test that selections persist:' , function ( ) {
1283+ var gd ;
1284+
1285+ beforeEach ( function ( ) {
1286+ gd = createGraphDiv ( ) ;
1287+ } ) ;
1288+
1289+ afterEach ( destroyGraphDiv ) ;
1290+
1291+ function assertPtOpacity ( selector , expected ) {
1292+ d3 . selectAll ( selector ) . each ( function ( _ , i ) {
1293+ var style = Number ( this . style . opacity ) ;
1294+ expect ( style ) . toBe ( expected . style [ i ] , 'style for pt ' + i ) ;
1295+ } ) ;
1296+ }
1297+
1298+ it ( 'should persist for scatter' , function ( done ) {
1299+ function _assert ( expected ) {
1300+ var selected = gd . calcdata [ 0 ] . map ( function ( d ) { return d . selected ; } ) ;
1301+ expect ( selected ) . toBeCloseToArray ( expected . selected , 'selected vals' ) ;
1302+ assertPtOpacity ( '.point' , expected ) ;
1303+ }
1304+
1305+ Plotly . plot ( gd , [ {
1306+ x : [ 1 , 2 , 3 ] ,
1307+ y : [ 1 , 2 , 1 ]
1308+ } ] , {
1309+ dragmode : 'select' ,
1310+ width : 400 ,
1311+ height : 400 ,
1312+ margin : { l : 0 , t : 0 , r : 0 , b : 0 }
1313+ } )
1314+ . then ( function ( ) {
1315+ resetEvents ( gd ) ;
1316+ drag ( [ [ 5 , 5 ] , [ 250 , 350 ] ] ) ;
1317+ return selectedPromise ;
1318+ } )
1319+ . then ( function ( ) {
1320+ _assert ( {
1321+ selected : [ 0 , 1 , 0 ] ,
1322+ style : [ 0.2 , 1 , 0.2 ]
1323+ } ) ;
1324+
1325+ // trigger a recalc
1326+ Plotly . restyle ( gd , 'x' , [ [ 10 , 20 , 30 ] ] ) ;
1327+ } )
1328+ . then ( function ( ) {
1329+ _assert ( {
1330+ selected : [ undefined , 1 , undefined ] ,
1331+ style : [ 0.2 , 1 , 0.2 ]
1332+ } ) ;
1333+ } )
1334+ . catch ( fail )
1335+ . then ( done ) ;
1336+ } ) ;
1337+
1338+ it ( 'should persist for box' , function ( done ) {
1339+ function _assert ( expected ) {
1340+ var selected = gd . calcdata [ 0 ] [ 0 ] . pts . map ( function ( d ) { return d . selected ; } ) ;
1341+ expect ( selected ) . toBeCloseToArray ( expected . selected , 'selected vals' ) ;
1342+ assertPtOpacity ( '.point' , expected ) ;
1343+ }
1344+
1345+ Plotly . plot ( gd , [ {
1346+ type : 'box' ,
1347+ x0 : 0 ,
1348+ y : [ 1 , 2 , 2 , 2 , 2 , 2 , 3 , 3 , 3 , 4 , 4 , 5 ] ,
1349+ boxpoints : 'all'
1350+ } ] , {
1351+ dragmode : 'select' ,
1352+ width : 400 ,
1353+ height : 400 ,
1354+ margin : { l : 0 , t : 0 , r : 0 , b : 0 }
1355+ } )
1356+ . then ( function ( ) {
1357+ resetEvents ( gd ) ;
1358+ drag ( [ [ 5 , 5 ] , [ 400 , 150 ] ] ) ;
1359+ return selectedPromise ;
1360+ } )
1361+ . then ( function ( ) {
1362+ _assert ( {
1363+ selected : [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 ] ,
1364+ style : [ 0.2 , 0.2 , 0.2 , 0.2 , 0.2 , 0.2 , 0.2 , 0.2 , 0.2 , 1 , 1 , 1 ] ,
1365+ } ) ;
1366+
1367+ // trigger a recalc
1368+ Plotly . restyle ( gd , 'x0' , 1 ) ;
1369+ } )
1370+ . then ( function ( ) {
1371+ _assert ( {
1372+ selected : [ undefined , undefined , undefined , undefined , undefined , undefined , undefined , undefined , undefined , 1 , 1 , 1 ] ,
1373+ style : [ 0.2 , 0.2 , 0.2 , 0.2 , 0.2 , 0.2 , 0.2 , 0.2 , 0.2 , 1 , 1 , 1 ] ,
1374+ } ) ;
1375+ } )
1376+ . catch ( fail )
1377+ . then ( done ) ;
1378+ } ) ;
1379+
1380+ it ( 'should persist for histogram' , function ( done ) {
1381+ function _assert ( expected ) {
1382+ var selected = gd . calcdata [ 0 ] . map ( function ( d ) { return d . selected ; } ) ;
1383+ expect ( selected ) . toBeCloseToArray ( expected . selected , 'selected vals' ) ;
1384+ assertPtOpacity ( '.point > path' , expected ) ;
1385+ }
1386+
1387+ Plotly . plot ( gd , [ {
1388+ type : 'histogram' ,
1389+ x : [ 1 , 2 , 2 , 2 , 2 , 2 , 3 , 3 , 3 , 4 , 4 , 5 ] ,
1390+ boxpoints : 'all'
1391+ } ] , {
1392+ dragmode : 'select' ,
1393+ width : 400 ,
1394+ height : 400 ,
1395+ margin : { l : 0 , t : 0 , r : 0 , b : 0 }
1396+ } )
1397+ . then ( function ( ) {
1398+ resetEvents ( gd ) ;
1399+ drag ( [ [ 5 , 5 ] , [ 400 , 150 ] ] ) ;
1400+ return selectedPromise ;
1401+ } )
1402+ . then ( function ( ) {
1403+ _assert ( {
1404+ selected : [ 0 , 1 , 0 , 0 , 0 ] ,
1405+ style : [ 0.2 , 1 , 0.2 , 0.2 , 0.2 ] ,
1406+ } ) ;
1407+
1408+ // trigger a recalc
1409+ Plotly . restyle ( gd , 'histfunc' , 'sum' ) ;
1410+ } )
1411+ . then ( done )
1412+ . then ( function ( ) {
1413+ _assert ( {
1414+ selected : [ undefined , 1 , undefined , undefined , undefined ] ,
1415+ style : [ 0.2 , 1 , 0.2 , 0.2 , 0.2 ] ,
1416+ } ) ;
1417+ } )
1418+ . catch ( fail )
1419+ . then ( done ) ;
1420+ } ) ;
1421+ } ) ;
1422+
12821423// to make sure none of the above tests fail with extraneous invisible traces,
12831424// add a bunch of them here
12841425function addInvisible ( fig , canHaveLegend ) {
0 commit comments