fix: bug 修复

This commit is contained in:
黎智洲 2022-03-01 01:32:28 +08:00
parent 97749ec35e
commit 2a09ca6be1
9 changed files with 1090 additions and 1140 deletions

View File

@ -8,15 +8,15 @@ SV.registerLayout('BinaryTree', {
label: '[data]', label: '[data]',
style: { style: {
fill: '#b83b5e', fill: '#b83b5e',
stroke: "#333", stroke: '#333',
cursor: 'pointer' cursor: 'pointer',
} },
} },
}, },
link: { link: {
child: { child: {
type: 'line', type: 'line',
sourceAnchor: index => index === 0 ? 3 : 1, sourceAnchor: index => (index === 0 ? 3 : 1),
targetAnchor: 0, targetAnchor: 0,
style: { style: {
stroke: '#333', stroke: '#333',
@ -25,10 +25,10 @@ SV.registerLayout('BinaryTree', {
endArrow: 'default', endArrow: 'default',
startArrow: { startArrow: {
path: G6.Arrow.circle(2, -1), path: G6.Arrow.circle(2, -1),
fill: '#333' fill: '#333',
} },
} },
} },
}, },
marker: { marker: {
external: { external: {
@ -36,22 +36,22 @@ SV.registerLayout('BinaryTree', {
anchor: 0, anchor: 0,
offset: 14, offset: 14,
style: { style: {
fill: '#f08a5d' fill: '#f08a5d',
}, },
labelOptions: { labelOptions: {
style: { style: {
fill: '#000099' fill: '#000099',
} },
} },
} },
}, },
layout: { layout: {
xInterval: 40, xInterval: 40,
yInterval: 40 yInterval: 40,
}, },
behavior: { behavior: {
// dragNode: false // dragNode: false
} },
}; };
}, },
@ -67,40 +67,25 @@ SV.registerLayout('BinaryTree', {
let bound = node.getBound(), let bound = node.getBound(),
width = bound.width, width = bound.width,
height = bound.height, height = bound.height,
group = new Group(node); group = new Group(node),
leftGroup = null,
rightGroup = null;
if (node.visited) { if (node.visited) {
return; return null;
} }
if (node.child && node.child[0]) {
if (parent) { leftGroup = this.layoutItem(node.child[0], node, 0, layoutOptions);
node.set('y', parent.get('y') + layoutOptions.yInterval + height);
// 左节点
if (index === 0) {
node.set('x', parent.get('x') - layoutOptions.xInterval / 2 - width / 2);
} }
// 右结点 if (node.child && node.child[1]) {
if (index === 1) { rightGroup = this.layoutItem(node.child[1], node, 1, layoutOptions);
node.set('x', parent.get('x') + layoutOptions.xInterval / 2 + width / 2);
} }
}
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) { if (leftGroup && rightGroup) {
intersection = Bound.intersect(leftGroup.getBound(), rightGroup.getBound()); let intersection = Bound.intersect(leftGroup.getBound(), rightGroup.getBound()),
move = 0; move = 0;
if (intersection && intersection.width > 0) { if (intersection && intersection.width > 0) {
@ -110,13 +95,28 @@ SV.registerLayout('BinaryTree', {
} }
} }
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);
}
if(rightGroup) {
let rightBound = rightGroup.getBound();
node.set('y', rightBound.y - layoutOptions.yInterval - height);
node.set('x', rightBound.x - layoutOptions.xInterval / 2 - width);
}
node.visited = true;
if (leftGroup) { if (leftGroup) {
group.add(leftGroup); group.add(leftGroup);
} }
if (rightGroup) { if (rightGroup) {
group.add(rightGroup) group.add(rightGroup);
}
} }
return group; return group;
@ -130,20 +130,16 @@ SV.registerLayout('BinaryTree', {
layout(elements, layoutOptions) { layout(elements, layoutOptions) {
let root = elements[0]; let root = elements[0];
this.layoutItem(root, null, -1, layoutOptions); this.layoutItem(root, null, -1, layoutOptions);
} },
}); });
[
{
id: 6385328,
data: '',
[{ external: ['L'],
"id": 6385328, root: true,
"data": "", after: null,
"external": [ next: null,
"L" },
], ];
"root": true,
"after": null,
"next": null
}]

View File

@ -1,7 +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" />
<title>DEMO</title> <title>DEMO</title>
@ -43,13 +42,13 @@
transition: opacity 0.75s ease-in-out; transition: opacity 0.75s ease-in-out;
} }
#leak>span { #leak > span {
color: #000; color: #000;
} }
</style> </style>
</head> </head>
<body> <body>
<div class="container" id="container"> <div class="container" id="container">
<div id="leak"> <div id="leak">
<span>泄漏区</span> <span>泄漏区</span>
@ -94,144 +93,105 @@
}, },
}); });
let data = [{ let data = [
"BinaryTree0": { {
"data": [{ BinaryTree0: {
"external": [ data: [
"T" {
], external: ['T', 'p'],
"child": [ child: ['0x615f40', '0x0'],
"0x616060", id: '0x615f10',
"0x615f40" name: 'T',
], data: 'W',
"id": "0x615f10", root: true,
"name": "T", type: 'default',
"data": "F",
"root": true,
"type": "default"
}, {
"child": [
"0x0",
"0x616090"
],
"id": "0x616060",
"name": "T->lchild",
"data": "A",
"type": "default"
}, {
"child": [
"0x6160c0",
"0x0"
],
"id": "0x616090",
"name": "(T->lchild)->rchild",
"data": "E",
"type": "default"
}, {
"child": [
"0x0",
"0x0"
],
"id": "0x6160c0",
"name": "((T->lchild)->rchild)->lchild",
"data": "D",
"type": "default"
}, {
"child": [
"0x615f70",
"0x615fd0"
],
"id": "0x615f40",
"name": "T->rchild",
"data": "U",
"type": "default"
}, {
"child": [
"0x615fa0",
"0x616000"
],
"id": "0x615f70",
"name": "(T->rchild)->lchild",
"data": "S",
"type": "default"
}, {
"child": [
"0x0",
"0x0"
],
"id": "0x615fa0",
"name": "((T->rchild)->lchild)->lchild",
"data": "R",
"type": "default"
}, {
"child": [
"0x0",
"0x0"
],
"id": "0x616000",
"name": "((T->rchild)->lchild)->rchild",
"data": "T",
"type": "default"
}, {
"child": [
"0x0",
"0x616030"
],
"id": "0x615fd0",
"name": "(T->rchild)->rchild",
"data": "V",
"type": "default"
}, {
"child": [
"0x0",
"0x0"
],
"id": "0x616030",
"name": "((T->rchild)->rchild)->rchild",
"data": "X",
"type": "default"
}],
"layouter": "BinaryTree"
}, },
"isEnterFunction": true {
}, { child: ['0x615f70', '0x615fa0'],
"BinaryTree0": { id: '0x615f40',
"data": [{ name: 'T->lchild',
"external": [ data: 'Q',
"T" type: 'default',
],
"child": [
"0x0",
"0x616090"
],
"id": "0x616060",
"name": "T",
"data": "A",
"root": true,
"type": "default"
}, {
"child": [
"0x6160c0",
"0x0"
],
"id": "0x616090",
"name": "T->rchild",
"data": "E",
"type": "default"
}, {
"child": [
"0x0",
"0x0"
],
"id": "0x6160c0",
"name": "(T->rchild)->lchild",
"data": "D",
"type": "default"
}],
"layouter": "BinaryTree"
}, },
"isEnterFunction": true {
}]; child: ['0x0', '0x615fd0'],
id: '0x615f70',
name: '(T->lchild)->lchild',
data: 'A',
type: 'default',
},
{
child: ['0x0', '0x0'],
id: '0x615fd0',
name: '((T->lchild)->lchild)->rchild',
data: 'D',
type: 'default',
},
{
child: ['0x616000', '0x616030'],
id: '0x615fa0',
name: '(T->lchild)->rchild',
data: 'U',
type: 'default',
},
{
child: ['0x0', '0x0'],
id: '0x616000',
name: '((T->lchild)->rchild)->lchild',
data: 'S',
type: 'default',
},
{
child: ['0x0', '0x0'],
id: '0x616030',
name: '((T->lchild)->rchild)->rchild',
data: 'V',
type: 'default',
},
],
layouter: 'BinaryTree',
},
isEnterFunction: false,
},
{
BinaryTree0: {
data: [
{
external: ['T', 'p'],
child: ['0x615f40', '0x0'],
id: '0x615f10',
name: 'T',
data: 'W',
root: true,
type: 'default',
},
{
child: ['0x615f70', '0x615fa0'],
id: '0x615f40',
name: 'T->lchild',
data: 'Q',
type: 'default',
},
{
child: ['0x0', '0x615fd0'],
id: '0x615f70',
name: '(T->lchild)->lchild',
data: 'A',
type: 'default',
},
{
child: ['0x0', '0x0'],
id: '0x615fd0',
name: '((T->lchild)->lchild)->rchild',
data: 'D',
type: 'default',
}
],
layouter: 'BinaryTree',
},
isEnterFunction: false,
},
];
let dataIndex = 0, let dataIndex = 0,
curData = data[dataIndex]; curData = data[dataIndex];
@ -286,6 +246,5 @@
pos.innerHTML = `${x},${y}`; pos.innerHTML = `${x},${y}`;
}); });
</script> </script>
</body> </body>
</html> </html>

View File

@ -1,8 +1,8 @@
import { Util } from '../Common/util'; import { Util } from '../Common/util';
export default Util.registerShape(
export default Util.registerShape('binary-tree-node', { 'binary-tree-node',
{
draw(cfg, group) { draw(cfg, group) {
cfg.size = cfg.size; cfg.size = cfg.size;
@ -17,9 +17,9 @@ export default Util.registerShape('binary-tree-node', {
height: height, height: height,
stroke: cfg.style.stroke || '#333', stroke: cfg.style.stroke || '#333',
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
fill: cfg.style.backgroundFill || '#eee' fill: cfg.style.backgroundFill || '#eee',
}, },
name: 'wrapper' name: 'wrapper',
}); });
group.addShape('rect', { group.addShape('rect', {
@ -30,16 +30,15 @@ export default Util.registerShape('binary-tree-node', {
height: height, height: height,
fill: cfg.style.fill, fill: cfg.style.fill,
stroke: cfg.style.stroke || '#333', stroke: cfg.style.stroke || '#333',
cursor: cfg.style.cursor cursor: cfg.style.cursor,
}, },
name: 'mid', name: 'mid',
draggable: true draggable: true,
}); });
const style = (cfg.labelCfg && cfg.labelCfg.style) || {}; const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
if (cfg.label) { if (cfg.label) {
group.addShape('text', { group.addShape('text', {
attrs: { attrs: {
x: width, // 居中 x: width, // 居中
@ -49,45 +48,50 @@ export default Util.registerShape('binary-tree-node', {
text: cfg.label, text: cfg.label,
fill: style.fill || '#000', fill: style.fill || '#000',
fontSize: style.fontSize || 16, fontSize: style.fontSize || 16,
cursor: cfg.style.cursor cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true 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';
//节点没有左孩子节点时 //节点没有左孩子节点时
if(cfg.child[0] == "0x0"){ if (isLeftEmpty) {
group.addShape('text', { group.addShape('text', {
attrs: { attrs: {
x: width * (5 / 8), x: width * (5 / 8),
y: height * ( 8 / 7), y: height * (8 / 7),
textAlign: 'center', textAlign: 'center',
textBaseline: 'middle', textBaseline: 'middle',
text: '^', text: '^',
fill: style.fill || '#000', fill: style.fill || '#000',
fontSize: 18, fontSize: 16,
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
} }
//节点没有右孩子节点时 //节点没有右孩子节点时
if(cfg.child[1] == "0x0"){ if (isRightEmpty) {
group.addShape('text', { group.addShape('text', {
attrs: { attrs: {
x: width * (11 / 8), x: width * (11 / 8),
y: height * ( 8 / 7), y: height * (8 / 7),
textAlign: 'center', textAlign: 'center',
textBaseline: 'middle', textBaseline: 'middle',
text: '^', text: '^',
fill: style.fill || '#000', fill: style.fill || '#000',
fontSize: 18, fontSize: 16,
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
} }
@ -99,7 +103,9 @@ export default Util.registerShape('binary-tree-node', {
[0.5, 0], [0.5, 0],
[0.875, 0.5], [0.875, 0.5],
[0.5, 1], [0.5, 1],
[0.125, 0.5] [0.125, 0.5],
]; ];
}, },
}, 'rect'); },
'rect'
);

View File

@ -1,21 +1,14 @@
import G6 from "@antv/g6"; import G6 from '@antv/g6';
import { Util } from "../Common/util"; import { Util } from '../Common/util';
export default function rotate(shape, angle, transform) { export default function rotate(shape, angle, transform) {
const matrix1 = shape.getMatrix(); const matrix1 = shape.getMatrix();
const newMatrix1 = transform(matrix1, [ const newMatrix1 = transform(matrix1, [['r', angle]]);
['r', angle],
]);
shape.setMatrix(newMatrix1); shape.setMatrix(newMatrix1);
} }
function translate(shape, x, y, transform) { function translate(shape, x, y, transform) {
const matrix1 = shape.getMatrix(); const matrix1 = shape.getMatrix();
const newMatrix1 = transform(matrix1, [ const newMatrix1 = transform(matrix1, [['t', x, y]]);
['t', x, y],
]);
shape.setMatrix(newMatrix1); shape.setMatrix(newMatrix1);
} }
function culcuRotate(angle, R) { function culcuRotate(angle, R) {
@ -25,11 +18,9 @@ function culcuRotate(angle, R) {
return { return {
offsetX, offsetX,
offsetY, offsetY,
} };
} }
Util.registerShape('clen-queue-pointer', { Util.registerShape('clen-queue-pointer', {
draw(cfg, group) { draw(cfg, group) {
let id = cfg.id as string; let id = cfg.id as string;
@ -44,10 +35,10 @@ Util.registerShape('clen-queue-pointer', {
fill: cfg.style.fill, fill: cfg.style.fill,
// matrix: cfg.style.matrix // matrix: cfg.style.matrix
}, },
name: 'pointer-path' name: 'pointer-path',
}); });
const angle = index * Math.PI * 2 / len; const angle = (index * Math.PI * 2) / len;
if (cfg.label) { if (cfg.label) {
const style = (cfg.labelCfg && cfg.labelCfg.style) || {}; const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
@ -59,28 +50,28 @@ Util.registerShape('clen-queue-pointer', {
height: 0, height: 0,
text: cfg.label, text: cfg.label,
fill: null, fill: null,
radius: 2 radius: 2,
}, },
name: 'bgRect' name: 'bgRect',
}); });
let label = cfg.label as string; let label = cfg.label as string;
let pointerText = label.split('-')[0]; let pointerText = label.split('-')[0];
let y = pointerText=="front"?30:15; let y = pointerText == 'front' ? 30 : 15;
const text = group.addShape('text', { const text = group.addShape('text', {
attrs: { attrs: {
x: culcuRotate(Math.PI/2 - angle, y).offsetX, x: culcuRotate(Math.PI / 2 - angle, y).offsetX,
y: culcuRotate(Math.PI/2 - angle, y).offsetY, y: culcuRotate(Math.PI / 2 - angle, y).offsetY,
// x: 0, // x: 0,
// y: 0, // y: 0,
textAlign: 'center', textAlign: 'center',
textBaseline: 'middle', textBaseline: 'middle',
text: pointerText, text: pointerText,
fill: style.fill || '#999', fill: style.fill || '#999',
fontSize: style.fontSize || 16 fontSize: style.fontSize || 16,
}, },
name: 'pointer-text-shape' name: 'pointer-text-shape',
}); });
// rotate(text, angle, G6.Util.transform); // rotate(text, angle, G6.Util.transform);
@ -90,8 +81,6 @@ Util.registerShape('clen-queue-pointer', {
translate(keyShape, 0, -75, G6.Util.transform); translate(keyShape, 0, -75, G6.Util.transform);
return keyShape; return keyShape;
}, },
getPath(cfg) { getPath(cfg) {
@ -104,9 +93,9 @@ Util.registerShape('clen-queue-pointer', {
['M', 0, 0], ['M', 0, 0],
['L', -width / 2, 0], ['L', -width / 2, 0],
['L', -width / 2, -height], ['L', -width / 2, -height],
['L', -width / 2 - (arrowWidth / 2), -height], ['L', -width / 2 - arrowWidth / 2, -height],
['L', 0, -height-arrowHeight], ['L', 0, -height - arrowHeight],
['L', width / 2 + (arrowWidth / 2), -height], ['L', width / 2 + arrowWidth / 2, -height],
['L', width / 2, -height], ['L', width / 2, -height],
['L', width / 2, 0], ['L', width / 2, 0],
['Z'], ['Z'],
@ -114,7 +103,4 @@ Util.registerShape('clen-queue-pointer', {
return path; return path;
}, },
}); });

View File

@ -6,11 +6,11 @@
* @Description: koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @FilePath: \c:\Users\13127\Desktop\\0126\StructV2\src\RegisteredShape\linkListNode.ts * @FilePath: \c:\Users\13127\Desktop\\0126\StructV2\src\RegisteredShape\linkListNode.ts
*/ */
import { Util } from "../Common/util"; import { Util } from '../Common/util';
export default Util.registerShape(
'link-list-node',
export default Util.registerShape('link-list-node', { {
draw(cfg, group) { draw(cfg, group) {
cfg.size = cfg.size || [30, 10]; cfg.size = cfg.size || [30, 10];
@ -25,9 +25,9 @@ export default Util.registerShape('link-list-node', {
height: height, height: height,
stroke: cfg.style.stroke || '#333', stroke: cfg.style.stroke || '#333',
fill: cfg.style.backgroundFill || '#eee', fill: cfg.style.backgroundFill || '#eee',
cursor: cfg.style.cursor cursor: cfg.style.cursor,
}, },
name: 'wrapper' name: 'wrapper',
}); });
group.addShape('rect', { group.addShape('rect', {
@ -38,10 +38,10 @@ export default Util.registerShape('link-list-node', {
height: height, height: height,
fill: cfg.style.fill, fill: cfg.style.fill,
stroke: cfg.style.stroke || '#333', stroke: cfg.style.stroke || '#333',
cursor: cfg.style.cursor cursor: cfg.style.cursor,
}, },
name: 'main-rect', name: 'main-rect',
draggable: true draggable: true,
}); });
const style = (cfg.labelCfg && cfg.labelCfg.style) || {}; const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
@ -55,28 +55,28 @@ export default Util.registerShape('link-list-node', {
textBaseline: 'middle', textBaseline: 'middle',
text: cfg.label, text: cfg.label,
fill: style.fill || '#000', fill: style.fill || '#000',
fontSize: style.fontSize || 16 fontSize: style.fontSize || 16,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
} }
//节点没有后续指针时 //节点没有后续指针时
if(!cfg.next && !cfg.loopNext){ if (!cfg.next && !cfg.loopNext) {
group.addShape('text', { group.addShape('text', {
attrs: { attrs: {
x: width * (4 / 3), x: width * (4 / 3),
y: height * ( 6 / 5), y: height * (6 / 5),
textAlign: 'center', textAlign: 'center',
textBaseline: 'middle', textBaseline: 'middle',
text: '^', text: '^',
fill: style.fill || '#000', fill: style.fill || '#000',
fontSize: 18, fontSize: 16,
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
} }
@ -92,7 +92,9 @@ export default Util.registerShape('link-list-node', {
[5 / 6, 1], [5 / 6, 1],
[0.5, 1], [0.5, 1],
[0, 0.5], [0, 0.5],
[1 / 3, 1] [1 / 3, 1],
]; ];
} },
}, 'rect'); },
'rect'
);

View File

@ -1,15 +1,14 @@
import { Util } from '../Common/util'; import { Util } from '../Common/util';
export default Util.registerShape('pointer', { export default Util.registerShape('pointer', {
draw(cfg, group) { draw(cfg, group) {
const keyShape = group.addShape('path', { const keyShape = group.addShape('path', {
attrs: { attrs: {
path: this.getPath(cfg), path: this.getPath(cfg),
fill: cfg.style.fill, fill: cfg.style.fill,
matrix: cfg.style.matrix matrix: cfg.style.matrix,
}, },
name: 'pointer-path' name: 'pointer-path',
}); });
if (cfg.label) { if (cfg.label) {
@ -21,9 +20,9 @@ export default Util.registerShape('pointer', {
y: 0, y: 0,
text: cfg.label, text: cfg.label,
fill: null, fill: null,
radius: 2 radius: 2,
}, },
name: 'bgRect' name: 'bgRect',
}); });
const text = group.addShape('text', { const text = group.addShape('text', {
@ -34,32 +33,32 @@ export default Util.registerShape('pointer', {
textBaseline: 'middle', textBaseline: 'middle',
text: cfg.label, text: cfg.label,
fill: labelStyle.fill || '#999', fill: labelStyle.fill || '#999',
fontSize: labelStyle.fontSize || 16 fontSize: labelStyle.fontSize || 16,
}, },
name: 'pointer-text-shape' name: 'pointer-text-shape',
}); });
const { width: textWidth, height: textHeight } = text.getBBox(); const { width: textWidth, height: textHeight } = text.getBBox();
const {width: pointerWidth, height: pointerHeight} = keyShape.getBBox(); const { width: pointerWidth, height: pointerHeight } = keyShape.getBBox();
bgRect.attr({ bgRect.attr({
width: textWidth + pointerWidth + 6, width: textWidth + pointerWidth + 6,
height: textHeight + pointerHeight + 6 height: textHeight + pointerHeight + 6,
}); });
// 旋转文字 // 旋转文字
const markerEndPosition = cfg.markerEndPosition; const markerEndPosition = cfg.markerEndPosition;
if(markerEndPosition) { if (markerEndPosition) {
let textX = markerEndPosition[0], let textX = markerEndPosition[0],
textY = markerEndPosition[1]; textY = markerEndPosition[1];
text.attr({ text.attr({
x: textX, x: textX,
y: textY y: textY,
}); });
bgRect.attr({ bgRect.attr({
x: textX - textWidth / 2 - 3, x: textX - textWidth / 2 - 3,
y: textY - textHeight / 2 - 3 y: textY - textHeight / 2 - 3,
}); });
} }
return bgRect; return bgRect;
@ -76,15 +75,15 @@ export default Util.registerShape('pointer', {
const path = [ const path = [
['M', 0, 0], ['M', 0, 0],
['L', -width / 2 - (arrowWidth / 2), -arrowHeight], ['L', -width / 2 - arrowWidth / 2, -arrowHeight],
['L', -width / 2, -arrowHeight], ['L', -width / 2, -arrowHeight],
['L', -width / 2, -height], ['L', -width / 2, -height],
['L', width / 2, -height], ['L', width / 2, -height],
['L', width / 2, -arrowHeight], ['L', width / 2, -arrowHeight],
['L', width / 2 + (arrowWidth / 2), -arrowHeight], ['L', width / 2 + arrowWidth / 2, -arrowHeight],
['Z'], ['Z'],
]; ];
return path; return path;
} },
}); });

View File

@ -8,8 +8,6 @@
*/ */
import { registerNode } from '@antv/g6'; import { registerNode } from '@antv/g6';
export default registerNode('three-cell', { export default registerNode('three-cell', {
draw(cfg, group) { draw(cfg, group) {
cfg.size = cfg.size || [30, 10]; cfg.size = cfg.size || [30, 10];
@ -24,9 +22,9 @@ export default registerNode('three-cell', {
width: width, width: width,
height: height, height: height,
stroke: cfg.style.stroke, stroke: cfg.style.stroke,
fill: cfg.style.backgroundFill || '#eee' fill: cfg.style.backgroundFill || '#eee',
}, },
name: 'wrapper' name: 'wrapper',
}); });
group.addShape('rect', { group.addShape('rect', {
@ -36,10 +34,10 @@ export default registerNode('three-cell', {
width: width / 3, width: width / 3,
height: height, height: height,
fill: cfg.style.fill, fill: cfg.style.fill,
stroke: cfg.style.stroke stroke: cfg.style.stroke,
}, },
name: 'left-rect', name: 'left-rect',
draggable: true draggable: true,
}); });
group.addShape('rect', { group.addShape('rect', {
@ -49,16 +47,16 @@ export default registerNode('three-cell', {
width: width / 3, width: width / 3,
height: height, height: height,
fill: cfg.style.fill, fill: cfg.style.fill,
stroke: cfg.style.stroke stroke: cfg.style.stroke,
}, },
name: 'middle-rect', name: 'middle-rect',
draggable: true draggable: true,
}); });
const style = (cfg.labelCfg && cfg.labelCfg.style) || {}; const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
//节点上方文字 //节点上方文字
if(cfg.root && cfg.rootLabel){ if (cfg.root && cfg.rootLabel) {
group.addShape('text', { group.addShape('text', {
attrs: { attrs: {
x: width * (2 / 3), x: width * (2 / 3),
@ -72,7 +70,7 @@ export default registerNode('three-cell', {
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
group.addShape('text', { group.addShape('text', {
@ -88,7 +86,7 @@ export default registerNode('three-cell', {
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
group.addShape('text', { group.addShape('text', {
@ -104,12 +102,12 @@ export default registerNode('three-cell', {
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
} }
//节点左边文字 //节点左边文字
if(cfg.index !== null){ if (cfg.index !== null) {
group.addShape('text', { group.addShape('text', {
attrs: { attrs: {
x: width * (2 / 5), x: width * (2 / 5),
@ -123,11 +121,11 @@ export default registerNode('three-cell', {
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
} }
//节点文字(数组形式) //节点文字(数组形式)
if(cfg.label) { if (cfg.label) {
group.addShape('text', { group.addShape('text', {
attrs: { attrs: {
x: width * (2 / 3), x: width * (2 / 3),
@ -140,7 +138,7 @@ export default registerNode('three-cell', {
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
group.addShape('text', { group.addShape('text', {
@ -155,29 +153,28 @@ export default registerNode('three-cell', {
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
} }
//节点没有后续指针时 //节点没有后续指针时
if(!cfg.headNext){ if (!cfg.headNext) {
group.addShape('text', { group.addShape('text', {
attrs: { attrs: {
x: width * (4 / 3), x: width * (4 / 3),
y: height * ( 6 / 5), y: height * (6 / 5),
textAlign: 'center', textAlign: 'center',
textBaseline: 'middle', textBaseline: 'middle',
text: '^', text: '^',
fill: style.fill || '#000', fill: style.fill || '#000',
fontSize: 25, fontSize: 22,
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
} }
return wrapperRect; return wrapperRect;
}, },
@ -186,7 +183,7 @@ export default registerNode('three-cell', {
[0.5, 0], [0.5, 0],
[5 / 6, 0.5], [5 / 6, 0.5],
[0.5, 1], [0.5, 1],
[0, 0.5] [0, 0.5],
]; ];
} },
}); });

View File

@ -1,7 +1,8 @@
import { Util } from '../Common/util'; import { Util } from '../Common/util';
export default Util.registerShape(
export default Util.registerShape('tri-tree-node', { 'tri-tree-node',
{
draw(cfg, group) { draw(cfg, group) {
cfg.size = cfg.size; cfg.size = cfg.size;
@ -16,9 +17,9 @@ export default Util.registerShape('tri-tree-node', {
height: height, height: height,
stroke: cfg.style.stroke || '#333', stroke: cfg.style.stroke || '#333',
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
fill: cfg.style.backgroundFill || '#eee' fill: cfg.style.backgroundFill || '#eee',
}, },
name: 'wrapper' name: 'wrapper',
}); });
group.addShape('rect', { group.addShape('rect', {
@ -29,10 +30,10 @@ export default Util.registerShape('tri-tree-node', {
height: height / 4, height: height / 4,
fill: '#eee', fill: '#eee',
stroke: cfg.style.stroke || '#333', stroke: cfg.style.stroke || '#333',
cursor: cfg.style.cursor cursor: cfg.style.cursor,
}, },
name: 'top', name: 'top',
draggable: true draggable: true,
}); });
group.addShape('rect', { group.addShape('rect', {
@ -40,13 +41,13 @@ export default Util.registerShape('tri-tree-node', {
x: width / 4 + width / 2, x: width / 4 + width / 2,
y: height / 2 + height / 4, y: height / 2 + height / 4,
width: width / 2, width: width / 2,
height: height / 4 * 3, height: (height / 4) * 3,
fill: cfg.color || cfg.style.fill, fill: cfg.color || cfg.style.fill,
stroke: cfg.style.stroke || '#333', stroke: cfg.style.stroke || '#333',
cursor: cfg.style.cursor cursor: cfg.style.cursor,
}, },
name: 'bottom', name: 'bottom',
draggable: true draggable: true,
}); });
if (cfg.label) { if (cfg.label) {
@ -60,10 +61,10 @@ export default Util.registerShape('tri-tree-node', {
text: cfg.label, text: cfg.label,
fill: style.fill || '#000', fill: style.fill || '#000',
fontSize: style.fontSize || 16, fontSize: style.fontSize || 16,
cursor: cfg.style.cursor cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
} }
@ -72,16 +73,16 @@ export default Util.registerShape('tri-tree-node', {
group.addShape('text', { group.addShape('text', {
attrs: { attrs: {
x: width, // 居中 x: width, // 居中
y: height / 4 * 3, y: (height / 4) * 3,
textAlign: 'center', textAlign: 'center',
textBaseline: 'middle', textBaseline: 'middle',
text: "^", text: '^',
fill: style.fill || '#000', fill: style.fill || '#000',
fontSize: style.fontSize || 14, fontSize: style.fontSize || 14,
cursor: cfg.style.cursor cursor: cfg.style.cursor,
}, },
name: 'parent', name: 'parent',
draggable: true draggable: true,
}); });
} }
@ -94,7 +95,9 @@ export default Util.registerShape('tri-tree-node', {
[0.875, 0.5], [0.875, 0.5],
[0.5, 1], [0.5, 1],
[0.5, 0], [0.5, 0],
[0.5, 0.125] [0.5, 0.125],
]; ];
}, },
}, 'rect'); },
'rect'
);

View File

@ -1,8 +1,8 @@
import { Util } from '../Common/util'; import { Util } from '../Common/util';
export default Util.registerShape(
'two-cell-node',
export default Util.registerShape('two-cell-node', { {
draw(cfg, group) { draw(cfg, group) {
cfg.size = cfg.size || [30, 10]; cfg.size = cfg.size || [30, 10];
@ -16,9 +16,9 @@ export default Util.registerShape('two-cell-node', {
width: width, width: width,
height: height, height: height,
stroke: cfg.style.stroke, stroke: cfg.style.stroke,
fill: cfg.style.backgroundFill || '#eee' fill: cfg.style.backgroundFill || '#eee',
}, },
name: 'wrapper' name: 'wrapper',
}); });
group.addShape('rect', { group.addShape('rect', {
@ -28,17 +28,18 @@ export default Util.registerShape('two-cell-node', {
width: width / 2, width: width / 2,
height: height, height: height,
fill: cfg.style.fill, fill: cfg.style.fill,
stroke: cfg.style.stroke stroke: cfg.style.stroke,
}, },
name: 'left-rect', name: 'left-rect',
draggable: true draggable: true,
}); });
const style = (cfg.labelCfg && cfg.labelCfg.style) || {}; const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
if (cfg.label) { if (cfg.label) {
if(Array.isArray(cfg.label)) { if (Array.isArray(cfg.label)) {
let tag = cfg.label[0], data = cfg.label[1]; let tag = cfg.label[0],
data = cfg.label[1];
group.addShape('text', { group.addShape('text', {
attrs: { attrs: {
@ -52,7 +53,7 @@ export default Util.registerShape('two-cell-node', {
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
group.addShape('text', { group.addShape('text', {
@ -67,10 +68,9 @@ export default Util.registerShape('two-cell-node', {
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
} } else {
else {
group.addShape('text', { group.addShape('text', {
attrs: { attrs: {
x: width * (3 / 4), x: width * (3 / 4),
@ -83,17 +83,17 @@ export default Util.registerShape('two-cell-node', {
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
} }
} }
//图 数据结构中没有后续指针 //图 数据结构中没有后续指针
if(cfg.id.includes('tableHeadNode') && !cfg.headNext){ if (cfg.id.includes('tableHeadNode') && !cfg.headNext) {
group.addShape('text', { group.addShape('text', {
attrs: { attrs: {
x: width * (5 / 4), x: width * (5 / 4),
y: height * ( 8 / 7), y: height * (8 / 7),
textAlign: 'center', textAlign: 'center',
textBaseline: 'middle', textBaseline: 'middle',
text: '^', text: '^',
@ -102,16 +102,16 @@ export default Util.registerShape('two-cell-node', {
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
} }
//哈希表 数据结构中没有后续指针 //哈希表 数据结构中没有后续指针
if(cfg.id.includes('head') && !cfg.start){ if (cfg.id.includes('head') && !cfg.start) {
group.addShape('text', { group.addShape('text', {
attrs: { attrs: {
x: width * (5 / 4), x: width * (5 / 4),
y: height * ( 8 / 7), y: height * (8 / 7),
textAlign: 'center', textAlign: 'center',
textBaseline: 'middle', textBaseline: 'middle',
text: '^', text: '^',
@ -120,7 +120,7 @@ export default Util.registerShape('two-cell-node', {
cursor: cfg.style.cursor, cursor: cfg.style.cursor,
}, },
name: 'text', name: 'text',
draggable: true draggable: true,
}); });
} }
@ -132,7 +132,9 @@ export default Util.registerShape('two-cell-node', {
[0.5, 0], [0.5, 0],
[3 / 4, 0.5], [3 / 4, 0.5],
[0.5, 1], [0.5, 1],
[0, 0.5] [0, 0.5],
]; ];
} },
}, 'rect'); },
'rect'
);