@@ -10,13 +10,57 @@ var getSVGElemScreenBBox = require(
10
10
var testMock = require ( '../../image/mocks/domain_refs_editable.json' ) ;
11
11
var delay = require ( '../assets/delay' ) ;
12
12
var mouseEvent = require ( '../assets/mouse_event' ) ;
13
+ var drag = require ( '../assets/drag' ) ;
13
14
14
- // color of first rectangle
15
- var rectColor1 = "rgb(10, 20, 30)" ;
15
+ // color of the rectangles
16
+ var rectColor1 = 'rgb(10, 20, 30)' ;
17
+ var rectColor2 = 'rgb(10, 20, 31)' ;
18
+ var rectColor3 = 'rgb(100, 200, 232)' ;
19
+ var rectColor4 = 'rgb(200, 200, 232)' ;
16
20
17
21
var DELAY_TIME = 0 ;
18
22
19
- describe ( "Shapes referencing domain" , function ( ) {
23
+ function testObjectMove ( objectColor , moveX , moveY , type ) {
24
+ var bboxBefore = getSVGElemScreenBBox (
25
+ domainRefComponents . findAROByColor ( objectColor , undefined , type )
26
+ ) ;
27
+ var pos = {
28
+ mouseStartX : bboxBefore . x + bboxBefore . width * 0.5 ,
29
+ mouseStartY : bboxBefore . y + bboxBefore . height * 0.5 ,
30
+ } ;
31
+ pos . mouseEndX = pos . mouseStartX + moveX ;
32
+ pos . mouseEndY = pos . mouseStartY + moveY ;
33
+ mouseEvent ( 'mousemove' , pos . mouseStartX , pos . mouseStartY ) ;
34
+ mouseEvent ( 'mousedown' , pos . mouseStartX , pos . mouseStartY ) ;
35
+ mouseEvent ( 'mousemove' , pos . mouseEndX , pos . mouseEndY ) ;
36
+ mouseEvent ( 'mouseup' , pos . mouseEndX , pos . mouseEndY ) ;
37
+ var bboxAfter = getSVGElemScreenBBox (
38
+ domainRefComponents . findAROByColor ( objectColor , undefined , type )
39
+ ) ;
40
+ expect ( bboxAfter . x ) . toBeCloseTo ( bboxBefore . x + moveX , 2 ) ;
41
+ expect ( bboxAfter . y ) . toBeCloseTo ( bboxBefore . y + moveY , 2 ) ;
42
+ }
43
+
44
+ function testAnnotationMove ( objectColor , moveX , moveY , type ) {
45
+ var bboxBefore = getSVGElemScreenBBox (
46
+ domainRefComponents . findAROByColor ( objectColor , undefined , type )
47
+ ) ;
48
+ var opt = {
49
+ pos0 : [ bboxBefore . x + bboxBefore . width * 0.5 ,
50
+ bboxBefore . y + bboxBefore . height * 0.5 ] ,
51
+ } ;
52
+ opt . dpos = [ moveX , moveY ] ;
53
+ return ( new Promise ( function ( ) { drag ( opt ) ; } ) )
54
+ . then ( function ( ) {
55
+ var bboxAfter = getSVGElemScreenBBox (
56
+ domainRefComponents . findAROByColor ( objectColor , undefined , type )
57
+ ) ;
58
+ expect ( bboxAfter . x ) . toBeCloseTo ( bboxBefore . x + moveX , 2 ) ;
59
+ expect ( bboxAfter . y ) . toBeCloseTo ( bboxBefore . y + moveY , 2 ) ;
60
+ } ) ;
61
+ }
62
+
63
+ describe ( 'Shapes referencing domain' , function ( ) {
20
64
var gd ;
21
65
beforeEach ( function ( ) {
22
66
gd = createGraphDiv ( ) ;
@@ -26,31 +70,34 @@ describe("Shapes referencing domain", function () {
26
70
destroyGraphDiv ( gd ) ;
27
71
gd = null ;
28
72
} ) ;
29
- it ( "should move to the proper position" , function ( done ) {
30
- Plotly . newPlot ( gd , Lib . extendDeep ( { } , testMock ) )
31
- . then ( delay ( DELAY_TIME ) )
32
- . then ( function ( ) {
33
- var rectPos1before = getSVGElemScreenBBox (
34
- domainRefComponents . findAROByColor ( rectColor1 )
35
- ) ;
36
- var pos = {
37
- mouseStartX : rectPos1before . x + rectPos1before . width * 0.5 ,
38
- mouseStartY : rectPos1before . y + rectPos1before . height * 0.5 ,
39
- } ;
40
- pos . mouseEndX = pos . mouseStartX + 100 ;
41
- pos . mouseEndY = pos . mouseStartY + - 300 ;
42
- mouseEvent ( 'mousemove' , pos . mouseStartX , pos . mouseStartY ) ;
43
- mouseEvent ( 'mousedown' , pos . mouseStartX , pos . mouseStartY ) ;
44
- mouseEvent ( 'mousemove' , pos . mouseEndX , pos . mouseEndY ) ;
45
- mouseEvent ( 'mouseup' , pos . mouseEndX , pos . mouseEndY ) ;
46
- var rectPos1after = getSVGElemScreenBBox (
47
- domainRefComponents . findAROByColor ( rectColor1 )
48
- ) ;
49
- expect ( rectPos1after . x ) . toBeCloseTo ( rectPos1before . x + 100 , 2 ) ;
50
- expect ( rectPos1after . y ) . toBeCloseTo ( rectPos1before . y - 300 , 2 ) ;
51
- } )
52
- . then ( delay ( DELAY_TIME ) )
53
- . catch ( failTest )
54
- . then ( done ) ;
55
- } ) ;
73
+ function testObjectMoveItFun ( color , x , y , type ) {
74
+ return function ( done ) {
75
+ Plotly . newPlot ( gd , Lib . extendDeep ( { } , testMock ) )
76
+ . then ( delay ( DELAY_TIME ) )
77
+ . then ( function ( ) {
78
+ testObjectMove ( color , x , y , type ) ;
79
+ } )
80
+ . then ( delay ( DELAY_TIME ) )
81
+ . catch ( failTest )
82
+ . then ( done ) ;
83
+ } ;
84
+ }
85
+ function testAnnotationMoveItFun ( color , x , y , type ) {
86
+ return function ( done ) {
87
+ Plotly . newPlot ( gd , Lib . extendDeep ( { } , testMock ) )
88
+ . then ( delay ( DELAY_TIME ) )
89
+ . then ( testAnnotationMove ( color , x , y , type ) )
90
+ . then ( delay ( DELAY_TIME ) )
91
+ . catch ( failTest )
92
+ . then ( done ) ;
93
+ } ;
94
+ }
95
+ it ( 'should move box on linear x axis and log y to the proper position' ,
96
+ testObjectMoveItFun ( rectColor1 , 100 , - 300 , 'path' ) ) ;
97
+ it ( 'should move box on log x axis and linear y to the proper position' ,
98
+ testObjectMoveItFun ( rectColor2 , - 400 , - 200 , 'path' ) ) ;
99
+ it ( 'should move annotation box on linear x axis and log y to the proper position' ,
100
+ testAnnotationMoveItFun ( rectColor3 , 50 , - 100 , 'rect' ) ) ;
101
+ it ( 'should move annotation box on log x axis and linear y to the proper position' ,
102
+ testAnnotationMoveItFun ( rectColor4 , - 75 , - 150 , 'rect' ) ) ;
56
103
} ) ;
0 commit comments