@@ -1348,6 +1348,10 @@ describe('annotation effects', function() {
1348
1348
describe ( 'animating annotations' , function ( ) {
1349
1349
var gd ;
1350
1350
1351
+ // Two slightly different 1x1 pngs:
1352
+ var img1 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQYV2P4z/C/HgAGfgJ+p8YU1AAAAABJRU5ErkJggg==' ;
1353
+ var img2 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQYV2P4//9/PQAJewN9w0ic/wAAAABJRU5ErkJggg==' ;
1354
+
1351
1355
beforeEach ( function ( ) {
1352
1356
gd = createGraphDiv ( ) ;
1353
1357
} ) ;
@@ -1360,24 +1364,62 @@ describe('animating annotations', function() {
1360
1364
var texts = Plotly . d3 . select ( gd ) . selectAll ( '.annotation .annotation-text' ) ;
1361
1365
expect ( expected . length ) . toEqual ( texts . size ( ) ) ;
1362
1366
1363
- texts . each ( function ( i ) {
1367
+ texts . each ( function ( d , i ) {
1364
1368
expect ( Plotly . d3 . select ( this ) . text ( ) ) . toEqual ( expected [ i ] ) ;
1365
1369
} ) ;
1366
1370
}
1367
1371
1372
+ function assertShapes ( expected ) {
1373
+ var paths = Plotly . d3 . select ( gd ) . selectAll ( '.shapelayer path' ) ;
1374
+
1375
+ expect ( expected . length ) . toEqual ( paths . size ( ) ) ;
1376
+
1377
+ paths . each ( function ( d , i ) {
1378
+ expect ( Plotly . d3 . select ( this ) . style ( 'fill' ) ) . toEqual ( expected [ i ] ) ;
1379
+ } ) ;
1380
+ }
1381
+
1382
+ function assertImages ( expected ) {
1383
+ var imgs = Plotly . d3 . select ( gd ) . selectAll ( '.imagelayer image' ) ;
1384
+
1385
+ expect ( expected . length ) . toEqual ( imgs . size ( ) ) ;
1386
+
1387
+ imgs . each ( function ( d , i ) {
1388
+ expect ( Plotly . d3 . select ( this ) . attr ( 'href' ) ) . toEqual ( expected [ i ] ) ;
1389
+ } ) ;
1390
+ }
1391
+
1368
1392
Plotly . plot ( gd ,
1369
1393
[ { y : [ 1 , 2 , 3 ] } ] ,
1370
- { annotations : [ { text : 'hello' } ] }
1394
+ {
1395
+ annotations : [ { text : 'hello' } ] ,
1396
+ shapes : [ { fillcolor : 'rgb(170, 170, 170)' } ] ,
1397
+ images : [ { source : img1 } ]
1398
+ }
1371
1399
) . then ( function ( ) {
1372
1400
assertAnnotations ( [ 'hello' ] ) ;
1401
+ assertShapes ( [ 'rgb(170, 170, 170)' ] ) ;
1402
+ assertImages ( [ img1 ] ) ;
1373
1403
1374
1404
return Plotly . animate ( gd , [ {
1375
- layout : { annotations : [ { text : 'hi' } ] }
1405
+ layout : {
1406
+ annotations : [ { text : 'hi' } ] ,
1407
+ shapes : [
1408
+ { fillcolor : 'rgb(171, 171, 171)' } ,
1409
+ { fillcolor : 'rgb(172, 172, 172)' }
1410
+ ] ,
1411
+ images : [ { source : img2 } ]
1412
+ }
1376
1413
} ] , {
1377
1414
frame : { redraw : false , duration : 0 }
1378
1415
} ) ;
1379
1416
} ) . then ( function ( ) {
1380
1417
assertAnnotations ( [ 'hi' ] ) ;
1418
+ assertShapes ( [
1419
+ 'rgb(171, 171, 171)' ,
1420
+ 'rgb(172, 172, 172)'
1421
+ ] ) ;
1422
+ assertImages ( [ img2 ] ) ;
1381
1423
1382
1424
} ) . catch ( failTest ) . then ( done ) ;
1383
1425
} ) ;
0 commit comments