fix: bug 修复
This commit is contained in:
parent
97749ec35e
commit
2a09ca6be1
@ -1,149 +1,145 @@
|
|||||||
SV.registerLayout('BinaryTree', {
|
SV.registerLayout('BinaryTree', {
|
||||||
defineOptions() {
|
defineOptions() {
|
||||||
return {
|
return {
|
||||||
element: {
|
element: {
|
||||||
default: {
|
default: {
|
||||||
type: 'binary-tree-node',
|
type: 'binary-tree-node',
|
||||||
size: [60, 30],
|
size: [60, 30],
|
||||||
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',
|
||||||
lineAppendWidth: 6,
|
lineAppendWidth: 6,
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
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: {
|
||||||
type: 'pointer',
|
type: 'pointer',
|
||||||
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
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对子树进行递归布局
|
* 对子树进行递归布局
|
||||||
*/
|
*/
|
||||||
layoutItem(node, parent, index, layoutOptions) {
|
layoutItem(node, parent, index, layoutOptions) {
|
||||||
// 次双亲不进行布局
|
// 次双亲不进行布局
|
||||||
if (!node) {
|
if (!node) {
|
||||||
return null;
|
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(),
|
if(rightGroup) {
|
||||||
width = bound.width,
|
let rightBound = rightGroup.getBound();
|
||||||
height = bound.height,
|
|
||||||
group = new Group(node);
|
|
||||||
|
|
||||||
if (node.visited) {
|
node.set('y', rightBound.y - layoutOptions.yInterval - height);
|
||||||
return;
|
node.set('x', rightBound.x - layoutOptions.xInterval / 2 - width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node.visited = true;
|
||||||
|
|
||||||
if (parent) {
|
if (leftGroup) {
|
||||||
node.set('y', parent.get('y') + layoutOptions.yInterval + height);
|
group.add(leftGroup);
|
||||||
|
}
|
||||||
|
|
||||||
// 左节点
|
if (rightGroup) {
|
||||||
if (index === 0) {
|
group.add(rightGroup);
|
||||||
node.set('x', parent.get('x') - layoutOptions.xInterval / 2 - width / 2);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 右结点
|
return group;
|
||||||
if (index === 1) {
|
},
|
||||||
node.set('x', parent.get('x') + layoutOptions.xInterval / 2 + width / 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
node.visited = true;
|
/**
|
||||||
|
* 布局函数
|
||||||
if (node.child && (node.child[0] || node.child[1])) {
|
* @param {*} elements
|
||||||
let leftChild = node.child[0],
|
* @param {*} layoutOptions
|
||||||
rightChild = node.child[1],
|
*/
|
||||||
leftGroup = this.layoutItem(leftChild, node, 0, layoutOptions),
|
layout(elements, layoutOptions) {
|
||||||
rightGroup = this.layoutItem(rightChild, node, 1, layoutOptions),
|
let root = elements[0];
|
||||||
intersection = null,
|
this.layoutItem(root, null, -1, layoutOptions);
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: 6385328,
|
||||||
|
data: '',
|
||||||
[{
|
external: ['L'],
|
||||||
"id": 6385328,
|
root: true,
|
||||||
"data": "",
|
after: null,
|
||||||
"external": [
|
next: null,
|
||||||
"L"
|
},
|
||||||
],
|
];
|
||||||
"root": true,
|
|
||||||
"after": null,
|
|
||||||
"next": null
|
|
||||||
}]
|
|
||||||
|
|||||||
@ -1,291 +1,250 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>DEMO</title>
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
<head>
|
.container {
|
||||||
<meta charset="UTF-8" />
|
background-color: #fafafa;
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
border: 1px solid #ccc;
|
||||||
<title>DEMO</title>
|
position: relative;
|
||||||
<style>
|
}
|
||||||
* {
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
user-select: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container {
|
.down {
|
||||||
background-color: #fafafa;
|
display: flex;
|
||||||
border: 1px solid #ccc;
|
margin-top: 20px;
|
||||||
position: relative;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.down {
|
#container {
|
||||||
display: flex;
|
width: 100%;
|
||||||
margin-top: 20px;
|
height: 500px;
|
||||||
}
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
#container {
|
#leak {
|
||||||
width: 100%;
|
position: absolute;
|
||||||
height: 500px;
|
left: 0;
|
||||||
position: relative;
|
opacity: 0;
|
||||||
overflow: hidden;
|
top: 100px;
|
||||||
}
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding: 4px;
|
||||||
|
border-top: 1px dashed #000;
|
||||||
|
pointer-events: none;
|
||||||
|
transition: opacity 0.75s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
#leak {
|
#leak > span {
|
||||||
position: absolute;
|
color: #000;
|
||||||
left: 0;
|
}
|
||||||
opacity: 0;
|
</style>
|
||||||
top: 100px;
|
</head>
|
||||||
width: 100%;
|
|
||||||
box-sizing: border-box;
|
|
||||||
padding: 4px;
|
|
||||||
border-top: 1px dashed #000;
|
|
||||||
pointer-events: none;
|
|
||||||
transition: opacity 0.75s ease-in-out;
|
|
||||||
}
|
|
||||||
|
|
||||||
#leak>span {
|
<body>
|
||||||
color: #000;
|
<div class="container" id="container">
|
||||||
}
|
<div id="leak">
|
||||||
</style>
|
<span>泄漏区</span>
|
||||||
</head>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<body>
|
<button id="btn-prev">prev</button>
|
||||||
<div class="container" id="container">
|
<button id="btn-next">next</button>
|
||||||
<div id="leak">
|
<button id="resize">resize</button>
|
||||||
<span>泄漏区</span>
|
<button id="relayout">relayout</button>
|
||||||
</div>
|
<button id="switch-mode">switch mode</button>
|
||||||
</div>
|
<button id="brush-select">brush-select</button>
|
||||||
|
<span id="pos"></span>
|
||||||
|
|
||||||
<button id="btn-prev">prev</button>
|
<script src="./../dist/sv.js"></script>
|
||||||
<button id="btn-next">next</button>
|
<script>
|
||||||
<button id="resize">resize</button>
|
const Group = SV.Group,
|
||||||
<button id="relayout">relayout</button>
|
Bound = SV.Bound,
|
||||||
<button id="switch-mode">switch mode</button>
|
G6 = SV.G6,
|
||||||
<button id="brush-select">brush-select</button>
|
Vector = SV.Vector;
|
||||||
<span id="pos"></span>
|
</script>
|
||||||
|
<script src="./Layouter/LinkList.js"></script>
|
||||||
|
<script src="./Layouter/BinaryTree.js"></script>
|
||||||
|
<script src="./Layouter/Stack.js"></script>
|
||||||
|
<script src="./Layouter/LinkQueue.js"></script>
|
||||||
|
<script src="./Layouter/GeneralizedList.js"></script>
|
||||||
|
<script src="./Layouter/ChainHashTable.js"></script>
|
||||||
|
<script src="./Layouter/Array.js"></script>
|
||||||
|
<script src="./Layouter/HashTable.js"></script>
|
||||||
|
<script src="./Layouter/LinkStack.js"></script>
|
||||||
|
<script src="./Layouter/AdjoinMatrixGraph.js"></script>
|
||||||
|
<script src="./Layouter/AdjoinTableGraph.js"></script>
|
||||||
|
<script src="./Layouter/SqQueue.js"></script>
|
||||||
|
<script src="./Layouter/PTree.js"></script>
|
||||||
|
<script src="./Layouter/PCTree.js"></script>
|
||||||
|
|
||||||
<script src="./../dist/sv.js"></script>
|
<script>
|
||||||
<script>
|
let cur = SV(document.getElementById('container'), {
|
||||||
const Group = SV.Group,
|
view: {
|
||||||
Bound = SV.Bound,
|
leakAreaHeight: 130,
|
||||||
G6 = SV.G6,
|
groupPadding: 40,
|
||||||
Vector = SV.Vector;
|
},
|
||||||
</script>
|
});
|
||||||
<script src="./Layouter/LinkList.js"></script>
|
|
||||||
<script src="./Layouter/BinaryTree.js"></script>
|
|
||||||
<script src="./Layouter/Stack.js"></script>
|
|
||||||
<script src="./Layouter/LinkQueue.js"></script>
|
|
||||||
<script src="./Layouter/GeneralizedList.js"></script>
|
|
||||||
<script src="./Layouter/ChainHashTable.js"></script>
|
|
||||||
<script src="./Layouter/Array.js"></script>
|
|
||||||
<script src="./Layouter/HashTable.js"></script>
|
|
||||||
<script src="./Layouter/LinkStack.js"></script>
|
|
||||||
<script src="./Layouter/AdjoinMatrixGraph.js"></script>
|
|
||||||
<script src="./Layouter/AdjoinTableGraph.js"></script>
|
|
||||||
<script src="./Layouter/SqQueue.js"></script>
|
|
||||||
<script src="./Layouter/PTree.js"></script>
|
|
||||||
<script src="./Layouter/PCTree.js"></script>
|
|
||||||
|
|
||||||
<script>
|
let data = [
|
||||||
let cur = SV(document.getElementById('container'), {
|
{
|
||||||
view: {
|
BinaryTree0: {
|
||||||
leakAreaHeight: 130,
|
data: [
|
||||||
groupPadding: 40,
|
{
|
||||||
},
|
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',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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 data = [{
|
let dataIndex = 0,
|
||||||
"BinaryTree0": {
|
curData = data[dataIndex];
|
||||||
"data": [{
|
|
||||||
"external": [
|
|
||||||
"T"
|
|
||||||
],
|
|
||||||
"child": [
|
|
||||||
"0x616060",
|
|
||||||
"0x615f40"
|
|
||||||
],
|
|
||||||
"id": "0x615f10",
|
|
||||||
"name": "T",
|
|
||||||
"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
|
|
||||||
}, {
|
|
||||||
"BinaryTree0": {
|
|
||||||
"data": [{
|
|
||||||
"external": [
|
|
||||||
"T"
|
|
||||||
],
|
|
||||||
"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
|
|
||||||
}];
|
|
||||||
|
|
||||||
let dataIndex = 0,
|
let enableBrushSelect = false;
|
||||||
curData = data[dataIndex];
|
|
||||||
|
|
||||||
let enableBrushSelect = false;
|
const container = document.getElementById('container'),
|
||||||
|
pos = document.getElementById('pos');
|
||||||
|
|
||||||
const container = document.getElementById('container'),
|
const leak = document.getElementById('leak');
|
||||||
pos = document.getElementById('pos');
|
|
||||||
|
|
||||||
const leak = document.getElementById('leak');
|
cur.render(curData);
|
||||||
|
|
||||||
cur.render(curData);
|
document.getElementById('btn-next').addEventListener('click', e => {
|
||||||
|
curData = data[++dataIndex];
|
||||||
|
cur.render(curData);
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById('btn-next').addEventListener('click', e => {
|
document.getElementById('btn-prev').addEventListener('click', e => {
|
||||||
curData = data[++dataIndex];
|
curData = data[--dataIndex];
|
||||||
cur.render(curData);
|
cur.render(curData);
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('btn-prev').addEventListener('click', e => {
|
document.getElementById('resize').addEventListener('click', e => {
|
||||||
curData = data[--dataIndex];
|
container.style.height = 800 + 'px';
|
||||||
cur.render(curData);
|
cur.resize(container.offsetWidth, container.offsetHeight);
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('resize').addEventListener('click', e => {
|
document.getElementById('relayout').addEventListener('click', e => {
|
||||||
container.style.height = 800 + 'px';
|
cur.reLayout();
|
||||||
cur.resize(container.offsetWidth, container.offsetHeight);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById('relayout').addEventListener('click', e => {
|
document.getElementById('switch-mode').addEventListener('click', e => {
|
||||||
cur.reLayout();
|
cur.updateStyle('Array', newArrayOption);
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('switch-mode').addEventListener('click', e => {
|
document.getElementById('brush-select').addEventListener('click', e => {
|
||||||
cur.updateStyle('Array', newArrayOption);
|
enableBrushSelect = !enableBrushSelect;
|
||||||
});
|
cur.switchBrushSelect(enableBrushSelect);
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById('brush-select').addEventListener('click', e => {
|
cur.on('onLeakAreaUpdate', payload => {
|
||||||
enableBrushSelect = !enableBrushSelect;
|
leak.style.opacity = payload.hasLeak ? 1 : 0;
|
||||||
cur.switchBrushSelect(enableBrushSelect);
|
leak.style.top = payload.leakAreaY - 40 + 'px';
|
||||||
});
|
});
|
||||||
|
|
||||||
cur.on('onLeakAreaUpdate', payload => {
|
// -------------------------------------------------------------------------------------------------------
|
||||||
leak.style.opacity = payload.hasLeak ? 1 : 0;
|
|
||||||
leak.style.top = payload.leakAreaY - 40 + 'px';
|
|
||||||
});
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
container.addEventListener('mousemove', e => {
|
|
||||||
let x = e.offsetX,
|
|
||||||
y = e.offsetY;
|
|
||||||
pos.innerHTML = `${x},${y}`;
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
|
container.addEventListener('mousemove', e => {
|
||||||
|
let x = e.offsetX,
|
||||||
|
y = e.offsetY;
|
||||||
|
pos.innerHTML = `${x},${y}`;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@ -1,105 +1,111 @@
|
|||||||
|
|
||||||
import { Util } from '../Common/util';
|
import { Util } from '../Common/util';
|
||||||
|
|
||||||
|
export default Util.registerShape(
|
||||||
|
'binary-tree-node',
|
||||||
|
{
|
||||||
|
draw(cfg, group) {
|
||||||
|
cfg.size = cfg.size;
|
||||||
|
|
||||||
export default Util.registerShape('binary-tree-node', {
|
const width = cfg.size[0],
|
||||||
draw(cfg, group) {
|
height = cfg.size[1];
|
||||||
cfg.size = cfg.size;
|
|
||||||
|
|
||||||
const width = cfg.size[0],
|
const wrapperRect = group.addShape('rect', {
|
||||||
height = cfg.size[1];
|
attrs: {
|
||||||
|
x: width / 2,
|
||||||
|
y: height / 2,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
stroke: cfg.style.stroke || '#333',
|
||||||
|
cursor: cfg.style.cursor,
|
||||||
|
fill: cfg.style.backgroundFill || '#eee',
|
||||||
|
},
|
||||||
|
name: 'wrapper',
|
||||||
|
});
|
||||||
|
|
||||||
const wrapperRect = group.addShape('rect', {
|
group.addShape('rect', {
|
||||||
attrs: {
|
attrs: {
|
||||||
x: width / 2,
|
x: width / 4 + width / 2,
|
||||||
y: height / 2,
|
y: height / 2,
|
||||||
width: width,
|
width: width / 2,
|
||||||
height: height,
|
height: height,
|
||||||
stroke: cfg.style.stroke || '#333',
|
fill: cfg.style.fill,
|
||||||
cursor: cfg.style.cursor,
|
stroke: cfg.style.stroke || '#333',
|
||||||
fill: cfg.style.backgroundFill || '#eee'
|
cursor: cfg.style.cursor,
|
||||||
},
|
},
|
||||||
name: 'wrapper'
|
name: 'mid',
|
||||||
});
|
draggable: true,
|
||||||
|
});
|
||||||
|
|
||||||
group.addShape('rect', {
|
const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
|
||||||
attrs: {
|
|
||||||
x: width / 4 + width / 2,
|
|
||||||
y: height / 2,
|
|
||||||
width: width / 2,
|
|
||||||
height: height,
|
|
||||||
fill: cfg.style.fill,
|
|
||||||
stroke: cfg.style.stroke || '#333',
|
|
||||||
cursor: cfg.style.cursor
|
|
||||||
},
|
|
||||||
name: 'mid',
|
|
||||||
draggable: true
|
|
||||||
});
|
|
||||||
|
|
||||||
const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
|
if (cfg.label) {
|
||||||
|
group.addShape('text', {
|
||||||
|
attrs: {
|
||||||
|
x: width, // 居中
|
||||||
|
y: height,
|
||||||
|
textAlign: 'center',
|
||||||
|
textBaseline: 'middle',
|
||||||
|
text: cfg.label,
|
||||||
|
fill: style.fill || '#000',
|
||||||
|
fontSize: style.fontSize || 16,
|
||||||
|
cursor: cfg.style.cursor,
|
||||||
|
},
|
||||||
|
name: 'text',
|
||||||
|
draggable: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (cfg.label) {
|
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';
|
||||||
|
|
||||||
group.addShape('text', {
|
//节点没有左孩子节点时
|
||||||
attrs: {
|
if (isLeftEmpty) {
|
||||||
x: width, // 居中
|
group.addShape('text', {
|
||||||
y: height,
|
attrs: {
|
||||||
textAlign: 'center',
|
x: width * (5 / 8),
|
||||||
textBaseline: 'middle',
|
y: height * (8 / 7),
|
||||||
text: cfg.label,
|
textAlign: 'center',
|
||||||
fill: style.fill || '#000',
|
textBaseline: 'middle',
|
||||||
fontSize: style.fontSize || 16,
|
text: '^',
|
||||||
cursor: cfg.style.cursor
|
fill: style.fill || '#000',
|
||||||
},
|
fontSize: 16,
|
||||||
name: 'text',
|
cursor: cfg.style.cursor,
|
||||||
draggable: true
|
},
|
||||||
});
|
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;
|
||||||
if(cfg.child[0] == "0x0"){
|
},
|
||||||
group.addShape('text', {
|
|
||||||
attrs: {
|
|
||||||
x: width * (5 / 8),
|
|
||||||
y: height * ( 8 / 7),
|
|
||||||
textAlign: 'center',
|
|
||||||
textBaseline: 'middle',
|
|
||||||
text: '^',
|
|
||||||
fill: style.fill || '#000',
|
|
||||||
fontSize: 18,
|
|
||||||
cursor: cfg.style.cursor,
|
|
||||||
},
|
|
||||||
name: 'text',
|
|
||||||
draggable: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
//节点没有右孩子节点时
|
|
||||||
if(cfg.child[1] == "0x0"){
|
|
||||||
group.addShape('text', {
|
|
||||||
attrs: {
|
|
||||||
x: width * (11 / 8),
|
|
||||||
y: height * ( 8 / 7),
|
|
||||||
textAlign: 'center',
|
|
||||||
textBaseline: 'middle',
|
|
||||||
text: '^',
|
|
||||||
fill: style.fill || '#000',
|
|
||||||
fontSize: 18,
|
|
||||||
cursor: cfg.style.cursor,
|
|
||||||
},
|
|
||||||
name: 'text',
|
|
||||||
draggable: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return wrapperRect;
|
getAnchorPoints() {
|
||||||
},
|
return [
|
||||||
|
[0.5, 0],
|
||||||
getAnchorPoints() {
|
[0.875, 0.5],
|
||||||
return [
|
[0.5, 1],
|
||||||
[0.5, 0],
|
[0.125, 0.5],
|
||||||
[0.875, 0.5],
|
];
|
||||||
[0.5, 1],
|
},
|
||||||
[0.125, 0.5]
|
},
|
||||||
];
|
'rect'
|
||||||
},
|
);
|
||||||
}, 'rect');
|
|
||||||
|
|||||||
@ -1,120 +1,106 @@
|
|||||||
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) {
|
||||||
let offsetX = Math.cos(angle) * R;
|
let offsetX = Math.cos(angle) * R;
|
||||||
let offsetY = -Math.sin(angle) * R;
|
let offsetY = -Math.sin(angle) * R;
|
||||||
console.log(offsetX, offsetY, R);
|
console.log(offsetX, offsetY, 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;
|
||||||
|
|
||||||
const index = parseInt(id.split('-')[1]);
|
const index = parseInt(id.split('-')[1]);
|
||||||
const len = parseInt(id.split('-')[2]);
|
const len = parseInt(id.split('-')[2]);
|
||||||
const keyShape = group.addShape('path', {
|
const keyShape = group.addShape('path', {
|
||||||
attrs: {
|
attrs: {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
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',
|
||||||
});
|
});
|
||||||
|
|
||||||
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) || {};
|
||||||
|
|
||||||
const bgRect = group.addShape('rect', {
|
const bgRect = group.addShape('rect', {
|
||||||
attrs: {
|
attrs: {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
width: 0,
|
width: 0,
|
||||||
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);
|
||||||
translate(text, 0, -75, G6.Util.transform);
|
translate(text, 0, -75, G6.Util.transform);
|
||||||
}
|
}
|
||||||
rotate(keyShape, angle, G6.Util.transform);
|
rotate(keyShape, angle, G6.Util.transform);
|
||||||
translate(keyShape, 0, -75, G6.Util.transform);
|
translate(keyShape, 0, -75, G6.Util.transform);
|
||||||
|
|
||||||
return keyShape;
|
return keyShape;
|
||||||
|
},
|
||||||
|
|
||||||
|
getPath(cfg) {
|
||||||
|
let width = 1,
|
||||||
|
height = 38,
|
||||||
|
arrowWidth = width + 4,
|
||||||
|
arrowHeight = height * 0.3;
|
||||||
|
|
||||||
},
|
const path = [
|
||||||
|
['M', 0, 0],
|
||||||
getPath(cfg) {
|
['L', -width / 2, 0],
|
||||||
let width = 1,
|
['L', -width / 2, -height],
|
||||||
height = 38,
|
['L', -width / 2 - arrowWidth / 2, -height],
|
||||||
arrowWidth = width + 4,
|
['L', 0, -height - arrowHeight],
|
||||||
arrowHeight = height * 0.3;
|
['L', width / 2 + arrowWidth / 2, -height],
|
||||||
|
['L', width / 2, -height],
|
||||||
const path = [
|
['L', width / 2, 0],
|
||||||
['M', 0, 0],
|
['Z'],
|
||||||
['L', -width / 2, 0],
|
];
|
||||||
['L', -width / 2, -height],
|
|
||||||
['L', -width / 2 - (arrowWidth / 2), -height],
|
|
||||||
['L', 0, -height-arrowHeight],
|
|
||||||
['L', width / 2 + (arrowWidth / 2), -height],
|
|
||||||
['L', width / 2, -height],
|
|
||||||
['L', width / 2, 0],
|
|
||||||
['Z'],
|
|
||||||
];
|
|
||||||
|
|
||||||
return path;
|
|
||||||
},
|
|
||||||
|
|
||||||
|
return path;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,93 +6,95 @@
|
|||||||
* @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',
|
||||||
|
{
|
||||||
|
draw(cfg, group) {
|
||||||
|
cfg.size = cfg.size || [30, 10];
|
||||||
|
|
||||||
|
const width = cfg.size[0],
|
||||||
|
height = cfg.size[1];
|
||||||
|
|
||||||
export default Util.registerShape('link-list-node', {
|
const wrapperRect = group.addShape('rect', {
|
||||||
draw(cfg, group) {
|
attrs: {
|
||||||
cfg.size = cfg.size || [30, 10];
|
x: width / 2,
|
||||||
|
y: height / 2,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
stroke: cfg.style.stroke || '#333',
|
||||||
|
fill: cfg.style.backgroundFill || '#eee',
|
||||||
|
cursor: cfg.style.cursor,
|
||||||
|
},
|
||||||
|
name: 'wrapper',
|
||||||
|
});
|
||||||
|
|
||||||
const width = cfg.size[0],
|
group.addShape('rect', {
|
||||||
height = cfg.size[1];
|
attrs: {
|
||||||
|
x: width / 2,
|
||||||
|
y: height / 2,
|
||||||
|
width: width * (2 / 3),
|
||||||
|
height: height,
|
||||||
|
fill: cfg.style.fill,
|
||||||
|
stroke: cfg.style.stroke || '#333',
|
||||||
|
cursor: cfg.style.cursor,
|
||||||
|
},
|
||||||
|
name: 'main-rect',
|
||||||
|
draggable: true,
|
||||||
|
});
|
||||||
|
|
||||||
const wrapperRect = group.addShape('rect', {
|
const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
|
||||||
attrs: {
|
|
||||||
x: width / 2,
|
|
||||||
y: height / 2,
|
|
||||||
width: width,
|
|
||||||
height: height,
|
|
||||||
stroke: cfg.style.stroke || '#333',
|
|
||||||
fill: cfg.style.backgroundFill || '#eee',
|
|
||||||
cursor: cfg.style.cursor
|
|
||||||
},
|
|
||||||
name: 'wrapper'
|
|
||||||
});
|
|
||||||
|
|
||||||
group.addShape('rect', {
|
if (cfg.label) {
|
||||||
attrs: {
|
group.addShape('text', {
|
||||||
x: width / 2,
|
attrs: {
|
||||||
y: height / 2,
|
x: width * (5 / 6),
|
||||||
width: width * (2 / 3),
|
y: height,
|
||||||
height: height,
|
textAlign: 'center',
|
||||||
fill: cfg.style.fill,
|
textBaseline: 'middle',
|
||||||
stroke: cfg.style.stroke || '#333',
|
text: cfg.label,
|
||||||
cursor: cfg.style.cursor
|
fill: style.fill || '#000',
|
||||||
},
|
fontSize: style.fontSize || 16,
|
||||||
name: 'main-rect',
|
},
|
||||||
draggable: true
|
name: 'text',
|
||||||
});
|
draggable: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
|
//节点没有后续指针时
|
||||||
|
if (!cfg.next && !cfg.loopNext) {
|
||||||
|
group.addShape('text', {
|
||||||
|
attrs: {
|
||||||
|
x: width * (4 / 3),
|
||||||
|
y: height * (6 / 5),
|
||||||
|
textAlign: 'center',
|
||||||
|
textBaseline: 'middle',
|
||||||
|
text: '^',
|
||||||
|
fill: style.fill || '#000',
|
||||||
|
fontSize: 16,
|
||||||
|
cursor: cfg.style.cursor,
|
||||||
|
},
|
||||||
|
name: 'text',
|
||||||
|
draggable: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (cfg.label) {
|
return wrapperRect;
|
||||||
group.addShape('text', {
|
},
|
||||||
attrs: {
|
|
||||||
x: width * (5 / 6),
|
|
||||||
y: height,
|
|
||||||
textAlign: 'center',
|
|
||||||
textBaseline: 'middle',
|
|
||||||
text: cfg.label,
|
|
||||||
fill: style.fill || '#000',
|
|
||||||
fontSize: style.fontSize || 16
|
|
||||||
},
|
|
||||||
name: 'text',
|
|
||||||
draggable: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//节点没有后续指针时
|
getAnchorPoints() {
|
||||||
if(!cfg.next && !cfg.loopNext){
|
return [
|
||||||
group.addShape('text', {
|
[0.5, 0],
|
||||||
attrs: {
|
[5 / 6, 0],
|
||||||
x: width * (4 / 3),
|
[5 / 6, 0.5],
|
||||||
y: height * ( 6 / 5),
|
[1, 0.5],
|
||||||
textAlign: 'center',
|
[5 / 6, 1],
|
||||||
textBaseline: 'middle',
|
[0.5, 1],
|
||||||
text: '^',
|
[0, 0.5],
|
||||||
fill: style.fill || '#000',
|
[1 / 3, 1],
|
||||||
fontSize: 18,
|
];
|
||||||
cursor: cfg.style.cursor,
|
},
|
||||||
},
|
},
|
||||||
name: 'text',
|
'rect'
|
||||||
draggable: true
|
);
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return wrapperRect;
|
|
||||||
},
|
|
||||||
|
|
||||||
getAnchorPoints() {
|
|
||||||
return [
|
|
||||||
[0.5, 0],
|
|
||||||
[5 / 6, 0],
|
|
||||||
[5 / 6, 0.5],
|
|
||||||
[1, 0.5],
|
|
||||||
[5 / 6, 1],
|
|
||||||
[0.5, 1],
|
|
||||||
[0, 0.5],
|
|
||||||
[1 / 3, 1]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}, 'rect');
|
|
||||||
|
|||||||
@ -1,90 +1,89 @@
|
|||||||
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) {
|
||||||
const labelStyle = (cfg.labelCfg && cfg.labelCfg.style) || {};
|
const labelStyle = (cfg.labelCfg && cfg.labelCfg.style) || {};
|
||||||
|
|
||||||
const bgRect = group.addShape('rect', {
|
const bgRect = group.addShape('rect', {
|
||||||
attrs: {
|
attrs: {
|
||||||
x: 0,
|
x: 0,
|
||||||
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', {
|
||||||
attrs: {
|
attrs: {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
return keyShape;
|
return keyShape;
|
||||||
},
|
},
|
||||||
|
|
||||||
getPath(cfg) {
|
getPath(cfg) {
|
||||||
let width = cfg.size[0],
|
let width = cfg.size[0],
|
||||||
height = cfg.size[1],
|
height = cfg.size[1],
|
||||||
arrowWidth = width + 4,
|
arrowWidth = width + 4,
|
||||||
arrowHeight = height * 0.3;
|
arrowHeight = height * 0.3;
|
||||||
|
|
||||||
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;
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
@ -8,185 +8,182 @@
|
|||||||
*/
|
*/
|
||||||
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];
|
||||||
|
|
||||||
const width = cfg.size[0],
|
const width = cfg.size[0],
|
||||||
height = cfg.size[1];
|
height = cfg.size[1];
|
||||||
|
|
||||||
const wrapperRect = group.addShape('rect', {
|
const wrapperRect = group.addShape('rect', {
|
||||||
attrs: {
|
attrs: {
|
||||||
x: width / 2,
|
x: width / 2,
|
||||||
y: height / 2,
|
y: height / 2,
|
||||||
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', {
|
||||||
attrs: {
|
attrs: {
|
||||||
x: width / 2,
|
x: width / 2,
|
||||||
y: height / 2,
|
y: height / 2,
|
||||||
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', {
|
||||||
attrs: {
|
attrs: {
|
||||||
x: width * (5 / 6),
|
x: width * (5 / 6),
|
||||||
y: height / 2,
|
y: height / 2,
|
||||||
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),
|
||||||
y: 0,
|
y: 0,
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
textBaseline: 'middle',
|
textBaseline: 'middle',
|
||||||
text: cfg.rootLabel[0],
|
text: cfg.rootLabel[0],
|
||||||
fill: style.fill || '#bbb',
|
fill: style.fill || '#bbb',
|
||||||
fontSize: style.fontSize || 16,
|
fontSize: style.fontSize || 16,
|
||||||
fontStyle: 'italic',
|
fontStyle: 'italic',
|
||||||
cursor: cfg.style.cursor,
|
cursor: cfg.style.cursor,
|
||||||
},
|
},
|
||||||
name: 'text',
|
name: 'text',
|
||||||
draggable: true
|
draggable: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
group.addShape('text', {
|
group.addShape('text', {
|
||||||
attrs: {
|
attrs: {
|
||||||
x: width,
|
x: width,
|
||||||
y: 0,
|
y: 0,
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
textBaseline: 'middle',
|
textBaseline: 'middle',
|
||||||
text: cfg.rootLabel[1],
|
text: cfg.rootLabel[1],
|
||||||
fill: style.fill || '#bbb',
|
fill: style.fill || '#bbb',
|
||||||
fontSize: style.fontSize || 16,
|
fontSize: style.fontSize || 16,
|
||||||
fontStyle: 'italic',
|
fontStyle: 'italic',
|
||||||
cursor: cfg.style.cursor,
|
cursor: cfg.style.cursor,
|
||||||
},
|
},
|
||||||
name: 'text',
|
name: 'text',
|
||||||
draggable: true
|
draggable: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
group.addShape('text', {
|
group.addShape('text', {
|
||||||
attrs: {
|
attrs: {
|
||||||
x: width * (4 / 3),
|
x: width * (4 / 3),
|
||||||
y: 0,
|
y: 0,
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
textBaseline: 'middle',
|
textBaseline: 'middle',
|
||||||
text: cfg.rootLabel[2],
|
text: cfg.rootLabel[2],
|
||||||
fill: style.fill || '#bbb',
|
fill: style.fill || '#bbb',
|
||||||
fontSize: style.fontSize || 16,
|
fontSize: style.fontSize || 16,
|
||||||
fontStyle: 'italic',
|
fontStyle: 'italic',
|
||||||
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),
|
||||||
y: height,
|
y: height,
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
textBaseline: 'middle',
|
textBaseline: 'middle',
|
||||||
text: cfg.index,
|
text: cfg.index,
|
||||||
fill: style.fill || '#bbb',
|
fill: style.fill || '#bbb',
|
||||||
fontSize: style.fontSize || 16,
|
fontSize: style.fontSize || 16,
|
||||||
fontStyle: 'italic',
|
fontStyle: 'italic',
|
||||||
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),
|
||||||
y: height,
|
y: height,
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
textBaseline: 'middle',
|
textBaseline: 'middle',
|
||||||
text: cfg.label[0],
|
text: cfg.label[0],
|
||||||
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,
|
||||||
});
|
});
|
||||||
|
|
||||||
group.addShape('text', {
|
group.addShape('text', {
|
||||||
attrs: {
|
attrs: {
|
||||||
x: width,
|
x: width,
|
||||||
y: height,
|
y: height,
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
textBaseline: 'middle',
|
textBaseline: 'middle',
|
||||||
text: cfg.label[1],
|
text: cfg.label[1],
|
||||||
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,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//节点没有后续指针时
|
//节点没有后续指针时
|
||||||
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;
|
getAnchorPoints() {
|
||||||
},
|
return [
|
||||||
|
[0.5, 0],
|
||||||
getAnchorPoints() {
|
[5 / 6, 0.5],
|
||||||
return [
|
[0.5, 1],
|
||||||
[0.5, 0],
|
[0, 0.5],
|
||||||
[5 / 6, 0.5],
|
];
|
||||||
[0.5, 1],
|
},
|
||||||
[0, 0.5]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
@ -1,100 +1,103 @@
|
|||||||
import { Util } from '../Common/util';
|
import { Util } from '../Common/util';
|
||||||
|
|
||||||
|
export default Util.registerShape(
|
||||||
|
'tri-tree-node',
|
||||||
|
{
|
||||||
|
draw(cfg, group) {
|
||||||
|
cfg.size = cfg.size;
|
||||||
|
|
||||||
export default Util.registerShape('tri-tree-node', {
|
const width = cfg.size[0],
|
||||||
draw(cfg, group) {
|
height = cfg.size[1];
|
||||||
cfg.size = cfg.size;
|
|
||||||
|
|
||||||
const width = cfg.size[0],
|
const wrapperRect = group.addShape('rect', {
|
||||||
height = cfg.size[1];
|
attrs: {
|
||||||
|
x: width / 2,
|
||||||
|
y: height / 2,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
stroke: cfg.style.stroke || '#333',
|
||||||
|
cursor: cfg.style.cursor,
|
||||||
|
fill: cfg.style.backgroundFill || '#eee',
|
||||||
|
},
|
||||||
|
name: 'wrapper',
|
||||||
|
});
|
||||||
|
|
||||||
const wrapperRect = group.addShape('rect', {
|
group.addShape('rect', {
|
||||||
attrs: {
|
attrs: {
|
||||||
x: width / 2,
|
x: width / 4 + width / 2,
|
||||||
y: height / 2,
|
y: height / 2,
|
||||||
width: width,
|
width: width / 2,
|
||||||
height: height,
|
height: height / 4,
|
||||||
stroke: cfg.style.stroke || '#333',
|
fill: '#eee',
|
||||||
cursor: cfg.style.cursor,
|
stroke: cfg.style.stroke || '#333',
|
||||||
fill: cfg.style.backgroundFill || '#eee'
|
cursor: cfg.style.cursor,
|
||||||
},
|
},
|
||||||
name: 'wrapper'
|
name: 'top',
|
||||||
});
|
draggable: true,
|
||||||
|
});
|
||||||
|
|
||||||
group.addShape('rect', {
|
group.addShape('rect', {
|
||||||
attrs: {
|
attrs: {
|
||||||
x: width / 4 + width / 2,
|
x: width / 4 + width / 2,
|
||||||
y: height / 2,
|
y: height / 2 + height / 4,
|
||||||
width: width / 2,
|
width: width / 2,
|
||||||
height: height / 4,
|
height: (height / 4) * 3,
|
||||||
fill: '#eee',
|
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: 'top',
|
name: 'bottom',
|
||||||
draggable: true
|
draggable: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
group.addShape('rect', {
|
if (cfg.label) {
|
||||||
attrs: {
|
const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
|
||||||
x: width / 4 + width / 2,
|
group.addShape('text', {
|
||||||
y: height / 2 + height / 4,
|
attrs: {
|
||||||
width: width / 2,
|
x: width, // 居中
|
||||||
height: height / 4 * 3,
|
y: height + height / 8,
|
||||||
fill: cfg.color || cfg.style.fill,
|
textAlign: 'center',
|
||||||
stroke: cfg.style.stroke || '#333',
|
textBaseline: 'middle',
|
||||||
cursor: cfg.style.cursor
|
text: cfg.label,
|
||||||
},
|
fill: style.fill || '#000',
|
||||||
name: 'bottom',
|
fontSize: style.fontSize || 16,
|
||||||
draggable: true
|
cursor: cfg.style.cursor,
|
||||||
});
|
},
|
||||||
|
name: 'text',
|
||||||
|
draggable: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (cfg.label) {
|
if (cfg.root) {
|
||||||
const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
|
const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
|
||||||
group.addShape('text', {
|
group.addShape('text', {
|
||||||
attrs: {
|
attrs: {
|
||||||
x: width, // 居中
|
x: width, // 居中
|
||||||
y: height + height / 8,
|
y: (height / 4) * 3,
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
textBaseline: 'middle',
|
textBaseline: 'middle',
|
||||||
text: cfg.label,
|
text: '^',
|
||||||
fill: style.fill || '#000',
|
fill: style.fill || '#000',
|
||||||
fontSize: style.fontSize || 16,
|
fontSize: style.fontSize || 14,
|
||||||
cursor: cfg.style.cursor
|
cursor: cfg.style.cursor,
|
||||||
},
|
},
|
||||||
name: 'text',
|
name: 'parent',
|
||||||
draggable: true
|
draggable: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg.root) {
|
return wrapperRect;
|
||||||
const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
|
},
|
||||||
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
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return wrapperRect;
|
getAnchorPoints() {
|
||||||
},
|
return [
|
||||||
|
[0.125, 0.5],
|
||||||
getAnchorPoints() {
|
[0.875, 0.5],
|
||||||
return [
|
[0.5, 1],
|
||||||
[0.125, 0.5],
|
[0.5, 0],
|
||||||
[0.875, 0.5],
|
[0.5, 0.125],
|
||||||
[0.5, 1],
|
];
|
||||||
[0.5, 0],
|
},
|
||||||
[0.5, 0.125]
|
},
|
||||||
];
|
'rect'
|
||||||
},
|
);
|
||||||
}, 'rect');
|
|
||||||
|
|||||||
@ -1,138 +1,140 @@
|
|||||||
import { Util } from '../Common/util';
|
import { Util } from '../Common/util';
|
||||||
|
|
||||||
|
export default Util.registerShape(
|
||||||
|
'two-cell-node',
|
||||||
|
{
|
||||||
|
draw(cfg, group) {
|
||||||
|
cfg.size = cfg.size || [30, 10];
|
||||||
|
|
||||||
|
const width = cfg.size[0],
|
||||||
|
height = cfg.size[1];
|
||||||
|
|
||||||
export default Util.registerShape('two-cell-node', {
|
const wrapperRect = group.addShape('rect', {
|
||||||
draw(cfg, group) {
|
attrs: {
|
||||||
cfg.size = cfg.size || [30, 10];
|
x: width / 2,
|
||||||
|
y: height / 2,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
stroke: cfg.style.stroke,
|
||||||
|
fill: cfg.style.backgroundFill || '#eee',
|
||||||
|
},
|
||||||
|
name: 'wrapper',
|
||||||
|
});
|
||||||
|
|
||||||
const width = cfg.size[0],
|
group.addShape('rect', {
|
||||||
height = cfg.size[1];
|
attrs: {
|
||||||
|
x: width / 2,
|
||||||
|
y: height / 2,
|
||||||
|
width: width / 2,
|
||||||
|
height: height,
|
||||||
|
fill: cfg.style.fill,
|
||||||
|
stroke: cfg.style.stroke,
|
||||||
|
},
|
||||||
|
name: 'left-rect',
|
||||||
|
draggable: true,
|
||||||
|
});
|
||||||
|
|
||||||
const wrapperRect = group.addShape('rect', {
|
const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
|
||||||
attrs: {
|
|
||||||
x: width / 2,
|
|
||||||
y: height / 2,
|
|
||||||
width: width,
|
|
||||||
height: height,
|
|
||||||
stroke: cfg.style.stroke,
|
|
||||||
fill: cfg.style.backgroundFill || '#eee'
|
|
||||||
},
|
|
||||||
name: 'wrapper'
|
|
||||||
});
|
|
||||||
|
|
||||||
group.addShape('rect', {
|
if (cfg.label) {
|
||||||
attrs: {
|
if (Array.isArray(cfg.label)) {
|
||||||
x: width / 2,
|
let tag = cfg.label[0],
|
||||||
y: height / 2,
|
data = cfg.label[1];
|
||||||
width: width / 2,
|
|
||||||
height: height,
|
|
||||||
fill: cfg.style.fill,
|
|
||||||
stroke: cfg.style.stroke
|
|
||||||
},
|
|
||||||
name: 'left-rect',
|
|
||||||
draggable: true
|
|
||||||
});
|
|
||||||
|
|
||||||
const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
|
group.addShape('text', {
|
||||||
|
attrs: {
|
||||||
|
x: width * (3 / 4),
|
||||||
|
y: height,
|
||||||
|
textAlign: 'center',
|
||||||
|
textBaseline: 'middle',
|
||||||
|
text: tag,
|
||||||
|
fill: style.fill || '#000',
|
||||||
|
fontSize: style.fontSize || 16,
|
||||||
|
cursor: cfg.style.cursor,
|
||||||
|
},
|
||||||
|
name: 'text',
|
||||||
|
draggable: true,
|
||||||
|
});
|
||||||
|
|
||||||
if (cfg.label) {
|
group.addShape('text', {
|
||||||
if(Array.isArray(cfg.label)) {
|
attrs: {
|
||||||
let tag = cfg.label[0], data = cfg.label[1];
|
x: width * (5 / 4),
|
||||||
|
y: height,
|
||||||
|
textAlign: 'center',
|
||||||
|
textBaseline: 'middle',
|
||||||
|
text: data,
|
||||||
|
fill: style.fill || '#000',
|
||||||
|
fontSize: style.fontSize || 16,
|
||||||
|
cursor: cfg.style.cursor,
|
||||||
|
},
|
||||||
|
name: 'text',
|
||||||
|
draggable: true,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
group.addShape('text', {
|
||||||
|
attrs: {
|
||||||
|
x: width * (3 / 4),
|
||||||
|
y: height,
|
||||||
|
textAlign: 'center',
|
||||||
|
textBaseline: 'middle',
|
||||||
|
text: cfg.label,
|
||||||
|
fill: style.fill || '#000',
|
||||||
|
fontSize: style.fontSize || 16,
|
||||||
|
cursor: cfg.style.cursor,
|
||||||
|
},
|
||||||
|
name: 'text',
|
||||||
|
draggable: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
group.addShape('text', {
|
//图 数据结构中没有后续指针
|
||||||
attrs: {
|
if (cfg.id.includes('tableHeadNode') && !cfg.headNext) {
|
||||||
x: width * (3 / 4),
|
group.addShape('text', {
|
||||||
y: height,
|
attrs: {
|
||||||
textAlign: 'center',
|
x: width * (5 / 4),
|
||||||
textBaseline: 'middle',
|
y: height * (8 / 7),
|
||||||
text: tag,
|
textAlign: 'center',
|
||||||
fill: style.fill || '#000',
|
textBaseline: 'middle',
|
||||||
fontSize: style.fontSize || 16,
|
text: '^',
|
||||||
cursor: cfg.style.cursor,
|
fill: style.fill || '#000',
|
||||||
},
|
fontSize: 20,
|
||||||
name: 'text',
|
cursor: cfg.style.cursor,
|
||||||
draggable: true
|
},
|
||||||
});
|
name: 'text',
|
||||||
|
draggable: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
group.addShape('text', {
|
//哈希表 数据结构中没有后续指针
|
||||||
attrs: {
|
if (cfg.id.includes('head') && !cfg.start) {
|
||||||
x: width * (5 / 4),
|
group.addShape('text', {
|
||||||
y: height,
|
attrs: {
|
||||||
textAlign: 'center',
|
x: width * (5 / 4),
|
||||||
textBaseline: 'middle',
|
y: height * (8 / 7),
|
||||||
text: data,
|
textAlign: 'center',
|
||||||
fill: style.fill || '#000',
|
textBaseline: 'middle',
|
||||||
fontSize: style.fontSize || 16,
|
text: '^',
|
||||||
cursor: cfg.style.cursor,
|
fill: style.fill || '#000',
|
||||||
},
|
fontSize: 20,
|
||||||
name: 'text',
|
cursor: cfg.style.cursor,
|
||||||
draggable: true
|
},
|
||||||
});
|
name: 'text',
|
||||||
}
|
draggable: true,
|
||||||
else {
|
});
|
||||||
group.addShape('text', {
|
}
|
||||||
attrs: {
|
|
||||||
x: width * (3 / 4),
|
|
||||||
y: height,
|
|
||||||
textAlign: 'center',
|
|
||||||
textBaseline: 'middle',
|
|
||||||
text: cfg.label,
|
|
||||||
fill: style.fill || '#000',
|
|
||||||
fontSize: style.fontSize || 16,
|
|
||||||
cursor: cfg.style.cursor,
|
|
||||||
},
|
|
||||||
name: 'text',
|
|
||||||
draggable: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//图 数据结构中没有后续指针
|
return wrapperRect;
|
||||||
if(cfg.id.includes('tableHeadNode') && !cfg.headNext){
|
},
|
||||||
group.addShape('text', {
|
|
||||||
attrs: {
|
|
||||||
x: width * (5 / 4),
|
|
||||||
y: height * ( 8 / 7),
|
|
||||||
textAlign: 'center',
|
|
||||||
textBaseline: 'middle',
|
|
||||||
text: '^',
|
|
||||||
fill: style.fill || '#000',
|
|
||||||
fontSize: 20,
|
|
||||||
cursor: cfg.style.cursor,
|
|
||||||
},
|
|
||||||
name: 'text',
|
|
||||||
draggable: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//哈希表 数据结构中没有后续指针
|
getAnchorPoints() {
|
||||||
if(cfg.id.includes('head') && !cfg.start){
|
return [
|
||||||
group.addShape('text', {
|
[0.5, 0],
|
||||||
attrs: {
|
[3 / 4, 0.5],
|
||||||
x: width * (5 / 4),
|
[0.5, 1],
|
||||||
y: height * ( 8 / 7),
|
[0, 0.5],
|
||||||
textAlign: 'center',
|
];
|
||||||
textBaseline: 'middle',
|
},
|
||||||
text: '^',
|
},
|
||||||
fill: style.fill || '#000',
|
'rect'
|
||||||
fontSize: 20,
|
);
|
||||||
cursor: cfg.style.cursor,
|
|
||||||
},
|
|
||||||
name: 'text',
|
|
||||||
draggable: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return wrapperRect;
|
|
||||||
},
|
|
||||||
|
|
||||||
getAnchorPoints() {
|
|
||||||
return [
|
|
||||||
[0.5, 0],
|
|
||||||
[3 / 4, 0.5],
|
|
||||||
[0.5, 1],
|
|
||||||
[0, 0.5]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}, 'rect');
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user