Skip to content

Commit 61bdcb3

Browse files
committed
WIP: implement family tree
1 parent f401bc7 commit 61bdcb3

File tree

9 files changed

+24
-17
lines changed

9 files changed

+24
-17
lines changed

demo/family-tree.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
<style type="text/css">
1010
.orgchart { background: #fff; }
1111
#chart-container {
12-
height: 800px;
12+
height: 850px;
1313
}
1414
.orgchart .node {
1515
padding: 3px 8px;
1616
/* box-shadow: rgba(99, 99, 99, 0.3) 0px 2px 8px 0px; */
1717
}
1818
.orgchart .node .avatar {
19-
box-shadow: rgba(99, 99, 99, 0.3) 0px 2px 8px 0px;
19+
border-radius: 60px;
20+
box-shadow: rgba(99, 99, 99, 0.8) 0px 2px 8px 0px;
2021
}
2122
.orgchart .couple:has(> .nodes) > .node:first-child::after {
2223
top: 148px;
@@ -64,7 +65,7 @@
6465
{ 'id': '12', 'name': 'Pang Pang', 'title': 'Wife', 'gender': 'female', 'outsider': true,
6566
'children': [
6667
[{ 'id': '7', 'name': 'Dan Dan', 'title': 'Daughter', 'gender': 'female' }],
67-
[{ 'id': '6', 'name': 'Er Dan', 'title': 'Daughter', 'gender': 'female' }],
68+
// [{ 'id': '6', 'name': 'Er Dan', 'title': 'Daughter', 'gender': 'female' }],
6869
]
6970
},
7071
{ 'id': '5', 'name': 'Hei Hei', 'title': 'Me', 'gender': 'male' },

demo/option-createNode.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
border-radius: 35px;
2727
box-shadow: 0 0 10px 1px #999;
2828
background-color: #fff;
29-
z-index: 1;
29+
z-index: 3;
3030
}
3131
.orgchart .node .second-menu .avatar {
3232
width: 60px;

dist/css/jquery.orgchart.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
background-color: rgba(238, 217, 54, 0.5);
260260
transition: .5s;
261261
cursor: default;
262-
z-index: 20;
262+
z-index: 2;
263263
}
264264

265265
.orgchart .node.focused {

dist/css/jquery.orgchart.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/jquery.orgchart.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@
750750
},
751751
// whether the cursor is hovering over the node
752752
isInAction: function ($node) {
753+
// TODO: 展开/折叠的按钮不止4个箭头,还有toggleBtn
753754
return [
754755
this.options.icons.expandToUp,
755756
this.options.icons.collapseToDown,
@@ -1474,7 +1475,7 @@
14741475
level = data.level;
14751476
} else {
14761477
level = $hierarchy.parentsUntil('.orgchart', '.nodes').length;
1477-
if (Array.isArray(data)) {
1478+
if (Array.isArray(data) && Array.isArray(data[0])) {
14781479
$.each(data, function () {
14791480
$.each(this, function () {
14801481
this.level = level;
@@ -1485,7 +1486,7 @@
14851486
}
14861487
}
14871488
// Construct the single node in OrgChart or the multiple nodes in family tree
1488-
if (Array.isArray(data)) { // 处理family tree的情况
1489+
if (Array.isArray(data) && Array.isArray(data[0])) { // 处理family tree的情况
14891490
$.each(data, function () { // 构造一个家庭的hierarchy
14901491
var _this = this;
14911492
$.each(this, function (i) { // 构造一个夫/妻节点
@@ -1518,8 +1519,10 @@
15181519
});
15191520
});
15201521
} else {
1521-
$nodeDiv = this.createNode(data);
1522-
$hierarchy.append($nodeDiv);
1522+
if (Object.keys(data).length > 2) { // TODO: 应该用更好的方式来判断是否是供父一级节点创建的信息
1523+
$nodeDiv = this.createNode(data);
1524+
$hierarchy.append($nodeDiv);
1525+
}
15231526
if (data.children && data.children.length) {
15241527
this.buildInferiorNodes($hierarchy, $nodeDiv, data, level);
15251528
}

dist/js/jquery.orgchart.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/jquery.orgchart.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/css/jquery.orgchart.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
background-color: rgba(238, 217, 54, 0.5);
260260
transition: .5s;
261261
cursor: default;
262-
z-index: 20;
262+
z-index: 2;
263263
}
264264

265265
.orgchart .node.focused {

src/js/jquery.orgchart.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@
750750
},
751751
// whether the cursor is hovering over the node
752752
isInAction: function ($node) {
753+
// TODO: 展开/折叠的按钮不止4个箭头,还有toggleBtn
753754
return [
754755
this.options.icons.expandToUp,
755756
this.options.icons.collapseToDown,
@@ -1474,7 +1475,7 @@
14741475
level = data.level;
14751476
} else {
14761477
level = $hierarchy.parentsUntil('.orgchart', '.nodes').length;
1477-
if (Array.isArray(data)) {
1478+
if (Array.isArray(data) && Array.isArray(data[0])) {
14781479
$.each(data, function () {
14791480
$.each(this, function () {
14801481
this.level = level;
@@ -1485,7 +1486,7 @@
14851486
}
14861487
}
14871488
// Construct the single node in OrgChart or the multiple nodes in family tree
1488-
if (Array.isArray(data)) { // 处理family tree的情况
1489+
if (Array.isArray(data) && Array.isArray(data[0])) { // 处理family tree的情况
14891490
$.each(data, function () { // 构造一个家庭的hierarchy
14901491
var _this = this;
14911492
$.each(this, function (i) { // 构造一个夫/妻节点
@@ -1518,8 +1519,10 @@
15181519
});
15191520
});
15201521
} else {
1521-
$nodeDiv = this.createNode(data);
1522-
$hierarchy.append($nodeDiv);
1522+
if (Object.keys(data).length > 2) { // TODO: 应该用更好的方式来判断是否是供父一级节点创建的信息
1523+
$nodeDiv = this.createNode(data);
1524+
$hierarchy.append($nodeDiv);
1525+
}
15231526
if (data.children && data.children.length) {
15241527
this.buildInferiorNodes($hierarchy, $nodeDiv, data, level);
15251528
}

0 commit comments

Comments
 (0)