Skip to content

Commit

Permalink
expose methods -- getParent(),getSiblings(),getChildren()
Browse files Browse the repository at this point in the history
  • Loading branch information
Xuebin Dong committed Nov 12, 2022
1 parent 4bbd7a8 commit 27c60e4
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 8 deletions.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,63 @@ This method returns you the nodes related to the specified node.
</tr>
</table>

#### getParent($node)
This method returns you the parent node of the specified node.
<table>
<tr>
<th>Name</th>
<th>Type</th>
<th>Required</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td>$node</td>
<td>JQuery Object</td>
<td>Yes</td>
<td></td>
<td>It's the desired JQuery Object to know its parent node</td>
</tr>
</table>

#### getSiblings($node)
This method returns you the sibling nodes of the specified node.
<table>
<tr>
<th>Name</th>
<th>Type</th>
<th>Required</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td>$node</td>
<td>JQuery Object</td>
<td>Yes</td>
<td></td>
<td>It's the desired JQuery Object to know its sibling nodes</td>
</tr>
</table>

#### getChildren($node)
This method returns you the child nodes of the specified node.
<table>
<tr>
<th>Name</th>
<th>Type</th>
<th>Required</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td>$node</td>
<td>JQuery Object</td>
<td>Yes</td>
<td></td>
<td>It's the desired JQuery Object to know its child nodes</td>
</tr>
</table>

#### setChartScale($chart, newScale)
This method helps you set the specified chart with new scale.
<table>
Expand Down
9 changes: 3 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "orgchart",
"version": "3.1.1",
"version": "3.1.2",
"description": "Simple and direct organization chart(tree-like hierarchy) plugin based on pure DOM and jQuery.",
"main": "./dist/js/jquery.orgchart.min.js",
"style": [
"./dist/css/jquery.orgchart.min.css"
],
"scripts": {
"test": "gulp test",
"unit-tests": "gulp unit-tests",
"build": "gulp build",
"start": "gulp serve"
},
Expand Down
34 changes: 33 additions & 1 deletion test/unit/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ describe('orgchart -- unit tests', function () {

it('getRelatedNodes()', function () {
oc.getRelatedNodes().should.deep.equal($());
oc.getRelatedNodes($('td:first'), 'children').should.deep.equal($());
oc.getRelatedNodes({}, 'children').should.deep.equal($());
oc.getRelatedNodes($('.hierarchy:first'), 'children').should.deep.equal($());
oc.getRelatedNodes($('.node:first'), 'child').should.deep.equal($());

oc.getRelatedNodes($laolao, 'parent').should.deep.equal($());
Expand All @@ -196,6 +197,37 @@ describe('orgchart -- unit tests', function () {
oc.getRelatedNodes($bomiao, 'siblings').toArray().should.members([$sumiao[0], $hongmiao[0]]);
});

it('getParent()', function () {
oc.getParent().should.deep.equal($());
oc.getParent({}).should.deep.equal($());
oc.getParent($('.hierarchy:first')).should.deep.equal($());

oc.getParent($laolao).should.deep.equal($());
oc.getParent($bomiao).should.deep.equal($laolao);
oc.getParent($sandan).should.deep.equal($pangpang);
});

it('getSiblings()', function () {
oc.getSiblings().should.deep.equal($());
oc.getSiblings({}).should.deep.equal($());
oc.getSiblings($('.hierarchy:first')).should.deep.equal($());

oc.getSiblings($laolao).should.deep.equal($());
oc.getSiblings($bomiao).toArray().should.members([$sumiao[0], $hongmiao[0]]);
oc.getSiblings($sandan).should.deep.equal($());
});

it('getChildren()', function () {
oc.getChildren().should.deep.equal($());
oc.getChildren({}).should.deep.equal($());
oc.getChildren($('.hierarchy:first')).should.deep.equal($());

oc.getChildren($laolao).toArray().should.members([$bomiao[0], $sumiao[0], $hongmiao[0]]);
oc.getChildren($bomiao).should.deep.equal($());
oc.getChildren($sumiao).toArray().should.members([$tiehua[0], $heihei[0], $pangpang[0]]);
oc.getChildren($sandan).should.deep.equal($());
});

it('hideParent()', function () {
var spy = sinon.spy(oc, 'hideParent');
var spy2 = sinon.spy(oc, 'hideSiblings');
Expand Down

0 comments on commit 27c60e4

Please sign in to comment.