@@ -17,7 +17,6 @@ var drag = require('../assets/drag');
17
17
var mouseEvent = require ( '../assets/mouse_event' ) ;
18
18
var click = require ( '../assets/click' ) ;
19
19
20
-
21
20
describe ( 'Test annotations' , function ( ) {
22
21
'use strict' ;
23
22
@@ -1344,10 +1343,7 @@ describe('annotation effects', function() {
1344
1343
function _click ( pos , opts ) {
1345
1344
return new Promise ( function ( resolve ) {
1346
1345
click ( pos [ 0 ] , pos [ 1 ] , opts ) ;
1347
-
1348
- setTimeout ( function ( ) {
1349
- resolve ( ) ;
1350
- } , DBLCLICKDELAY * 1.1 ) ;
1346
+ setTimeout ( resolve , DBLCLICKDELAY * 1.1 ) ;
1351
1347
} ) ;
1352
1348
}
1353
1349
@@ -1370,7 +1366,7 @@ describe('annotation effects', function() {
1370
1366
clickData = [ ] ;
1371
1367
1372
1368
gd . on ( 'plotly_clickannotation' , function ( evt ) {
1373
- expect ( evt . event ) . toEqual ( jasmine . objectContaining ( { type : 'click' } ) ) ;
1369
+ evt . eventType = evt . event . type ;
1374
1370
evt . button = evt . event . button ;
1375
1371
if ( evt . event . ctrlKey ) evt . ctrlKey = true ;
1376
1372
delete evt . event ;
@@ -1448,7 +1444,8 @@ describe('annotation effects', function() {
1448
1444
index : 1 ,
1449
1445
annotation : gd . layout . annotations [ 1 ] ,
1450
1446
fullAnnotation : gd . _fullLayout . annotations [ 1 ] ,
1451
- button : 0
1447
+ button : 0 ,
1448
+ eventType : 'click'
1452
1449
} ] ) ;
1453
1450
1454
1451
expect ( gd . _fullLayout . annotations [ 0 ] . hoverlabel ) . toBeUndefined ( ) ;
@@ -1473,7 +1470,8 @@ describe('annotation effects', function() {
1473
1470
index : 0 ,
1474
1471
annotation : gd . layout . annotations [ 0 ] ,
1475
1472
fullAnnotation : gd . _fullLayout . annotations [ 0 ] ,
1476
- button : 0
1473
+ button : 0 ,
1474
+ eventType : 'click'
1477
1475
} ] ) ;
1478
1476
1479
1477
return Plotly . relayout ( gd , {
@@ -1528,7 +1526,56 @@ describe('annotation effects', function() {
1528
1526
index : 1 ,
1529
1527
annotation : gd . layout . annotations [ 1 ] ,
1530
1528
fullAnnotation : gd . _fullLayout . annotations [ 1 ] ,
1531
- button : 0
1529
+ button : 0 ,
1530
+ eventType : 'click'
1531
+ } ] ) ;
1532
+ } )
1533
+ . catch ( failTest )
1534
+ . then ( done ) ;
1535
+ } ) ;
1536
+
1537
+ it ( 'should register clicks even in editable:true mode' , function ( done ) {
1538
+ function clickForTextEdit ( pos ) {
1539
+ return new Promise ( function ( resolve , reject ) {
1540
+ gd . once ( 'plotly_relayout' , resolve ) ;
1541
+
1542
+ setTimeout ( function ( ) {
1543
+ reject ( 'Did not trigger plotly_relayout' ) ;
1544
+ } , DBLCLICKDELAY * 2 ) ;
1545
+
1546
+ click ( pos [ 0 ] , pos [ 1 ] ) ;
1547
+
1548
+ setTimeout ( function ( ) {
1549
+ var input = d3 . select ( '.plugin-editable.editable' ) ;
1550
+ input . node ( ) . dispatchEvent ( new KeyboardEvent ( 'blur' ) ) ;
1551
+ } , DBLCLICKDELAY * 1.1 ) ;
1552
+ } ) ;
1553
+ }
1554
+
1555
+ makePlot ( [
1556
+ { x : 50 , y : 50 , text : 'hi' , width : 50 , height : 40 , ax : 0 , ay : - 40 , xshift : - 50 , yshift : 50 } ,
1557
+ { x : 20 , y : 20 , text : 'bye' , height : 40 , showarrow : false } ,
1558
+ { x : 80 , y : 80 , text : 'why?' , ax : 0 , ay : - 40 }
1559
+ ] , { editable : true } )
1560
+ . then ( initClickTests )
1561
+ . then ( function ( ) { return clickForTextEdit ( pos0 ) ; } )
1562
+ . then ( function ( ) {
1563
+ assertClickData ( [ ] ) ;
1564
+ } )
1565
+ . then ( function ( ) {
1566
+ return Plotly . relayout ( gd , {
1567
+ 'annotations[1].captureevents' : true ,
1568
+ 'annotations[2].captureevents' : true
1569
+ } ) ;
1570
+ } )
1571
+ . then ( function ( ) { return clickForTextEdit ( pos1 ) ; } )
1572
+ . then ( function ( ) {
1573
+ assertClickData ( [ {
1574
+ index : 1 ,
1575
+ annotation : gd . layout . annotations [ 1 ] ,
1576
+ fullAnnotation : gd . _fullLayout . annotations [ 1 ] ,
1577
+ button : 0 ,
1578
+ eventType : 'mousedown'
1532
1579
} ] ) ;
1533
1580
} )
1534
1581
. catch ( failTest )
0 commit comments