From 27c60e4073374eafdd7e0d9d16ccfb227413b6f5 Mon Sep 17 00:00:00 2001 From: Xuebin Dong Date: Sat, 12 Nov 2022 18:54:41 +0800 Subject: [PATCH] expose methods -- getParent(),getSiblings(),getChildren() --- README.md | 57 ++++++++++++++++++++++++++++++++++++++++++++++ package-lock.json | 9 +++----- package.json | 3 ++- test/unit/tests.js | 34 ++++++++++++++++++++++++++- 4 files changed, 95 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 900c4482..86317353 100644 --- a/README.md +++ b/README.md @@ -685,6 +685,63 @@ This method returns you the nodes related to the specified node. +#### getParent($node) +This method returns you the parent node of the specified node. + + + + + + + + + + + + + + + +
NameTypeRequiredDefaultDescription
$nodeJQuery ObjectYesIt's the desired JQuery Object to know its parent node
+ +#### getSiblings($node) +This method returns you the sibling nodes of the specified node. + + + + + + + + + + + + + + + +
NameTypeRequiredDefaultDescription
$nodeJQuery ObjectYesIt's the desired JQuery Object to know its sibling nodes
+ +#### getChildren($node) +This method returns you the child nodes of the specified node. + + + + + + + + + + + + + + + +
NameTypeRequiredDefaultDescription
$nodeJQuery ObjectYesIt's the desired JQuery Object to know its child nodes
+ #### setChartScale($chart, newScale) This method helps you set the specified chart with new scale. diff --git a/package-lock.json b/package-lock.json index 88597375..eb3efa8c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "orgchart", - "version": "3.1.1", + "version": "3.1.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -5995,7 +5995,6 @@ "version": "2.3.5", "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.5.tgz", "integrity": "sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA==", - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -6213,8 +6212,7 @@ "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "optional": true + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, "safer-buffer": { "version": "2.1.2", @@ -6317,8 +6315,7 @@ "yallist": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz", - "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==", - "optional": true + "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==" } } }, diff --git a/package.json b/package.json index 52ffafa0..8968e111 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "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": [ @@ -8,6 +8,7 @@ ], "scripts": { "test": "gulp test", + "unit-tests": "gulp unit-tests", "build": "gulp build", "start": "gulp serve" }, diff --git a/test/unit/tests.js b/test/unit/tests.js index 9bfd69f0..a191ae34 100644 --- a/test/unit/tests.js +++ b/test/unit/tests.js @@ -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($()); @@ -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');