@@ -113,6 +113,42 @@ describe('Drawing', function() {
113
113
el . attr ( 'transform' , 'rotate(20)' ) ;
114
114
expect ( Drawing . getTranslate ( el ) ) . toEqual ( { x : 0 , y : 0 } ) ;
115
115
} ) ;
116
+
117
+ it ( 'should work with negative values' , function ( ) {
118
+ var el = document . createElement ( 'div' ) ,
119
+ el3 = d3 . select ( document . createElement ( 'div' ) ) ;
120
+
121
+ expect ( Drawing . getTranslate ( el ) ) . toEqual ( { x : 0 , y : 0 } ) ;
122
+
123
+ var testCases = [
124
+ { transform : 'translate(-123.45px, -67)' , x : - 123.45 , y : - 67 } ,
125
+ { transform : 'translate(-123.45px, 67)' , x : - 123.45 , y : 67 } ,
126
+ { transform : 'translate(123.45px, -67)' , x : 123.45 , y : - 67 } ,
127
+ { transform : 'translate(-123.45)' , x : - 123.45 , y : 0 } ,
128
+ { transform : 'translate(-1 -2)' , x : - 1 , y : - 2 } ,
129
+ { transform : 'translate(-1 2)' , x : - 1 , y : 2 } ,
130
+ { transform : 'translate(1 -2)' , x : 1 , y : - 2 } ,
131
+ { transform : 'translate(-1 -2); rotate(20deg)' , x : - 1 , y : - 2 } ,
132
+ { transform : 'translate(-1 2); rotate(20deg)' , x : - 1 , y : 2 } ,
133
+ { transform : 'translate(1 -2); rotate(20deg)' , x : 1 , y : - 2 } ,
134
+ { transform : 'rotate(20deg) translate(-1 -2);' , x : - 1 , y : - 2 } ,
135
+ { transform : 'rotate(20deg) translate(-1 2);' , x : - 1 , y : 2 } ,
136
+ { transform : 'rotate(20deg) translate(1 -2);' , x : 1 , y : - 2 }
137
+ ] ;
138
+
139
+ for ( var i = 0 ; i < testCases . length ; i ++ ) {
140
+ var testCase = testCases [ i ] ,
141
+ transform = testCase . transform ,
142
+ x = testCase . x ,
143
+ y = testCase . y ;
144
+
145
+ el . setAttribute ( 'transform' , transform ) ;
146
+ expect ( Drawing . getTranslate ( el ) ) . toEqual ( { x : x , y : y } ) ;
147
+
148
+ el3 . attr ( 'transform' , transform ) ;
149
+ expect ( Drawing . getTranslate ( el ) ) . toEqual ( { x : x , y : y } ) ;
150
+ }
151
+ } ) ;
116
152
} ) ;
117
153
118
154
describe ( 'setTranslate' , function ( ) {
0 commit comments