Skip to content

Commit 868b546

Browse files
dabengDong Xuebin
authored andcommitted
refactor the core methods
1 parent c9cf2a6 commit 868b546

17 files changed

+452
-240
lines changed

README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ It's a so easy task, we just need to append id or className property to node dat
100100

101101
In fact, this is a wonderful solution to display a orgchart which includes a huge number of node data.
102102

103-
- [I want a hybrid(horizontal + vertical) chart](https://rawgit.com/dabeng/OrgChart/master/demo/vertical-depth.html)
103+
- [I want a hybrid(horizontal + vertical) chart](https://rawgit.com/dabeng/OrgChart/master/demo/vertical-level.html)
104104

105105
This feature is inspired by the issues([Aligning Children Vertical](https://github.com/dabeng/OrgChart/issues/46), [Hybrid(horizontal + vertical) OrgChart](https://github.com/dabeng/OrgChart/issues/61)). Thank [mfahadi](https://github.com/mfahadi) and [Destructrix](https://github.com/Destructrix) for their constructive suggestions:blush: Special thanks to [tedliang](https://github.com/tedliang) for his wonderful hybrid mode solution.
106106

107-
From now on, users never have to worry about how to align a huge of nodes in one screen of browser. The option "verticalDepth" allows users to align child nodes vertically from the given depth.
107+
From now on, users never have to worry about how to align a huge of nodes in one screen of browser. The option "verticalLevel" allows users to align child nodes vertically from the given level.
108108

109109
**Note**: currently, this option is incompatible with many other options or methods, like direction, drag&drop, addChildren(), removeNodes(), getHierarchy() and so on. These conflicts will be solved one by one in the later versions.
110110

@@ -191,7 +191,7 @@ var oc = $('#chartContainerId').orgchart(options);
191191
<td>direction</td><td>string</td><td>no</td><td>"t2b"</td><td>The available values are t2b(implies "top to bottom", it's default value), b2t(implies "bottom to top"), l2r(implies "left to right"), r2l(implies "right to left").</td>
192192
</tr>
193193
<tr>
194-
<td>verticalDepth</td><td>integer</td><td>no</td><td></td><td>Users can make use of this option to align the nodes vertically from the specified depth.</td>
194+
<td>verticalLevel</td><td>integer(>=2)</td><td>no</td><td></td><td>Users can make use of this option to align the nodes vertically from the specified level.</td>
195195
</tr>
196196
<tr>
197197
<td>toggleSiblingsResp</td><td>boolean</td><td>no</td><td>false</td><td>Once enable this option, users can show/hide left/right sibling nodes respectively by clicking left/right arrow.</td>
@@ -200,7 +200,7 @@ var oc = $('#chartContainerId').orgchart(options);
200200
<td>ajaxURL</td><td>json</td><td>no</td><td></td><td>It inclueds four properites -- parent, children, siblings, families(ask for parent node and siblings nodes). As their names imply, different propety provides the URL to which ajax request for different nodes is sent.</td>
201201
</tr>
202202
<tr>
203-
<td>depth</td><td>positive integer</td><td>no</td><td>999</td><td>It indicates the level that at the very beginning orgchart is expanded to.</td>
203+
<td>visibleLevel</td><td>positive integer</td><td>no</td><td>999</td><td>It indicates the level that at the very beginning orgchart is expanded to.</td>
204204
</tr>
205205
<tr>
206206
<td>nodeTitle</td><td>string</td><td>no</td><td>"name"</td><td>It sets one property of datasource as text content of title section of orgchart node. In fact, users can create a simple orghcart with only nodeTitle option.</td>
@@ -251,41 +251,38 @@ I'm sure that you can grasp the key points of the methods below after you try ou
251251
Embeds an organization chart in designated container. Accepts an options object and you can go through the "options" section to find which options are required. Variable oc is the instance of class OrgChart.
252252
#### init(newOptions)
253253
It's the useful way when users want to re-initialize or refresh orgchart based on new options or reload new data.
254-
#### addParent(data, opts)
254+
#### addParent(data)
255255
Adds parent node(actullay it's always root node) for current orgchart.
256256
<table>
257257
<thead>
258258
<tr><th>Name</th><th>Type</th><th>Required</th><th>Default</th><th>Description</th></tr>
259259
</thead>
260260
<tbody>
261261
<tr><td>data</td><td>json object</td><td>yes</td><td></td><td>datasource for building root node</td></tr>
262-
<tr><td>opts</td><td>json object</td><td>no</td><td>initial options of current orgchart</td><td>options used for overriding initial options</td></tr>
263262
</tbody>
264263
</table>
265264

266-
#### addSiblings($node, data, opts)
265+
#### addSiblings($node, data)
267266
Adds sibling nodes for designated node.
268267
<table>
269268
<thead>
270269
<tr><th>Name</th><th>Type</th><th>Required</th><th>Default</th><th>Description</th></tr>
271270
</thead>
272271
<tbody>
273272
<tr><td>$node</td><td>jquery object</td><td>yes</td><td></td><td>we'll add sibling nodes based on this node</td></tr>
274-
<tr><td>data</td><td>json object</td><td>yes</td><td></td><td>datasource for building sibling nodes</td></tr>
275-
<tr><td>opts</td><td>json object</td><td>no</td><td>initial options of current orgchart</td><td>options used for overriding initial options</td></tr>
273+
<tr><td>data</td><td>array</td><td>yes</td><td></td><td>datasource for building sibling nodes</td></tr>
276274
</tbody>
277275
</table>
278276

279-
#### addChildren($node, data, opts)
277+
#### addChildren($node, data)
280278
Adds child nodes for designed node.
281279
<table>
282280
<thead>
283281
<tr><th>Name</th><th>Type</th><th>Required</th><th>Default</th><th>Description</th></tr>
284282
</thead>
285283
<tbody>
286284
<tr><td>$node</td><td>jquery object</td><td>yes</td><td></td><td>we'll add child nodes based on this node</td></tr>
287-
<tr><td>data</td><td>json object</td><td>yes</td><td></td><td>datasource for building child nodes</td></tr>
288-
<tr><td>opts</td><td>json object</td><td>no</td><td>initial options of current orgchart</td><td>options used for overriding initial options</td></tr>
285+
<tr><td>data</td><td>array</td><td>yes</td><td></td><td>datasource for building child nodes</td></tr>
289286
</tbody>
290287
</table>
291288

demo/center-on-selected-node.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
};
4848

4949
$('#chart-container').orgchart({
50-
'depth': 2,
50+
'visibleLevel': 2,
5151
'pan': true,
5252
'data' : datascource,
5353
'nodeContent': 'title',

demo/edit-chart.html

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
<link rel="stylesheet" href="css/jquery.orgchart.css">
99
<link rel="stylesheet" href="css/style.css">
1010
<style type="text/css">
11-
#chart-container { background-color: #eee; height: 300px; }
11+
#chart-container { background-color: #eee; height: 500px; }
1212
.orgchart { background: #fff; }
13-
.orgchart.view-state .edge { display: none; }
13+
.orgchart.edit-state .edge { display: none; }
1414
.orgchart .node { width: 150px; }
15+
.orgchart .node .title { height: 30px; line-height: 30px; }
1516
.orgchart .node .title .symbol { margin-top: 1px; }
1617
#edit-panel {
1718
position: relative;
@@ -25,7 +26,7 @@
2526
background-color: #449d44;
2627
}
2728
#edit-panel .btn-inputs { font-size: 24px; }
28-
#edit-panel.view-state>:not(#chart-state-panel) { display: none; }
29+
#edit-panel.edit-state>:not(#chart-state-panel) { display: none; }
2930
#edit-panel label { font-weight: bold; }
3031
#edit-panel.edit-parent-node .selected-node-group { display: none; }
3132
#chart-state-panel, #selected-node, #btn-remove-input { margin-right: 20px; }
@@ -116,6 +117,7 @@
116117

117118
var oc = $('#chart-container').orgchart({
118119
'data' : datascource,
120+
'chartClass': 'edit-state',
119121
'exportButton': true,
120122
'exportFilename': 'SportsChart',
121123
'parentNodeSymbol': 'fa-th-large',
@@ -136,8 +138,8 @@
136138
});
137139

138140
$('input[name="chart-state"]').on('click', function() {
139-
$('.orgchart').toggleClass('view-state', this.value !== 'view');
140-
$('#edit-panel').toggleClass('view-state', this.value === 'view');
141+
$('.orgchart').toggleClass('edit-state', this.value !== 'view');
142+
$('#edit-panel').toggleClass('edit-state', this.value === 'view');
141143
if ($(this).val() === 'edit') {
142144
$('.orgchart').find('tr').removeClass('hidden')
143145
.find('td').removeClass('hidden')
@@ -211,22 +213,24 @@
211213
oc.addParent($chartContainer.find('.node:first'), { 'name': nodeVals[0], 'id': getId() });
212214
}
213215
} else if (nodeType.val() === 'siblings') {
214-
oc.addSiblings($node,
215-
{ 'siblings': nodeVals.map(function(item) { return { 'name': item, 'relationship': '110', 'id': getId() }; })
216-
});
216+
if ($node[0].id === oc.$chart.find('.node:first')[0].id) {
217+
alert('You are not allowed to directly add sibling nodes to root node');
218+
return;
219+
}
220+
oc.addSiblings($node, nodeVals.map(function (item) {
221+
return { 'name': item, 'relationship': '110', 'id': getId() };
222+
}));
217223
} else {
218224
var hasChild = $node.parent().attr('colspan') > 0 ? true : false;
219225
if (!hasChild) {
220226
var rel = nodeVals.length > 1 ? '110' : '100';
221-
oc.addChildren($node, {
222-
'children': nodeVals.map(function(item) {
223-
return { 'name': item, 'relationship': rel, 'id': getId() };
224-
})
225-
}, $.extend({}, $chartContainer.find('.orgchart').data('options'), { depth: 0 }));
227+
oc.addChildren($node, nodeVals.map(function (item) {
228+
return { 'name': item, 'relationship': rel, 'id': getId() };
229+
}));
226230
} else {
227-
oc.addSiblings($node.closest('tr').siblings('.nodes').find('.node:first'),
228-
{ 'siblings': nodeVals.map(function(item) { return { 'name': item, 'relationship': '110', 'id': getId() }; })
229-
});
231+
oc.addSiblings($node.closest('tr').siblings('.nodes').find('.node:first'), nodeVals.map(function (item) {
232+
return { 'name': item, 'relationship': '110', 'id': getId() };
233+
}));
230234
}
231235
}
232236
});

demo/expand-to-given-depth.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
]
5050
};
5151

52-
var showDescendents = function(node, depth) {
53-
if (depth === 1) {
52+
var showDescendents = function(node, visibleLevel) {
53+
if (visibleLevel === 1) {
5454
return false;
5555
}
5656
$(node).closest('tr').siblings(':last').children().find('.node:first').each(function(index, node) {
@@ -60,12 +60,12 @@
6060
$children[0].style.offsetWidth = $children[0].offsetWidth;
6161
}
6262
$children.removeClass('slide-up');
63-
showDescendents(node, depth--);
63+
showDescendents(node, visibleLevel--);
6464
});
6565
};
6666

6767
$('#chart-container').orgchart({
68-
'depth': 2,
68+
'visibleLevel': 2,
6969
'data' : datascource,
7070
'nodeContent': 'title',
7171
'createNode': function($node, data) {

demo/export-chart.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
$('#chart-container').orgchart({
5353
'data' : datascource,
54-
'depth': 2,
54+
'visibleLevel': 2,
5555
'nodeContent': 'title',
5656
'exportButton': true,
5757
'exportFilename': 'MyOrgChart'

demo/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@
134134
<li><a href="reload-data.html" target="_blank">refresh orgchart with new options</a></li>
135135
<li><a href="report-path.html" target="_blank">report path</a></li>
136136
<li><a href="toggle-sibs-resp.html" target="_blank">toggle sibling nodes respectively</a></li>
137-
<li><a href="ul-datasource.html">ul datasource</a></li>
138-
<li><a href="vertical-depth.html">hybrid(horizontal + vertical) chart</a></li>
139-
<li><a href="custom-template.html">template for internal structure of node</a></li>
137+
<li><a href="ul-datasource.html" target="_blank">ul datasource</a></li>
138+
<li><a href="vertical-level.html" target="_blank">hybrid(horizontal + vertical) chart</a></li>
139+
<li><a href="custom-template.html" target="_blank">template for internal structure of node</a></li>
140140
</ol>
141141
</section>
142142
</body>

demo/local-datasource.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
{ 'name': 'Hong Miao', 'title': 'department manager' }
3636
]
37-
}
37+
};
3838

3939
$('#chart-container').orgchart({
4040
'data' : datasource,

demo/option-createNode.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575

7676
$('#chart-container').orgchart({
7777
'data' : datascource,
78-
'depth': 2,
78+
'visibleLevel': 2,
7979
'nodeContent': 'title',
8080
'nodeID': 'id',
8181
'createNode': function($node, data) {

demo/vertical-depth.html renamed to demo/vertical-level.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
$('#chart-container').orgchart({
6464
'data' : datascource,
6565
'nodeContent': 'title',
66-
'verticalDepth': 3,
67-
'depth': 4
66+
'verticalLevel': 3,
67+
'visibleLevel': 4
6868
});
6969

7070
});

0 commit comments

Comments
 (0)