Skip to content

Commit 2bc359c

Browse files
committed
WIP: implement family tree
1 parent b1cf73e commit 2bc359c

File tree

4 files changed

+24
-108
lines changed

4 files changed

+24
-108
lines changed

dist/js/jquery.orgchart.js

Lines changed: 11 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,21 +1446,15 @@
14461446
$hierarchy.append($nodesLayer);
14471447
}
14481448
// recurse through children nodes
1449-
$.each(data.children, function () {
1450-
if (Array.isArray(this)) {
1449+
$.each(data, function () {
1450+
if (Array.isArray(this)) { // 处理一对夫妻(可能有多个妻)
14511451
$.each(this, function() {
14521452
this.level = level + 1;
1453-
if (data.compact) {
1454-
that.buildHierarchy($nodeDiv, this);
1455-
} else {
1456-
var $nodeCell = $('<li class="hierarchy">');
1457-
$nodesLayer.append($nodeCell);
1458-
that.buildHierarchy($nodeCell, this);
1459-
}
14601453
});
1454+
that.buildHierarchy($nodesLayer, [this]);
14611455
} else {
14621456
this.level = level + 1;
1463-
if (data.compact) {
1457+
if (this.compact) {
14641458
that.buildHierarchy($nodeDiv, this);
14651459
} else {
14661460
var $nodeCell = $('<li class="hierarchy">');
@@ -1491,24 +1485,24 @@
14911485
}
14921486
}
14931487
// Construct the single node in OrgChart or the multiple nodes in family tree
1494-
if (Array.isArray(data)) {
1495-
$.each(data, function () {
1488+
if (Array.isArray(data)) { // 处理family tree的情况
1489+
$.each(data, function () { // 构造一个家庭的hierarchy
14961490
var _this = this;
1497-
$.each(this, function (i) {
1491+
$.each(this, function (i) { // 构造一个夫/妻节点
14981492
$nodeDiv = that.createNode(this);
14991493
// if there are only two persons in a marriage, two single nodes will appear in a hierarchy
15001494
if (_this.length === 2 && i === 1) {
1501-
$hierarchy.children('.hierarchy:first').append($nodeDiv);
1495+
$hierarchy.find(`#${_this[0].id}`).after($nodeDiv);
15021496
if (this.children && this.children.length) {
1503-
that.buildInferiorNodes($hierarchy.children('.hierarchy:first'), $nodeDiv, this, level);
1497+
that.buildInferiorNodes($hierarchy.find(`#${_this[0].id}`).parent(), $nodeDiv, this.children, level);
15041498
}
15051499
} else {
15061500
// if there are more than two persons in a marriage, every node will be included in a single hierarchy
15071501
var $wrapper = $('<li class="hierarchy"></li>');
15081502
$wrapper.append($nodeDiv);
15091503
$hierarchy.append($wrapper);
15101504
if (this.children && this.children.length) {
1511-
that.buildInferiorNodes($wrapper, $nodeDiv, this, level);
1505+
that.buildInferiorNodes($wrapper, $nodeDiv, this.children, level);
15121506
}
15131507
}
15141508
});
@@ -1517,45 +1511,9 @@
15171511
$nodeDiv = this.createNode(data);
15181512
$hierarchy.append($nodeDiv);
15191513
if (data.children && data.children.length) {
1520-
this.buildInferiorNodes($hierarchy, $nodeDiv, data, level);
1514+
this.buildInferiorNodes($hierarchy, $nodeDiv, data.children, level);
15211515
}
15221516
}
1523-
1524-
// Construct the "inferior nodes"
1525-
/*if (data.children && data.children.length) {
1526-
var isHidden = level + 1 > opts.visibleLevel || (data.collapsed !== undefined && data.collapsed);
1527-
var $nodesLayer;
1528-
if ((opts.verticalLevel && (level + 1) >= opts.verticalLevel) || data.hybrid) {
1529-
$nodesLayer = $('<ul class="nodes">');
1530-
if (isHidden && (opts.verticalLevel && (level + 1) >= opts.verticalLevel)) {
1531-
$nodesLayer.addClass('hidden');
1532-
}
1533-
if (((opts.verticalLevel && level + 1 === opts.verticalLevel) || data.hybrid)
1534-
&& !$hierarchy.closest('.vertical').length) {
1535-
$nodesLayer.addClass('vertical');
1536-
}
1537-
$hierarchy.append($nodesLayer);
1538-
} else if (data.compact) {
1539-
$nodeDiv.addClass('compact');
1540-
} else {
1541-
$nodesLayer = $('<ul class="nodes' + (isHidden ? ' hidden' : '') + '">');
1542-
if (isHidden) {
1543-
$hierarchy.addClass('isChildrenCollapsed');
1544-
}
1545-
$hierarchy.append($nodesLayer);
1546-
}
1547-
// recurse through children nodes
1548-
$.each(data.children, function () {
1549-
this.level = level + 1;
1550-
if (data.compact) {
1551-
that.buildHierarchy($nodeDiv, this);
1552-
} else {
1553-
var $nodeCell = $('<li class="hierarchy">');
1554-
$nodesLayer.append($nodeCell);
1555-
that.buildHierarchy($nodeCell, this);
1556-
}
1557-
});
1558-
}*/
15591517
},
15601518
// build the child nodes of specific node
15611519
buildChildNode: function ($appendTo, data) {

0 commit comments

Comments
 (0)