From d4066249c7b21be33c6da42e7a7614d11a7e8f93 Mon Sep 17 00:00:00 2001 From: cjc <431909623@qq.com> Date: Fri, 18 Mar 2022 20:37:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8D=E5=90=8Cgroup?= =?UTF-8?q?=E7=9A=84=E7=BB=93=E7=82=B9=E4=B8=8D=E8=83=BD=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/Layouter/TriTree.js | 15 ++ demo/data.js | 211 ++++++++++++++++++++++------- src/Model/modelConstructor.ts | 25 +++- src/RegisteredShape/triTreeNode.ts | 12 +- 4 files changed, 207 insertions(+), 56 deletions(-) diff --git a/demo/Layouter/TriTree.js b/demo/Layouter/TriTree.js index e49cc8b..1fe7d9d 100644 --- a/demo/Layouter/TriTree.js +++ b/demo/Layouter/TriTree.js @@ -36,6 +36,21 @@ SV.registerLayout('TriTree', { } } }, + parent: { + type: 'line', + sourceAnchor: 4, + targetAnchor: 6, + style: { + stroke: '#999', + lineAppendWidth: 10, + lineWidth: 1.6, + endArrow: 'default', + startArrow: { + path: G6.Arrow.circle(2, -1), + fill: '#999' + } + } + }, r_parent: { type: 'quadratic', sourceAnchor: 4, diff --git a/demo/data.js b/demo/data.js index 313d1b2..2804eef 100644 --- a/demo/data.js +++ b/demo/data.js @@ -8,10 +8,10 @@ const SOURCES_DATA = [{ "0x0" ], "child": [ - "0xb07ee0", - "0xb07f10" + "0xfd9ee0", + "0xfd9f10" ], - "id": "0xb07eb0", + "id": "0xfd9eb0", "name": "T", "data": "A", "root": true, @@ -22,12 +22,12 @@ const SOURCES_DATA = [{ "0x0", "0x0" ], - "id": "0xb07ee0", + "id": "0xfd9ee0", "name": "T->lchild", "data": "B", "type": "default", "l_parent": [ - "0x0" + "0xfd9eb0" ], "external": [ "T1" @@ -38,12 +38,12 @@ const SOURCES_DATA = [{ "0x0", "0x0" ], - "id": "0xb07f10", + "id": "0xfd9f10", "name": "T->rchild", "data": "C", "type": "default", "r_parent": [ - "0x0" + "0xfd9eb0" ], "external": [ "T2" @@ -52,6 +52,144 @@ const SOURCES_DATA = [{ ], "layouter": "TriTree" }, + "TriTree3": { + "data": [{ + "external": [ + "T3" + ], + "parent": [ + "0x0" + ], + "child": [ + "0x0", + "0x0" + ], + "id": "0xfd9f40", + "name": "T3", + "data": "D", + "root": true, + "type": "default" + }], + "layouter": "TriTree" + }, + "TriTree4": { + "data": [{ + "external": [ + "T4" + ], + "parent": [ + "0x0" + ], + "child": [ + "0x0", + "0x0" + ], + "id": "0xfd9f70", + "name": "T4", + "data": "E", + "root": true, + "type": "default" + }], + "layouter": "TriTree" + }, + "handleUpdate": { + "isEnterFunction": true, + "isFirstDebug": true + } +}, { + "TriTree0": { + "data": [{ + "external": [ + "T" + ], + "parent": [ + "0x0" + ], + "child": [ + "0xfd9ee0", + "0xfd9f10" + ], + "id": "0xfd9eb0", + "name": "T", + "data": "A", + "root": true, + "type": "default" + }, + { + "child": [ + "0x0", + "0x0" + ], + "id": "0xfd9ee0", + "name": "T->lchild", + "data": "B", + "type": "default", + "l_parent": [ + "0xfd9eb0" + ], + "external": [ + "T1" + ] + }, + { + "child": [ + "0x0", + "0x0" + ], + "id": "0xfd9f10", + "name": "T->rchild", + "data": "C", + "type": "default", + "r_parent": [ + "0xfd9eb0" + ], + "external": [ + "T2" + ] + } + ], + "layouter": "TriTree" + }, + "TriTree3": { + "data": [{ + "external": [ + "T3" + ], + "parent": [ + "0x0" + ], + "child": [ + "0x0", + "0x0" + ], + "id": "0xfd9f40", + "name": "T3", + "data": "D", + "root": true, + "type": "default" + }], + "layouter": "TriTree" + }, + "TriTree4": { + "data": [{ + "external": [ + "T4" + ], + "parent": [ + "0xfd9f40" + ], + "child": [ + "0x0", + "0x0" + ], + "id": "0xfd9f70", + "name": "T4", + "data": "E", + "root": true, + "type": "default" + }], + "layouter": "TriTree" + }, "handleUpdate": { "isEnterFunction": false, "isFirstDebug": false @@ -66,10 +204,10 @@ const SOURCES_DATA = [{ "0x0" ], "child": [ - "0xb07ee0", - "0xb07f10" + "0xfd9ee0", + "0xfd9f10" ], - "id": "0xb07eb0", + "id": "0xfd9eb0", "name": "T", "data": "A", "root": true, @@ -80,12 +218,12 @@ const SOURCES_DATA = [{ "0x0", "0x0" ], - "id": "0xb07ee0", + "id": "0xfd9ee0", "name": "T->lchild", "data": "B", "type": "default", "l_parent": [ - "0xb07eb0" + "0xfd9eb0" ], "external": [ "T1" @@ -96,12 +234,12 @@ const SOURCES_DATA = [{ "0x0", "0x0" ], - "id": "0xb07f10", + "id": "0xfd9f10", "name": "T->rchild", "data": "C", "type": "default", "r_parent": [ - "0x0" + "0xfd9eb0" ], "external": [ "T2" @@ -110,26 +248,21 @@ const SOURCES_DATA = [{ ], "layouter": "TriTree" }, - "handleUpdate": { - "isEnterFunction": false, - "isFirstDebug": false - } -}, { - "TriTree0": { + "TriTree3": { "data": [{ "external": [ - "T" + "T3" ], "parent": [ "0x0" ], "child": [ - "0xb07ee0", - "0xb07f10" + "0xfd9f70", + "0x0" ], - "id": "0xb07eb0", - "name": "T", - "data": "A", + "id": "0xfd9f40", + "name": "T3", + "data": "D", "root": true, "type": "default" }, @@ -138,31 +271,15 @@ const SOURCES_DATA = [{ "0x0", "0x0" ], - "id": "0xb07ee0", - "name": "T->lchild", - "data": "B", + "id": "0xfd9f70", + "name": "T3->lchild", + "data": "E", "type": "default", "l_parent": [ - "0xb07eb0" + "0xfd9f40" ], "external": [ - "T1" - ] - }, - { - "child": [ - "0x0", - "0x0" - ], - "id": "0xb07f10", - "name": "T->rchild", - "data": "C", - "type": "default", - "r_parent": [ - "0xb07eb0" - ], - "external": [ - "T2" + "T4" ] } ], diff --git a/src/Model/modelConstructor.ts b/src/Model/modelConstructor.ts index 33b4952..5f516a4 100644 --- a/src/Model/modelConstructor.ts +++ b/src/Model/modelConstructor.ts @@ -434,7 +434,7 @@ export class ModelConstructor { sourceNodeType = info.pop(); targetGroupName = info.pop(); } else { - let field = info.pop(); + let field = info.pop(); if (layoutGroupTable.get(targetGroupName).node.find(item => item.sourceType === field)) { sourceNodeType = field; } else if (layoutGroupTable.has(field)) { @@ -444,14 +444,25 @@ export class ModelConstructor { } } - nodeList = layoutGroupTable.get(targetGroupName).node.filter(item => item.sourceType === sourceNodeType); + // 为了可以连接到不同group的结点 + for (let layoutGroup of layoutGroupTable.values()) { + nodeList = layoutGroup.node.filter(item => item.sourceType === sourceNodeType); + if (nodeList === undefined) { + continue; + } + targetNode = nodeList.find(item => item.sourceId === targetId); + if (targetNode) { + break; + } + } + // nodeList = layoutGroupTable.get(targetGroupName).node.filter(item => item.sourceType === sourceNodeType); - // 若目标node不存在,返回null - if (nodeList === undefined) { - return null; - } + // // 若目标node不存在,返回null + // if (nodeList === undefined) { + // return null; + // } - targetNode = nodeList.find(item => item.sourceId === targetId); + // targetNode = nodeList.find(item => item.sourceId === targetId); return targetNode || null; } diff --git a/src/RegisteredShape/triTreeNode.ts b/src/RegisteredShape/triTreeNode.ts index 9f73bda..be26146 100644 --- a/src/RegisteredShape/triTreeNode.ts +++ b/src/RegisteredShape/triTreeNode.ts @@ -67,12 +67,19 @@ export default Util.registerShape( draggable: true }); } + let parent = cfg.parent || cfg.l_parent || cfg.r_parent; const isLeftEmpty = !cfg.child || cfg.child[0] === undefined || cfg.child[0] === undefined || cfg.child[0] == '0x0', isRightEmpty = !cfg.child || cfg.child[1] === undefined || cfg.child[1] === undefined || cfg.child[1] == '0x0', - isparentEmpty = cfg.parent == "0x0" || cfg.l_parent == "0x0" || cfg.r_parent == "0x0"; - + isparentEmpty = parent[0] == "0x0"; + + + // console.log(cfg.id); + // console.log(parent); + + // console.log(isparentEmpty); + if (isparentEmpty) { { @@ -140,6 +147,7 @@ export default Util.registerShape( [0.5, 0], [0.5, 0.125], [0.6, 1], + [0.5,1] ]; }, }