@@ -3,6 +3,7 @@ var d3 = require('d3');
3
3
var Plotly = require ( '@lib/index' ) ;
4
4
var Plots = require ( '@src/plots/plots' ) ;
5
5
var Lib = require ( '@src/lib' ) ;
6
+ var Drawing = require ( '@src/components/drawing' ) ;
6
7
7
8
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
8
9
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
@@ -587,6 +588,7 @@ describe('Test gl plot interactions', function() {
587
588
} ) ;
588
589
} ) ;
589
590
} ) ;
591
+
590
592
describe ( 'Plotly.newPlot' , function ( ) {
591
593
592
594
var mockData2dNew = [ {
@@ -761,20 +763,18 @@ describe('gl2d interaction', function() {
761
763
it ( 'data-referenced annotations should update on drag' , function ( done ) {
762
764
763
765
function drag ( start , end ) {
764
- var opts = { buttons : 1 } ;
765
-
766
- mouseEvent ( 'mousemove' , start [ 0 ] , start [ 1 ] , opts ) ;
767
- mouseEvent ( 'mousedown' , start [ 0 ] , start [ 1 ] , opts ) ;
768
- mouseEvent ( 'mousemove' , end [ 0 ] , end [ 1 ] , opts ) ;
769
- mouseEvent ( 'mouseup' , end [ 0 ] , end [ 1 ] , opts ) ;
766
+ mouseEvent ( 'mousemove' , start [ 0 ] , start [ 1 ] ) ;
767
+ mouseEvent ( 'mousedown' , start [ 0 ] , start [ 1 ] , { buttons : 1 } ) ;
768
+ mouseEvent ( 'mousemove' , end [ 0 ] , end [ 1 ] , { buttons : 1 } ) ;
769
+ mouseEvent ( 'mouseup' , end [ 0 ] , end [ 1 ] ) ;
770
770
}
771
771
772
772
function assertAnnotation ( xy ) {
773
- var ann = d3 . select ( 'g.annotation-text-g' ) ;
774
- var x = + ann . attr ( 'x' ) ;
775
- var y = + ann . attr ( 'y' ) ;
773
+ var ann = d3 . select ( 'g.annotation-text-g' ) . select ( 'g' ) ;
774
+ var translate = Drawing . getTranslate ( ann ) ;
776
775
777
- expect ( [ x , y ] ) . toBeCloseToArray ( xy ) ;
776
+ expect ( translate . x ) . toBeWithin ( xy [ 0 ] , 1.5 ) ;
777
+ expect ( translate . y ) . toBeWithin ( xy [ 1 ] , 1.5 ) ;
778
778
}
779
779
780
780
Plotly . plot ( gd , [ {
@@ -790,18 +790,18 @@ describe('gl2d interaction', function() {
790
790
dragmode : 'pan'
791
791
} )
792
792
. then ( function ( ) {
793
- assertAnnotation ( [ 340 , 334 ] ) ;
793
+ assertAnnotation ( [ 327 , 325 ] ) ;
794
794
795
- drag ( [ 250 , 200 ] , [ 150 , 300 ] ) ;
796
- assertAnnotation ( [ 410 , 264 ] ) ;
795
+ drag ( [ 250 , 200 ] , [ 200 , 150 ] ) ;
796
+ assertAnnotation ( [ 277 , 275 ] ) ;
797
797
798
798
return Plotly . relayout ( gd , {
799
799
'xaxis.range' : [ 1.5 , 2.5 ] ,
800
800
'yaxis.range' : [ 1 , 1.5 ]
801
801
} ) ;
802
802
} )
803
803
. then ( function ( ) {
804
- assertAnnotation ( [ 340 , 340 ] ) ;
804
+ assertAnnotation ( [ 327 , 331 ] ) ;
805
805
} )
806
806
. then ( done ) ;
807
807
} ) ;
0 commit comments