@@ -7,6 +7,7 @@ var DBLCLICKDELAY = require('../../../src/plot_api/plot_config').dfltConfig.doub
77var d3Select = require ( '../../strict-d3' ) . select ;
88var d3SelectAll = require ( '../../strict-d3' ) . selectAll ;
99var createGraphDiv = require ( '../assets/create_graph_div' ) ;
10+ var createShadowGraphDiv = require ( '../assets/create_shadow_graph_div' ) ;
1011var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
1112
1213var mouseEvent = require ( '../assets/mouse_event' ) ;
@@ -1059,17 +1060,17 @@ describe('Test click interactions:', function() {
10591060 width : 600 ,
10601061 height : 600
10611062 } ) . then ( function ( ) {
1062- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 1 , 2.068 ] ) ;
1063+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 1 , 2.068 ] , 1 ) ;
10631064
10641065 return doubleClick ( 300 , 300 ) ;
10651066 } )
10661067 . then ( function ( ) {
1067- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ - 0.2019 , 3.249 ] ) ;
1068+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ - 0.2019 , 3.249 ] , 1 ) ;
10681069
10691070 return doubleClick ( 300 , 300 ) ;
10701071 } )
10711072 . then ( function ( ) {
1072- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 1 , 2.068 ] ) ;
1073+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 1 , 2.068 ] , 1 ) ;
10731074 } )
10741075 . then ( done , done . fail ) ;
10751076 } ) ;
@@ -1164,6 +1165,56 @@ describe('Test click interactions:', function() {
11641165 } ) ;
11651166} ) ;
11661167
1168+ describe ( 'Click events in Shadow DOM' , function ( ) {
1169+ afterEach ( destroyGraphDiv ) ;
1170+
1171+ function fig ( ) {
1172+ var x = [ ] ;
1173+ var y = [ ] ;
1174+ for ( var i = 0 ; i <= 20 ; i ++ ) {
1175+ for ( var j = 0 ; j <= 20 ; j ++ ) {
1176+ x . push ( i ) ;
1177+ y . push ( j ) ;
1178+ }
1179+ }
1180+ return {
1181+ data : [ { x : x , y : y , mode : 'markers' } ] ,
1182+ layout : {
1183+ width : 400 ,
1184+ height : 400 ,
1185+ margin : { l : 100 , r : 100 , t : 100 , b : 100 } ,
1186+ xaxis : { range : [ 0 , 20 ] } ,
1187+ yaxis : { range : [ 0 , 20 ] } ,
1188+ }
1189+ } ;
1190+ }
1191+
1192+ it ( 'should select the same point in regular and shadow DOM' , function ( done ) {
1193+ var clickData ;
1194+ var clickX = 120 ;
1195+ var clickY = 150 ;
1196+ var expectedX = 2 ; // counts up 1 every 10px from 0 at 100px
1197+ var expectedY = 15 ; // counts down 1 every 10px from 20 at 100px
1198+
1199+ function check ( gd ) {
1200+ gd . on ( 'plotly_click' , function ( event ) { clickData = event ; } ) ;
1201+ click ( clickX , clickY ) ;
1202+ expect ( clickData . points . length ) . toBe ( 1 ) ;
1203+ var pt = clickData . points [ 0 ] ;
1204+ expect ( pt . x ) . toBe ( expectedX ) ;
1205+ expect ( pt . y ) . toBe ( expectedY ) ;
1206+ clickData = null ;
1207+ }
1208+
1209+ Plotly . newPlot ( createGraphDiv ( ) , fig ( ) )
1210+ . then ( check )
1211+ . then ( destroyGraphDiv )
1212+ . then ( function ( ) { return Plotly . newPlot ( createShadowGraphDiv ( ) , fig ( ) ) } )
1213+ . then ( check )
1214+ . then ( done , done . fail ) ;
1215+ } ) ;
1216+ } ) ;
1217+
11671218
11681219describe ( 'dragbox' , function ( ) {
11691220 afterEach ( destroyGraphDiv ) ;
0 commit comments