Merge branch 'hotfix/cjc' into 'main'

修改外部指针id,增加自定义的三叉树

See merge request phenomLi/StructV2!15
This commit is contained in:
chen jiancheng 2022-03-17 07:15:47 +00:00
commit 1c36865547
6 changed files with 469 additions and 215 deletions

View File

@ -4,93 +4,97 @@
SV.registerLayout('TriTree', { SV.registerLayout('TriTree', {
defineOptions() { defineOptions() {
return { return {
/** node: {
* 结点
*/
element: {
default: { default: {
type: 'tri-tree-node', type: 'tri-tree-node',
size: [60, 30], size: [60, 30],
label: '[data]', label: '[data]',
style: { style: {
fill: '#ff2e63', fill: '#95e1d3',
stroke: "#333", stroke: '#333',
cursor: 'pointer' cursor: 'pointer',
backgroundFill: '#eee'
},
labelOptions: {
style: { fontSize: 16 }
} }
} }
}, },
/**
* 箭头
*/
link: { link: {
child: { child: {
type: 'line',
sourceAnchor: index => index, sourceAnchor: index => index,
targetAnchor: 3, targetAnchor: 3,
type: 'line',
style: { style: {
stroke: '#333', stroke: '#333',
//边的响应范围 lineAppendWidth: 10,
lineAppendWidth: 6, lineWidth: 1.6,
cursor: 'pointer',
endArrow: 'default', endArrow: 'default',
startArrow: { startArrow: {
//参数:半径、偏移量
path: G6.Arrow.circle(2, -1), path: G6.Arrow.circle(2, -1),
fill: '#333' fill: '#333'
} }
} }
}, },
parent: { r_parent: {
type: 'line', type: 'quadratic',
sourceAnchor: 4,
targetAnchor: 5,
curveOffset: -20,
style: {
stroke: '#999',
lineAppendWidth: 10,
lineWidth: 1.6,
endArrow: 'default',
startArrow: {
path: G6.Arrow.circle(2, -1),
fill: '#999'
}
}
},
l_parent: {
type: 'quadratic',
sourceAnchor: 4, sourceAnchor: 4,
targetAnchor: 2, targetAnchor: 2,
curveOffset: 20,
style: { style: {
stroke: '#A9A9A9', stroke: '#999',
//边的响应范围 lineAppendWidth: 10,
lineAppendWidth: 6, lineWidth: 1.6,
cursor: 'pointer',
endArrow: 'default', endArrow: 'default',
startArrow: { startArrow: {
//参数:半径、偏移量
path: G6.Arrow.circle(2, -1), path: G6.Arrow.circle(2, -1),
fill: '#333' fill: '#999'
} }
} }
}, },
}, },
/**
* 指针
*/
marker: { marker: {
external: { external: {
type: "pointer", type: 'pointer',
anchor: 3, anchor: 3,
offset: 14, offset: 14,
labelOffset: 2,
style: { style: {
fill: '#f08a5d' fill: '#f08a5d'
}, },
labelOptions: { labelOptions: {
style: { style: {
// stroke: fontSize: 15,
fill: '#999'
} }
} }
} }
}, },
/** addressLabel: {
* 布局 style: {
*/ fill: '#999'
}
},
layout: { layout: {
xInterval: 40, xInterval: 40,
yInterval: 40, yInterval: 40,
}, }
/**
* 动画
*/
//animation: {
// enable: true,
// duration: 750,
// timingFunction: 'easePolyOut'
//}
}; };
}, },

View File

@ -1,16 +1,19 @@
const SOURCES_DATA = [{ const SOURCES_DATA = [{
"BinaryTree0": { "TriTree0": {
"data": [{ "data": [{
"external": [ "external": [
"T1" "T"
],
"parent": [
"0x0"
], ],
"child": [ "child": [
"0x617ee0", "0xb07ee0",
"0x617f10" "0xb07f10"
], ],
"id": "0x617eb0", "id": "0xb07eb0",
"name": "T1", "name": "T",
"data": "Z", "data": "A",
"root": true, "root": true,
"type": "default" "type": "default"
}, },
@ -19,19 +22,57 @@ const SOURCES_DATA = [{
"0x0", "0x0",
"0x0" "0x0"
], ],
"id": "0x617ee0", "id": "0xb07ee0",
"name": "T1->lchild", "name": "T->lchild",
"data": "D", "data": "B",
"type": "default" "type": "default",
"l_parent": [
"0x0"
],
"external": [
"T1"
]
}, },
{ {
"child": [ "child": [
"0x617f70", "0x0",
"0x617f40" "0x0"
], ],
"id": "0x617f10", "id": "0xb07f10",
"name": "T1->rchild", "name": "T->rchild",
"data": "C", "data": "C",
"type": "default",
"r_parent": [
"0x0"
],
"external": [
"T2"
]
}
],
"layouter": "TriTree"
},
"handleUpdate": {
"isEnterFunction": false,
"isFirstDebug": false
}
}, {
"TriTree0": {
"data": [{
"external": [
"T"
],
"parent": [
"0x0"
],
"child": [
"0xb07ee0",
"0xb07f10"
],
"id": "0xb07eb0",
"name": "T",
"data": "A",
"root": true,
"type": "default" "type": "default"
}, },
{ {
@ -39,39 +80,93 @@ const SOURCES_DATA = [{
"0x0", "0x0",
"0x0" "0x0"
], ],
"id": "0x617f70", "id": "0xb07ee0",
"name": "(T1->rchild)->lchild", "name": "T->lchild",
"data": "B",
"type": "default",
"l_parent": [
"0xb07eb0"
],
"external": [
"T1"
]
},
{
"child": [
"0x0",
"0x0"
],
"id": "0xb07f10",
"name": "T->rchild",
"data": "C",
"type": "default",
"r_parent": [
"0x0"
],
"external": [
"T2"
]
}
],
"layouter": "TriTree"
},
"handleUpdate": {
"isEnterFunction": false,
"isFirstDebug": false
}
}, {
"TriTree0": {
"data": [{
"external": [
"T"
],
"parent": [
"0x0"
],
"child": [
"0xb07ee0",
"0xb07f10"
],
"id": "0xb07eb0",
"name": "T",
"data": "A", "data": "A",
"root": true,
"type": "default" "type": "default"
}, },
{ {
"child": [ "child": [
"0x0", "0x0",
"0x617fa0" "0x0"
], ],
"id": "0x617f40", "id": "0xb07ee0",
"name": "(T1->rchild)->rchild", "name": "T->lchild",
"data": "B", "data": "B",
"type": "default", "type": "default",
"l_parent": [
"0xb07eb0"
],
"external": [ "external": [
"t" "T1"
] ]
}, },
{ {
"child": [ "child": [
"0x0", "0x0",
"0x617f40" "0x0"
], ],
"id": "0x617fa0", "id": "0xb07f10",
"name": "((T1->rchild)->rchild)->rchild", "name": "T->rchild",
"data": "E", "data": "C",
"type": "default", "type": "default",
"r_parent": [
"0xb07eb0"
],
"external": [ "external": [
"r" "T2"
] ]
} }
], ],
"layouter": "BinaryTree" "layouter": "TriTree"
}, },
"handleUpdate": { "handleUpdate": {
"isEnterFunction": false, "isEnterFunction": false,

View File

@ -1,5 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
@ -72,6 +73,7 @@
</script> </script>
<script src="./Layouter/LinkList.js"></script> <script src="./Layouter/LinkList.js"></script>
<script src="./Layouter/BinaryTree.js"></script> <script src="./Layouter/BinaryTree.js"></script>
<script src="./Layouter/TriTree.js"></script>
<script src="./Layouter/Stack.js"></script> <script src="./Layouter/Stack.js"></script>
<script src="./Layouter/LinkQueue.js"></script> <script src="./Layouter/LinkQueue.js"></script>
<script src="./Layouter/GeneralizedList.js"></script> <script src="./Layouter/GeneralizedList.js"></script>
@ -148,4 +150,5 @@
}); });
</script> </script>
</body> </body>
</html> </html>

View File

@ -49,6 +49,7 @@ export class ModelConstructor {
const layoutGroupTable = new Map<string, LayoutGroup>(), const layoutGroupTable = new Map<string, LayoutGroup>(),
layoutMap: { [key: string]: LayoutCreator } = SV.registeredLayout; layoutMap: { [key: string]: LayoutCreator } = SV.registeredLayout;
Object.keys(sources).forEach(group => { Object.keys(sources).forEach(group => {
let sourceGroup = sources[group], let sourceGroup = sources[group],
layout = sourceGroup.layouter, layout = sourceGroup.layouter,
@ -301,7 +302,8 @@ export class ModelConstructor {
// 若没有指针字段的结点则跳过 // 若没有指针字段的结点则跳过
if (!markerData) continue; if (!markerData) continue;
let id = `${group}[${name}(${Array.isArray(markerData) ? markerData.join('-') : markerData})]`, let id = `[${name}(${Array.isArray(markerData) ? markerData.join('-') : markerData})]`,
marker = new SVMarker(id, name, group, layout, markerData, node, markerOptions[name]); marker = new SVMarker(id, name, group, layout, markerData, node, markerOptions[name]);
markerList.push(marker); markerList.push(marker);
@ -349,6 +351,7 @@ export class ModelConstructor {
): SVNode { ): SVNode {
let label: string | string[] = this.resolveNodeLabel(options.label, sourceNode), let label: string | string[] = this.resolveNodeLabel(options.label, sourceNode),
id = `${sourceNodeType}(${sourceNode.id.toString()})`, id = `${sourceNodeType}(${sourceNode.id.toString()})`,
node = new SVNode(id, sourceNodeType, group, layout, sourceNode, label, options); node = new SVNode(id, sourceNodeType, group, layout, sourceNode, label, options);
if (node.freed) { if (node.freed) {

View File

@ -0,0 +1,146 @@
import { Util } from '../Common/util';
export default Util.registerShape(
'tri-tree-node',
{
draw(cfg, group) {
cfg.size = cfg.size;
const width = cfg.size[0],
height = cfg.size[1];
const wrapperRect = group.addShape('rect', {
attrs: {
x: width / 2,
y: height / 2,
width: width,
height: height,
stroke: cfg.style.stroke || '#333',
cursor: cfg.style.cursor,
fill: '#eee'
},
name: 'wrapper'
});
group.addShape('rect', {
attrs: {
x: width / 4 + width / 2,
y: height / 2,
width: width / 2,
height: height / 4,
fill: '#eee',
stroke: cfg.style.stroke || '#333',
cursor: cfg.style.cursor
},
name: 'top',
draggable: true
});
group.addShape('rect', {
attrs: {
x: width / 4 + width / 2,
y: height / 2 + height / 4,
width: width / 2,
height: height / 4 * 3,
fill: cfg.color || cfg.style.fill,
stroke: cfg.style.stroke || '#333',
cursor: cfg.style.cursor
},
name: 'bottom',
draggable: true
});
const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
if (cfg.label) {
group.addShape('text', {
attrs: {
x: width, // 居中
y: height + height / 8,
textAlign: 'center',
textBaseline: 'middle',
text: cfg.label,
fill: style.fill || '#000',
fontSize: style.fontSize || 16,
cursor: cfg.style.cursor
},
name: 'text',
draggable: true
});
}
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";
if (isparentEmpty) {
{
group.addShape('text', {
attrs: {
x: width, // 居中
y: height / 4 * 3,
textAlign: 'center',
textBaseline: 'middle',
text: "^",
fill: style.fill || '#000',
fontSize: style.fontSize || 14,
cursor: cfg.style.cursor
},
name: 'parent',
draggable: true
});
}
}
//节点没有左孩子节点时
if (isLeftEmpty) {
group.addShape('text', {
attrs: {
x: width * (5 / 8),
y: height * (8 / 7),
textAlign: 'center',
textBaseline: 'middle',
text: '^',
fill: style.fill || '#000',
fontSize: 16,
cursor: cfg.style.cursor,
},
name: 'text',
draggable: true,
});
}
//节点没有右孩子节点时
if (isRightEmpty) {
group.addShape('text', {
attrs: {
x: width * (11 / 8),
y: height * (8 / 7),
textAlign: 'center',
textBaseline: 'middle',
text: '^',
fill: style.fill || '#000',
fontSize: 16,
cursor: cfg.style.cursor,
},
name: 'text',
draggable: true,
});
}
return wrapperRect;
},
getAnchorPoints() {
return [
[0.125, 0.5],
[0.875, 0.5],
[0.4, 1],
[0.5, 0],
[0.5, 0.125],
[0.6, 1],
];
},
}
);

View File

@ -13,6 +13,7 @@ import G6 from '@antv/g6';
import Pointer from "./RegisteredShape/pointer"; import Pointer from "./RegisteredShape/pointer";
import LinkListNode from "./RegisteredShape/linkListNode"; import LinkListNode from "./RegisteredShape/linkListNode";
import BinaryTreeNode from "./RegisteredShape/binaryTreeNode"; import BinaryTreeNode from "./RegisteredShape/binaryTreeNode";
import TriTreeNode from "./RegisteredShape/triTreeNode";
import CLenQueuePointer from "./RegisteredShape/clenQueuePointer"; import CLenQueuePointer from "./RegisteredShape/clenQueuePointer";
import TwoCellNode from "./RegisteredShape/twoCellNode"; import TwoCellNode from "./RegisteredShape/twoCellNode";
import ThreeCellNode from "./RegisteredShape/threeCellNode"; import ThreeCellNode from "./RegisteredShape/threeCellNode";
@ -65,6 +66,7 @@ SV.registeredShape = [
Pointer, Pointer,
LinkListNode, LinkListNode,
BinaryTreeNode, BinaryTreeNode,
TriTreeNode,
TwoCellNode, TwoCellNode,
ThreeCellNode, ThreeCellNode,
Cursor, Cursor,
@ -92,5 +94,6 @@ SV.registerLayout = function(name: string, layoutCreator: LayoutCreator) {
} }
SV.registeredLayout[name] = layoutCreator; SV.registeredLayout[name] = layoutCreator;
}; };