1
1
var Plotly = require ( '@lib' ) ;
2
2
var Plots = require ( '@src/plots/plots' ) ;
3
3
var Lib = require ( '@src/lib' ) ;
4
+ var Drawing = require ( '@src/components/drawing' ) ;
4
5
var constants = require ( '@src/traces/treemap/constants' ) ;
5
6
6
7
var d3 = require ( 'd3' ) ;
@@ -1113,25 +1114,26 @@ describe('Test treemap tweening:', function() {
1113
1114
return s . replace ( / \s / g, '' ) ;
1114
1115
}
1115
1116
1117
+
1116
1118
function _assert ( msg , attrName , id , exp ) {
1117
1119
var lookup = { d : pathTweenFnLookup , transform : textTweenFnLookup } [ attrName ] ;
1118
1120
var fn = lookup [ id ] ;
1119
1121
// normalize time in [0, 1] where we'll assert the tweening fn output,
1120
1122
// asserting at the mid point *should be* representative enough
1121
1123
var t = 0.5 ;
1122
1124
var actual = trim ( fn ( t ) ) ;
1125
+ var msg2 = msg + ' | node ' + id + ' @t=' + t ;
1123
1126
1124
- // do not assert textBB translate piece,
1125
- // which isn't tweened and has OS-dependent results
1126
1127
if ( attrName === 'transform' ) {
1127
- actual = actual . split ( 'translate' ) . slice ( 0 , 2 ) . join ( 'translate' ) ;
1128
+ var fake = { attr : function ( ) { return actual ; } } ;
1129
+ var xy = Drawing . getTranslate ( fake ) ;
1130
+ expect ( [ xy . x , xy . y ] ) . toBeWithinArray ( exp , 1 , msg2 ) ;
1131
+ } else {
1132
+ // we could maybe to bring in:
1133
+ // https://github.com/hughsk/svg-path-parser
1134
+ // to make these assertions more readable
1135
+ expect ( actual ) . toBe ( trim ( exp ) , msg2 ) ;
1128
1136
}
1129
-
1130
- // we could maybe to bring in:
1131
- // https://github.com/hughsk/svg-path-parser
1132
- // to make these assertions more readable
1133
-
1134
- expect ( actual ) . toBe ( trim ( exp ) , msg + ' | node ' + id + ' @t=' + t ) ;
1135
1137
}
1136
1138
1137
1139
it ( 'should tween sector exit/update (case: click on branch, no maxdepth)' , function ( done ) {
@@ -1158,12 +1160,8 @@ describe('Test treemap tweening:', function() {
1158
1160
_assert ( 'update b to new position' , 'd' , 'b' ,
1159
1161
'M221.75,136L611,136L611,361L221.75,361Z'
1160
1162
) ;
1161
- _assert ( 'move B text to new position' , 'transform' , 'B' ,
1162
- 'translate(221.75126)'
1163
- ) ;
1164
- _assert ( 'move b text to new position' , 'transform' , 'b' ,
1165
- 'translate(224.75150)'
1166
- ) ;
1163
+ _assert ( 'move B text to new position' , 'transform' , 'B' , [ 221.75126 , 0 ] ) ;
1164
+ _assert ( 'move b text to new position' , 'transform' , 'b' , [ 224.75150 , 0 ] ) ;
1167
1165
} )
1168
1166
. catch ( failTest )
1169
1167
. then ( done ) ;
@@ -1194,12 +1192,8 @@ describe('Test treemap tweening:', function() {
1194
1192
_assert ( 'update b to new position' , 'd' , 'b' ,
1195
1193
'M221.75,136L611,136L611,361L221.75,361Z'
1196
1194
) ;
1197
- _assert ( 'move B text to new position' , 'transform' , 'B' ,
1198
- 'translate(221.75126)'
1199
- ) ;
1200
- _assert ( 'move b text to new position' , 'transform' , 'b' ,
1201
- 'translate(224.75150)'
1202
- ) ;
1195
+ _assert ( 'move B text to new position' , 'transform' , 'B' , [ 221.75126 , 0 ] ) ;
1196
+ _assert ( 'move b text to new position' , 'transform' , 'b' , [ 224.75150 , 0 ] ) ;
1203
1197
} )
1204
1198
. catch ( failTest )
1205
1199
. then ( done ) ;
@@ -1230,12 +1224,8 @@ describe('Test treemap tweening:', function() {
1230
1224
_assert ( 'enter b for parent position' , 'd' , 'b' ,
1231
1225
'M284.375,188.5L548.375,188.5L548.375,308.5L284.375,308.5Z'
1232
1226
) ;
1233
- _assert ( 'move B text to new position' , 'transform' , 'B' ,
1234
- 'translate(220.25126)'
1235
- ) ;
1236
- _assert ( 'enter b text to new position' , 'transform' , 'b' ,
1237
- 'translate(287.375195.5)scale(0.5)'
1238
- ) ;
1227
+ _assert ( 'move B text to new position' , 'transform' , 'B' , [ 220.25126 , 0 ] ) ;
1228
+ _assert ( 'enter b text to new position' , 'transform' , 'b' , [ 287.375195 , 5 ] ) ;
1239
1229
} )
1240
1230
. catch ( failTest )
1241
1231
. then ( done ) ;
0 commit comments