From 2a09ca6be10ef0e25fca93e40f423f9c1f1c2dec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E6=99=BA=E6=B4=B2?= <1543046129@qq.com> Date: Tue, 1 Mar 2022 01:32:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20bug=20=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demoV2/Layouter/BinaryTree.js | 268 +++++++------ demoV2/demo2.html | 495 +++++++++++------------- src/RegisteredShape/binaryTreeNode.ts | 196 +++++----- src/RegisteredShape/clenQueuePointer.ts | 186 ++++----- src/RegisteredShape/linkListNode.ts | 164 ++++---- src/RegisteredShape/pointer.ts | 153 ++++---- src/RegisteredShape/threeCellNode.ts | 333 ++++++++-------- src/RegisteredShape/triTreeNode.ts | 183 ++++----- src/RegisteredShape/twoCellNode.ts | 252 ++++++------ 9 files changed, 1090 insertions(+), 1140 deletions(-) diff --git a/demoV2/Layouter/BinaryTree.js b/demoV2/Layouter/BinaryTree.js index bf1e321..35aff49 100644 --- a/demoV2/Layouter/BinaryTree.js +++ b/demoV2/Layouter/BinaryTree.js @@ -1,149 +1,145 @@ SV.registerLayout('BinaryTree', { - defineOptions() { - return { - element: { - default: { - type: 'binary-tree-node', - size: [60, 30], - label: '[data]', - style: { - fill: '#b83b5e', - stroke: "#333", - cursor: 'pointer' - } - } - }, - link: { - child: { - type: 'line', - sourceAnchor: index => index === 0 ? 3 : 1, - targetAnchor: 0, - style: { - stroke: '#333', - lineAppendWidth: 6, - cursor: 'pointer', - endArrow: 'default', - startArrow: { - path: G6.Arrow.circle(2, -1), - fill: '#333' - } - } - } - }, - marker: { - external: { - type: 'pointer', - anchor: 0, - offset: 14, - style: { - fill: '#f08a5d' - }, - labelOptions: { - style: { - fill: '#000099' - } - } - } - }, - layout: { - xInterval: 40, - yInterval: 40 - }, - behavior: { - // dragNode: false - } - }; - }, + defineOptions() { + return { + element: { + default: { + type: 'binary-tree-node', + size: [60, 30], + label: '[data]', + style: { + fill: '#b83b5e', + stroke: '#333', + cursor: 'pointer', + }, + }, + }, + link: { + child: { + type: 'line', + sourceAnchor: index => (index === 0 ? 3 : 1), + targetAnchor: 0, + style: { + stroke: '#333', + lineAppendWidth: 6, + cursor: 'pointer', + endArrow: 'default', + startArrow: { + path: G6.Arrow.circle(2, -1), + fill: '#333', + }, + }, + }, + }, + marker: { + external: { + type: 'pointer', + anchor: 0, + offset: 14, + style: { + fill: '#f08a5d', + }, + labelOptions: { + style: { + fill: '#000099', + }, + }, + }, + }, + layout: { + xInterval: 40, + yInterval: 40, + }, + behavior: { + // dragNode: false + }, + }; + }, - /** - * 对子树进行递归布局 - */ - layoutItem(node, parent, index, layoutOptions) { - // 次双亲不进行布局 - if (!node) { - return null; + /** + * 对子树进行递归布局 + */ + layoutItem(node, parent, index, layoutOptions) { + // 次双亲不进行布局 + if (!node) { + return null; + } + + let bound = node.getBound(), + width = bound.width, + height = bound.height, + group = new Group(node), + leftGroup = null, + rightGroup = null; + + if (node.visited) { + return null; + } + + if (node.child && node.child[0]) { + leftGroup = this.layoutItem(node.child[0], node, 0, layoutOptions); + } + + if (node.child && node.child[1]) { + rightGroup = this.layoutItem(node.child[1], node, 1, layoutOptions); + } + + // 处理左右子树相交问题 + if (leftGroup && rightGroup) { + let intersection = Bound.intersect(leftGroup.getBound(), rightGroup.getBound()), + move = 0; + + if (intersection && intersection.width > 0) { + move = (intersection.width + layoutOptions.xInterval) / 2; + leftGroup.translate(-move, 0); + rightGroup.translate(move, 0); + } + } + + if (leftGroup) { + let leftBound = leftGroup.getBound(); + + node.set('y', leftBound.y - layoutOptions.yInterval - height); + node.set('x', leftBound.x + leftBound.width + layoutOptions.xInterval / 2 - width); } - let bound = node.getBound(), - width = bound.width, - height = bound.height, - group = new Group(node); + if(rightGroup) { + let rightBound = rightGroup.getBound(); - if (node.visited) { - return; + node.set('y', rightBound.y - layoutOptions.yInterval - height); + node.set('x', rightBound.x - layoutOptions.xInterval / 2 - width); } + node.visited = true; - if (parent) { - node.set('y', parent.get('y') + layoutOptions.yInterval + height); + if (leftGroup) { + group.add(leftGroup); + } - // 左节点 - if (index === 0) { - node.set('x', parent.get('x') - layoutOptions.xInterval / 2 - width / 2); - } + if (rightGroup) { + group.add(rightGroup); + } - // 右结点 - if (index === 1) { - node.set('x', parent.get('x') + layoutOptions.xInterval / 2 + width / 2); - } - } + return group; + }, - node.visited = true; - - if (node.child && (node.child[0] || node.child[1])) { - let leftChild = node.child[0], - rightChild = node.child[1], - leftGroup = this.layoutItem(leftChild, node, 0, layoutOptions), - rightGroup = this.layoutItem(rightChild, node, 1, layoutOptions), - intersection = null, - move = 0; - - // 处理左右子树相交问题 - if (leftGroup && rightGroup) { - intersection = Bound.intersect(leftGroup.getBound(), rightGroup.getBound()); - move = 0; - - if (intersection && intersection.width > 0) { - move = (intersection.width + layoutOptions.xInterval) / 2; - leftGroup.translate(-move, 0); - rightGroup.translate(move, 0); - } - } - - if (leftGroup) { - group.add(leftGroup); - } - - if (rightGroup) { - group.add(rightGroup) - } - } - - return group; - }, - - /** - * 布局函数 - * @param {*} elements - * @param {*} layoutOptions - */ - layout(elements, layoutOptions) { - let root = elements[0]; - this.layoutItem(root, null, -1, layoutOptions); - } + /** + * 布局函数 + * @param {*} elements + * @param {*} layoutOptions + */ + layout(elements, layoutOptions) { + let root = elements[0]; + this.layoutItem(root, null, -1, layoutOptions); + }, }); - - - - -[{ - "id": 6385328, - "data": "", - "external": [ - "L" - ], - "root": true, - "after": null, - "next": null -}] \ No newline at end of file +[ + { + id: 6385328, + data: '', + external: ['L'], + root: true, + after: null, + next: null, + }, +]; diff --git a/demoV2/demo2.html b/demoV2/demo2.html index a80936e..69c7959 100644 --- a/demoV2/demo2.html +++ b/demoV2/demo2.html @@ -1,291 +1,250 @@ +
+ + +