@@ -55,6 +55,10 @@ function eqL(levels, items) {
55
55
return result ;
56
56
}
57
57
58
+ function getLeftNode ( visualTree , nodeId ) {
59
+ return visualTree . getChild ( visualTree . parentid ( nodeId ) , visualTree . indexOf ( nodeId ) - 1 ) ;
60
+ }
61
+
58
62
test ( "Horizontal children layout" , ( ) => {
59
63
var builder = VisualTreeBuilder ( ) ;
60
64
const items = [
@@ -1226,3 +1230,199 @@ test("Trim trailing invisible nodes", () => {
1226
1230
expect ( visualTree . node ( 3 ) ) . toBe ( undefined ) ;
1227
1231
} ) ;
1228
1232
1233
+ test ( "Cross-branch aligned child should be at the same level" , ( ) => {
1234
+ var builder = VisualTreeBuilder ( ) ;
1235
+ const items = [
1236
+ { id : 0 , parent : null , name : "Auto created invisible root item" } ,
1237
+ { id : 1 , parent : 0 , name : "1" } ,
1238
+ { id : 2 , parent : 1 , name : "Branch 1" } ,
1239
+ { id : 3 , parent : 1 , name : "Branch 2" } ,
1240
+ { id : 4 , parent : 2 , name : "4" , itemType : ItemType . Assistant } ,
1241
+ { id : 5 , parent : 2 , name : "5" } ,
1242
+ { id : 6 , parent : 3 , name : "6" } ,
1243
+ ] ;
1244
+ var { visualTree, navigationFamily } = builder . build (
1245
+ getOrgTree ( items ) ,
1246
+ getMaximumId ( items ) ,
1247
+ getActiveItems ( items ) ,
1248
+ {
1249
+ alignBranches : true ,
1250
+ childrenPlacementType : ChildrenPlacementType . Horizontal ,
1251
+ horizontalAlignment : HorizontalAlignmentType . Center ,
1252
+ leavesPlacementType : ChildrenPlacementType . Horizontal ,
1253
+ maximumColumnsInMatrix : 2 ,
1254
+ placeAdvisersAboveChildren : true ,
1255
+ placeAssistantsAboveChildren : true ,
1256
+ }
1257
+ ) ;
1258
+ var l = getLevels ( visualTree ) ;
1259
+ expect ( l [ 0 ] < l [ 2 ] && eqL ( l , [ 2 , 3 ] ) && l [ 2 ] < l [ 4 ] && l [ 4 ] < l [ 5 ] && eqL ( l , [ 5 , 6 ] ) ) . toBe ( true ) ;
1260
+ } ) ;
1261
+
1262
+ test ( "Cross-branch aligned child should be at the same level when assistants have children" , ( ) => {
1263
+ var builder = VisualTreeBuilder ( ) ;
1264
+ const items = [
1265
+ { id : 0 , parent : null , name : "Auto created invisible root item" } ,
1266
+ { id : 1 , parent : 0 , name : "1" } ,
1267
+ { id : 2 , parent : 1 , name : "Branch 1" } ,
1268
+ { id : 3 , parent : 1 , name : "Branch 2" } ,
1269
+ { id : 4 , parent : 2 , name : "4" , itemType : ItemType . Assistant } ,
1270
+ { id : 5 , parent : 2 , name : "5" } ,
1271
+ { id : 6 , parent : 3 , name : "6" } ,
1272
+ { id : 7 , parent : 4 , name : "Extra child for Assistant" } ,
1273
+ ] ;
1274
+ var { visualTree, navigationFamily } = builder . build (
1275
+ getOrgTree ( items ) ,
1276
+ getMaximumId ( items ) ,
1277
+ getActiveItems ( items ) ,
1278
+ {
1279
+ alignBranches : true ,
1280
+ childrenPlacementType : ChildrenPlacementType . Horizontal ,
1281
+ horizontalAlignment : HorizontalAlignmentType . Center ,
1282
+ leavesPlacementType : ChildrenPlacementType . Horizontal ,
1283
+ maximumColumnsInMatrix : 3 ,
1284
+ placeAdvisersAboveChildren : true ,
1285
+ placeAssistantsAboveChildren : true ,
1286
+ }
1287
+ ) ;
1288
+ var l = getLevels ( visualTree ) ;
1289
+ expect ( l [ 0 ] < l [ 2 ] && eqL ( l , [ 2 , 3 ] ) && l [ 2 ] < l [ 4 ] && l [ 4 ] < l [ 5 ] && eqL ( l , [ 5 , 6 ] ) ) . toBe ( true ) ;
1290
+ expect ( l [ 7 ] < l [ 5 ] ) . toBe ( true ) ;
1291
+ } ) ;
1292
+
1293
+ test ( "Cross-branch alignment Use Case" , ( ) => {
1294
+ var builder = VisualTreeBuilder ( ) ;
1295
+ const items = [
1296
+ /* Branch 1 */
1297
+ { id : 0 , parent : null , name : "Auto created invisible root item" } ,
1298
+ { id : 1 , parent : 0 , title : "Branch 1" , childrenPlacementType : ChildrenPlacementType . Matrix } ,
1299
+ { id : 10 , parent : 1 , levelOffset : 0 , title : "Child 1 at row 0" } ,
1300
+ { id : 11 , parent : 1 , levelOffset : 0 , title : "Child 2 at row 0" } ,
1301
+ { id : 12 , parent : 1 , levelOffset : 1 , title : "Child 3 at row 1" } ,
1302
+ { id : 13 , parent : 1 , levelOffset : 1 , title : "Child 4 at row 1" } ,
1303
+ { id : 14 , parent : 1 , levelOffset : 1 , title : "Child 5 at row 1" } ,
1304
+ { id : 15 , parent : 1 , levelOffset : 1 , title : "Child 6 at row 1" } ,
1305
+ { id : 2 , parent : 1 , title : "Child 7" } ,
1306
+ { id : 3 , parent : 1 , title : "Child 8" } ,
1307
+ { id : 4 , parent : 1 , title : "Child 9" } ,
1308
+ { id : 5 , parent : 1 , title : "Child 10" } ,
1309
+ { id : 6 , parent : 1 , title : "Child 11" } ,
1310
+ { id : 7 , parent : 1 , title : "Child 12" } ,
1311
+ { id : 8 , parent : 1 , title : "Child 13" } ,
1312
+ { id : 9 , parent : 1 , title : "Child 14" } ,
1313
+
1314
+ /* Branch 2 */
1315
+ { id : 101 , parent : 0 , title : "Branch 2" } ,
1316
+ { id : 102 , parent : 101 , levelOffset : 1 , title : "Child 1 at row 1" } ,
1317
+ { id : 103 , parent : 101 , levelOffset : 1 , title : "Child 2 at row 1" , childrenPlacementType : ChildrenPlacementType . Vertical } ,
1318
+ { id : 104 , parent : 103 , title : "Sub Child 3" } ,
1319
+ { id : 105 , parent : 103 , title : "Sub Child 4" } ,
1320
+ { id : 106 , parent : 101 , title : "Child 3" } ,
1321
+ { id : 107 , parent : 101 , title : "Child 4" }
1322
+ ] ;
1323
+ var { visualTree, navigationFamily } = builder . build (
1324
+ getOrgTree ( items ) ,
1325
+ getMaximumId ( items ) ,
1326
+ getActiveItems ( items ) ,
1327
+ {
1328
+ alignBranches : true ,
1329
+ childrenPlacementType : ChildrenPlacementType . Horizontal ,
1330
+ horizontalAlignment : HorizontalAlignmentType . Center ,
1331
+ leavesPlacementType : ChildrenPlacementType . Horizontal ,
1332
+ maximumColumnsInMatrix : 3 ,
1333
+ placeAdvisersAboveChildren : true ,
1334
+ placeAssistantsAboveChildren : true ,
1335
+ }
1336
+ ) ;
1337
+ var l = getLevels ( visualTree ) ;
1338
+ expect ( l [ 10 ] < l [ 12 ] && eqL ( l , [ 10 , 11 ] ) && eqL ( l , [ 12 , 13 , 14 , 15 , 102 , 103 ] ) && l [ 12 ] < l [ 2 ] && eqL ( l , [ 2 , 3 , 4 , 106 , 107 ] ) ) . toBe ( true ) ;
1339
+ } ) ;
1340
+
1341
+ test ( "Cross-branch aligned matrix children formation should not have empty trailing aggregators" , ( ) => {
1342
+ var builder = VisualTreeBuilder ( ) ;
1343
+ const items = [
1344
+ /* Branch 1 */
1345
+ { id : 0 , parent : null , name : "Auto created invisible root item" } ,
1346
+ /* matrix layout example */
1347
+ { id : 1 , parent : 0 , title : "Matrix Layout" , childrenPlacementType : ChildrenPlacementType . Matrix } ,
1348
+ { id : 2 , parent : 1 , title : "Child 1" } ,
1349
+ { id : 3 , parent : 1 , title : "Child 2" } ,
1350
+ { id : 4 , parent : 1 , title : "Child 3" } ,
1351
+ { id : 5 , parent : 1 , title : "Child 4" } ,
1352
+ { id : 6 , parent : 1 , title : "Child 5" } ,
1353
+ { id : 7 , parent : 1 , title : "Child 6" } ,
1354
+ { id : 8 , parent : 1 , title : "Child 7" } ,
1355
+ { id : 9 , parent : 1 , title : "Child 8" } ,
1356
+
1357
+ /* vertical layout example */
1358
+ { id : 101 , parent : 0 , title : "Vertical Layout" , childrenPlacementType : ChildrenPlacementType . Vertical } ,
1359
+ { id : 102 , parent : 101 , title : "Child 1" } ,
1360
+ { id : 103 , parent : 101 , title : "Child 2" , childrenPlacementType : ChildrenPlacementType . Vertical } ,
1361
+ { id : 104 , parent : 103 , title : "Sub Child 3" } ,
1362
+ { id : 105 , parent : 103 , title : "Sub Child 4" } ,
1363
+ { id : 106 , parent : 101 , title : "Child 5" }
1364
+ ] ;
1365
+ var { visualTree, navigationFamily } = builder . build (
1366
+ getOrgTree ( items ) ,
1367
+ getMaximumId ( items ) ,
1368
+ getActiveItems ( items ) ,
1369
+ {
1370
+ alignBranches : true ,
1371
+ childrenPlacementType : ChildrenPlacementType . Horizontal ,
1372
+ horizontalAlignment : HorizontalAlignmentType . Center ,
1373
+ leavesPlacementType : ChildrenPlacementType . Horizontal ,
1374
+ maximumColumnsInMatrix : 3 ,
1375
+ placeAdvisersAboveChildren : true ,
1376
+ placeAssistantsAboveChildren : true ,
1377
+ }
1378
+ ) ;
1379
+ var l = getLevels ( visualTree ) ;
1380
+ var va = getLeftNode ( visualTree , 7 ) ;
1381
+
1382
+ expect ( eqL ( l , [ 8 , 9 , 106 ] ) && l [ 105 ] < l [ 106 ] ) . toBe ( true ) ;
1383
+ expect ( visualTree . hasChildren ( va . id ) ) . toBe ( false ) ;
1384
+ } ) ;
1385
+
1386
+ test ( "Cross-branch aligned vertical children formation should not have empty trailing aggregators" , ( ) => {
1387
+ var builder = VisualTreeBuilder ( ) ;
1388
+ const items = [
1389
+ /* Branch 1 */
1390
+ { id : 0 , parent : null , name : "Auto created invisible root item" } ,
1391
+ /* matrix layout example */
1392
+ { id : 1 , parent : 0 , title : "Matrix Layout" , childrenPlacementType : ChildrenPlacementType . Matrix } ,
1393
+ { id : 2 , parent : 1 , title : "Child 1" } ,
1394
+ { id : 3 , parent : 1 , title : "Child 2" } ,
1395
+ { id : 4 , parent : 1 , title : "Child 3" } ,
1396
+ { id : 5 , parent : 1 , title : "Child 4" } ,
1397
+ { id : 6 , parent : 1 , title : "Child 5" , childrenPlacementType : ChildrenPlacementType . Vertical } ,
1398
+ { id : 104 , parent : 6 , title : "Sub Child 3" } ,
1399
+ { id : 105 , parent : 6 , title : "Sub Child 4" } ,
1400
+ { id : 7 , parent : 1 , title : "Child 6" } ,
1401
+ { id : 8 , parent : 1 , title : "Child 7" } ,
1402
+ { id : 9 , parent : 1 , title : "Child 8" } ,
1403
+
1404
+ /* vertical layout example */
1405
+ { id : 101 , parent : 0 , title : "Vertical Layout" , childrenPlacementType : ChildrenPlacementType . Vertical } ,
1406
+ { id : 102 , parent : 101 , title : "Child 1" } ,
1407
+ { id : 103 , parent : 101 , title : "Child 2" }
1408
+ ] ;
1409
+ var { visualTree, navigationFamily } = builder . build (
1410
+ getOrgTree ( items ) ,
1411
+ getMaximumId ( items ) ,
1412
+ getActiveItems ( items ) ,
1413
+ {
1414
+ alignBranches : true ,
1415
+ childrenPlacementType : ChildrenPlacementType . Horizontal ,
1416
+ horizontalAlignment : HorizontalAlignmentType . Center ,
1417
+ leavesPlacementType : ChildrenPlacementType . Horizontal ,
1418
+ maximumColumnsInMatrix : 3 ,
1419
+ placeAdvisersAboveChildren : true ,
1420
+ placeAssistantsAboveChildren : true ,
1421
+ }
1422
+ ) ;
1423
+ var l = getLevels ( visualTree ) ;
1424
+ var va = getLeftNode ( visualTree , 103 ) ;
1425
+
1426
+ expect ( l [ 105 ] < l [ 9 ] ) . toBe ( true ) ;
1427
+ expect ( visualTree . hasChildren ( va . id ) ) . toBe ( false ) ;
1428
+ } ) ;
0 commit comments