@@ -17,7 +17,6 @@ var drag = require('../assets/drag');
1717var mouseEvent = require ( '../assets/mouse_event' ) ;
1818var click = require ( '../assets/click' ) ;
1919
20-
2120describe ( 'Test annotations' , function ( ) {
2221 'use strict' ;
2322
@@ -1344,10 +1343,7 @@ describe('annotation effects', function() {
13441343 function _click ( pos , opts ) {
13451344 return new Promise ( function ( resolve ) {
13461345 click ( pos [ 0 ] , pos [ 1 ] , opts ) ;
1347-
1348- setTimeout ( function ( ) {
1349- resolve ( ) ;
1350- } , DBLCLICKDELAY * 1.1 ) ;
1346+ setTimeout ( resolve , DBLCLICKDELAY * 1.1 ) ;
13511347 } ) ;
13521348 }
13531349
@@ -1370,7 +1366,7 @@ describe('annotation effects', function() {
13701366 clickData = [ ] ;
13711367
13721368 gd . on ( 'plotly_clickannotation' , function ( evt ) {
1373- expect ( evt . event ) . toEqual ( jasmine . objectContaining ( { type : 'click' } ) ) ;
1369+ evt . eventType = evt . event . type ;
13741370 evt . button = evt . event . button ;
13751371 if ( evt . event . ctrlKey ) evt . ctrlKey = true ;
13761372 delete evt . event ;
@@ -1448,7 +1444,8 @@ describe('annotation effects', function() {
14481444 index : 1 ,
14491445 annotation : gd . layout . annotations [ 1 ] ,
14501446 fullAnnotation : gd . _fullLayout . annotations [ 1 ] ,
1451- button : 0
1447+ button : 0 ,
1448+ eventType : 'click'
14521449 } ] ) ;
14531450
14541451 expect ( gd . _fullLayout . annotations [ 0 ] . hoverlabel ) . toBeUndefined ( ) ;
@@ -1473,7 +1470,8 @@ describe('annotation effects', function() {
14731470 index : 0 ,
14741471 annotation : gd . layout . annotations [ 0 ] ,
14751472 fullAnnotation : gd . _fullLayout . annotations [ 0 ] ,
1476- button : 0
1473+ button : 0 ,
1474+ eventType : 'click'
14771475 } ] ) ;
14781476
14791477 return Plotly . relayout ( gd , {
@@ -1528,7 +1526,56 @@ describe('annotation effects', function() {
15281526 index : 1 ,
15291527 annotation : gd . layout . annotations [ 1 ] ,
15301528 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'
15321579 } ] ) ;
15331580 } )
15341581 . catch ( failTest )
0 commit comments