@@ -823,6 +823,9 @@ describe('Test lib.js:', function() {
823823 el . setAttribute ( 'transform' , 'translate(1 2); rotate(20deg)' ) ;
824824 expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 1 , y : 2 } ) ;
825825
826+ el . setAttribute ( 'transform' , 'rotate(20deg) translate(1 2);' ) ;
827+ expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 1 , y : 2 } ) ;
828+
826829 el . setAttribute ( 'transform' , 'rotate(20deg)' ) ;
827830 expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 0 , y : 0 } ) ;
828831 } ) ;
@@ -858,9 +861,6 @@ describe('Test lib.js:', function() {
858861 Lib . setTranslate ( el , 10 , 20 ) ;
859862 expect ( el . getAttribute ( 'transform' ) ) . toBe ( 'translate(10, 20)' ) ;
860863
861- Lib . setTranslate ( el , 30 , 40 ) ;
862- expect ( el . getAttribute ( 'transform' ) ) . toBe ( 'translate(30, 40)' ) ;
863-
864864 Lib . setTranslate ( el ) ;
865865 expect ( el . getAttribute ( 'transform' ) ) . toBe ( 'translate(0, 0)' ) ;
866866
@@ -875,9 +875,6 @@ describe('Test lib.js:', function() {
875875 Lib . setTranslate ( el , 5 ) ;
876876 expect ( el . attr ( 'transform' ) ) . toBe ( 'translate(5, 0)' ) ;
877877
878- Lib . setTranslate ( el , 10 , 20 ) ;
879- expect ( el . attr ( 'transform' ) ) . toBe ( 'translate(10, 20)' ) ;
880-
881878 Lib . setTranslate ( el , 30 , 40 ) ;
882879 expect ( el . attr ( 'transform' ) ) . toBe ( 'translate(30, 40)' ) ;
883880
@@ -890,6 +887,89 @@ describe('Test lib.js:', function() {
890887 } ) ;
891888 } ) ;
892889
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+
893973 describe ( 'pushUnique' , function ( ) {
894974
895975 beforeEach ( function ( ) {
0 commit comments