@@ -823,6 +823,9 @@ describe('Test lib.js:', function() {
823
823
el . setAttribute ( 'transform' , 'translate(1 2); rotate(20deg)' ) ;
824
824
expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 1 , y : 2 } ) ;
825
825
826
+ el . setAttribute ( 'transform' , 'rotate(20deg) translate(1 2);' ) ;
827
+ expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 1 , y : 2 } ) ;
828
+
826
829
el . setAttribute ( 'transform' , 'rotate(20deg)' ) ;
827
830
expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 0 , y : 0 } ) ;
828
831
} ) ;
@@ -858,9 +861,6 @@ describe('Test lib.js:', function() {
858
861
Lib . setTranslate ( el , 10 , 20 ) ;
859
862
expect ( el . getAttribute ( 'transform' ) ) . toBe ( 'translate(10, 20)' ) ;
860
863
861
- Lib . setTranslate ( el , 30 , 40 ) ;
862
- expect ( el . getAttribute ( 'transform' ) ) . toBe ( 'translate(30, 40)' ) ;
863
-
864
864
Lib . setTranslate ( el ) ;
865
865
expect ( el . getAttribute ( 'transform' ) ) . toBe ( 'translate(0, 0)' ) ;
866
866
@@ -875,9 +875,6 @@ describe('Test lib.js:', function() {
875
875
Lib . setTranslate ( el , 5 ) ;
876
876
expect ( el . attr ( 'transform' ) ) . toBe ( 'translate(5, 0)' ) ;
877
877
878
- Lib . setTranslate ( el , 10 , 20 ) ;
879
- expect ( el . attr ( 'transform' ) ) . toBe ( 'translate(10, 20)' ) ;
880
-
881
878
Lib . setTranslate ( el , 30 , 40 ) ;
882
879
expect ( el . attr ( 'transform' ) ) . toBe ( 'translate(30, 40)' ) ;
883
880
@@ -890,6 +887,89 @@ describe('Test lib.js:', function() {
890
887
} ) ;
891
888
} ) ;
892
889
890
+ describe ( 'getScale' , function ( ) {
891
+
892
+ it ( 'should work with regular DOM elements' , function ( ) {
893
+ var el = document . createElement ( 'div' ) ;
894
+
895
+ expect ( Lib . getScale ( el ) ) . toEqual ( { x : 1 , y : 1 } ) ;
896
+
897
+ el . setAttribute ( 'transform' , 'scale(1.23, 45)' ) ;
898
+ expect ( Lib . getScale ( el ) ) . toEqual ( { x : 1.23 , y : 45 } ) ;
899
+
900
+ el . setAttribute ( 'transform' , 'scale(123.45)' ) ;
901
+ expect ( Lib . getScale ( el ) ) . toEqual ( { x : 123.45 , y : 1 } ) ;
902
+
903
+ el . setAttribute ( 'transform' , 'scale(0.1 2)' ) ;
904
+ expect ( Lib . getScale ( el ) ) . toEqual ( { x : 0.1 , y : 2 } ) ;
905
+
906
+ el . setAttribute ( 'transform' , 'scale(0.1 2); rotate(20deg)' ) ;
907
+ expect ( Lib . getScale ( el ) ) . toEqual ( { x : 0.1 , y : 2 } ) ;
908
+
909
+ el . setAttribute ( 'transform' , 'rotate(20deg) scale(0.1 2);' ) ;
910
+ expect ( Lib . getScale ( el ) ) . toEqual ( { x : 0.1 , y : 2 } ) ;
911
+
912
+ el . setAttribute ( 'transform' , 'rotate(20deg)' ) ;
913
+ expect ( Lib . getScale ( el ) ) . toEqual ( { x : 1 , y : 1 } ) ;
914
+ } ) ;
915
+
916
+ it ( 'should work with d3 elements' , function ( ) {
917
+ var el = d3 . select ( document . createElement ( 'div' ) ) ;
918
+
919
+ el . attr ( 'transform' , 'scale(1.23, 45)' ) ;
920
+ expect ( Lib . getScale ( el ) ) . toEqual ( { x : 1.23 , y : 45 } ) ;
921
+
922
+ el . attr ( 'transform' , 'scale(123.45)' ) ;
923
+ expect ( Lib . getScale ( el ) ) . toEqual ( { x : 123.45 , y : 1 } ) ;
924
+
925
+ el . attr ( 'transform' , 'scale(0.1 2)' ) ;
926
+ expect ( Lib . getScale ( el ) ) . toEqual ( { x : 0.1 , y : 2 } ) ;
927
+
928
+ el . attr ( 'transform' , 'scale(0.1 2); rotate(20)' ) ;
929
+ expect ( Lib . getScale ( el ) ) . toEqual ( { x : 0.1 , y : 2 } ) ;
930
+
931
+ el . attr ( 'transform' , 'rotate(20)' ) ;
932
+ expect ( Lib . getScale ( el ) ) . toEqual ( { x : 1 , y : 1 } ) ;
933
+ } ) ;
934
+ } ) ;
935
+
936
+ describe ( 'setScale' , function ( ) {
937
+
938
+ it ( 'should work with regular DOM elements' , function ( ) {
939
+ var el = document . createElement ( 'div' ) ;
940
+
941
+ Lib . setScale ( el , 5 ) ;
942
+ expect ( el . getAttribute ( 'transform' ) ) . toBe ( 'scale(5, 1)' ) ;
943
+
944
+ Lib . setScale ( el , 30 , 40 ) ;
945
+ expect ( el . getAttribute ( 'transform' ) ) . toBe ( 'scale(30, 40)' ) ;
946
+
947
+ Lib . setScale ( el ) ;
948
+ expect ( el . getAttribute ( 'transform' ) ) . toBe ( 'scale(1, 1)' ) ;
949
+
950
+ el . setAttribute ( 'transform' , 'scale(1, 1); rotate(30)' ) ;
951
+ Lib . setScale ( el , 30 , 40 ) ;
952
+ expect ( el . getAttribute ( 'transform' ) ) . toBe ( 'rotate(30) scale(30, 40)' ) ;
953
+ } ) ;
954
+
955
+ it ( 'should work with d3 elements' , function ( ) {
956
+ var el = d3 . select ( document . createElement ( 'div' ) ) ;
957
+
958
+ Lib . setScale ( el , 5 ) ;
959
+ expect ( el . attr ( 'transform' ) ) . toBe ( 'scale(5, 1)' ) ;
960
+
961
+ Lib . setScale ( el , 30 , 40 ) ;
962
+ expect ( el . attr ( 'transform' ) ) . toBe ( 'scale(30, 40)' ) ;
963
+
964
+ Lib . setScale ( el ) ;
965
+ expect ( el . attr ( 'transform' ) ) . toBe ( 'scale(1, 1)' ) ;
966
+
967
+ el . attr ( 'transform' , 'scale(0, 0); rotate(30)' ) ;
968
+ Lib . setScale ( el , 30 , 40 ) ;
969
+ expect ( el . attr ( 'transform' ) ) . toBe ( 'rotate(30) scale(30, 40)' ) ;
970
+ } ) ;
971
+ } ) ;
972
+
893
973
describe ( 'pushUnique' , function ( ) {
894
974
895
975
beforeEach ( function ( ) {
0 commit comments