@@ -6,6 +6,7 @@ var d3 = require('d3');
66var createGraphDiv = require ( '../assets/create_graph_div' ) ;
77var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
88var fail = require ( '../assets/fail_test' ) ;
9+ var mouseEvent = require ( '../assets/mouse_event' ) ;
910
1011describe ( 'Test sort transform defaults:' , function ( ) {
1112 function _supply ( trace , layout ) {
@@ -241,4 +242,102 @@ describe('Test sort transform interactions:', function() {
241242 . catch ( fail )
242243 . then ( done ) ;
243244 } ) ;
245+
246+ it ( 'does not preserve hover/click `pointNumber` value' , function ( done ) {
247+ var gd = createGraphDiv ( ) ;
248+
249+ function getPxPos ( gd , id ) {
250+ var trace = gd . data [ 0 ] ;
251+ var fullLayout = gd . _fullLayout ;
252+ var index = trace . ids . indexOf ( id ) ;
253+
254+ return [
255+ fullLayout . xaxis . d2p ( trace . x [ index ] ) ,
256+ fullLayout . yaxis . d2p ( trace . y [ index ] )
257+ ] ;
258+ }
259+
260+ function hover ( gd , id ) {
261+ return new Promise ( function ( resolve ) {
262+ gd . once ( 'plotly_hover' , function ( eventData ) {
263+ resolve ( eventData ) ;
264+ } ) ;
265+
266+ var pos = getPxPos ( gd , id ) ;
267+ mouseEvent ( 'mousemove' , pos [ 0 ] , pos [ 1 ] ) ;
268+ } ) ;
269+ }
270+
271+ function click ( gd , id ) {
272+ return new Promise ( function ( resolve ) {
273+ gd . once ( 'plotly_click' , function ( eventData ) {
274+ resolve ( eventData ) ;
275+ } ) ;
276+
277+ var pos = getPxPos ( gd , id ) ;
278+ mouseEvent ( 'mousemove' , pos [ 0 ] , pos [ 1 ] ) ;
279+ mouseEvent ( 'mousedown' , pos [ 0 ] , pos [ 1 ] ) ;
280+ mouseEvent ( 'mouseup' , pos [ 0 ] , pos [ 1 ] ) ;
281+ } ) ;
282+ }
283+
284+ function wait ( ) {
285+ return new Promise ( function ( resolve ) {
286+ setTimeout ( resolve , 60 ) ;
287+ } ) ;
288+ }
289+
290+ function assertPt ( eventData , x , y , pointNumber , id ) {
291+ var pt = eventData . points [ 0 ] ;
292+
293+ expect ( pt . x ) . toEqual ( x , 'x' ) ;
294+ expect ( pt . y ) . toEqual ( y , 'y' ) ;
295+ expect ( pt . pointNumber ) . toEqual ( pointNumber , 'pointNumber' ) ;
296+ expect ( pt . fullData . ids [ pt . pointNumber ] ) . toEqual ( id , 'id' ) ;
297+ }
298+
299+ Plotly . plot ( gd , [ {
300+ mode : 'markers' ,
301+ x : [ - 2 , - 1 , - 2 , 0 , 1 , 3 , 1 ] ,
302+ y : [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ,
303+ ids : [ 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' ] ,
304+ marker : {
305+ size : [ 10 , 20 , 5 , 1 , 6 , 0 , 10 ]
306+ } ,
307+ transforms : [ {
308+ enabled : false ,
309+ type : 'sort' ,
310+ target : 'marker.size' ,
311+ } ]
312+ } ] , {
313+ width : 500 ,
314+ height : 500 ,
315+ margin : { l : 0 , t : 0 , r : 0 , b : 0 } ,
316+ hovermode : 'closest'
317+ } )
318+ . then ( function ( ) { return hover ( gd , 'D' ) ; } )
319+ . then ( function ( eventData ) {
320+ assertPt ( eventData , 0 , 1 , 3 , 'D' ) ;
321+ } )
322+ . then ( wait )
323+ . then ( function ( ) { return click ( gd , 'G' ) ; } )
324+ . then ( function ( eventData ) {
325+ assertPt ( eventData , 1 , 1 , 6 , 'G' ) ;
326+ } )
327+ . then ( wait )
328+ . then ( function ( ) {
329+ return Plotly . restyle ( gd , 'transforms[0].enabled' , true ) ;
330+ } )
331+ . then ( function ( ) { return hover ( gd , 'D' ) ; } )
332+ . then ( function ( eventData ) {
333+ assertPt ( eventData , 0 , 1 , 1 , 'D' ) ;
334+ } )
335+ . then ( wait )
336+ . then ( function ( ) { return click ( gd , 'G' ) ; } )
337+ . then ( function ( eventData ) {
338+ assertPt ( eventData , 1 , 1 , 5 , 'G' ) ;
339+ } )
340+ . catch ( fail )
341+ . then ( done ) ;
342+ } ) ;
244343} ) ;
0 commit comments