bug修复

This commit is contained in:
黎智洲
2021-04-20 19:12:41 +08:00
parent 0dcad0f117
commit a623ae7445
20 changed files with 492 additions and 107 deletions
+10 -2
View File
@@ -17,6 +17,14 @@ class Arrays extends Engine {
}
}
},
pointer: {
external: {
offset: 8,
style: {
fill: '#f08a5d'
}
}
},
interaction: {
dragNode: false
}
@@ -41,7 +49,7 @@ const A = function(container) {
return{
engine: new Arrays(container),
data: [[
{ id: 1 },
{ id: 1, external: 'A' },
{ id: 2 },
{ id: 3 },
{ id: 4 },
@@ -56,7 +64,7 @@ const A = function(container) {
{ id: 1 },
{ id: 2 },
{ id: 3 },
{ id: 6 },
{ id: 6, external: 'A' },
{ id: 7 },
{ id: 8 }
]]
+60 -21
View File
@@ -164,27 +164,66 @@ class BinaryTree extends Engine {
const BTree = function(container) {
return{
engine: new BinaryTree(container),
data: [[
{ id: 1, child: [2, 3], root: true, external: ['treeA', 'gear'] },
{ id: 2, child: [null, 6] },
{ id: 3, child: [5, 4] },
{ id: 4, external: 'foo' },
{ id: 5 },
{ id: 6, external: 'bar', child: [null, 7] },
{ id: 7 },
{ id: 8, child: [9, 10], root: true },
{ id: 9, child: [11, null] },
{ id: 10 },
{ id: 11 }
],
[
{ id: 1, child: [2, 3], root: true, external: 'treeA' },
{ id: 2, external: 'gear' },
{ id: 3, child: [5, 4] },
{ id: 4, external: 'foo' },
{ id: 5, child: [12, 13] },
{ id: 12 }, { id: 13 }
]]
data: [
// [
// { id: 1, child: [2, 3], root: true, external: ['treeA', 'gear'] },
// { id: 2, child: [null, 6] },
// { id: 3, child: [5, 4] },
// { id: 4, external: 'foo' },
// { id: 5 },
// { id: 6, external: 'bar', child: [null, 7] },
// { id: 7 },
// { id: 8, child: [9, 10], root: true },
// { id: 9, child: [11, null] },
// { id: 10 },
// { id: 11 }
// ],
// [
// { id: 1, child: [2, 3], root: true, external: 'treeA' },
// { id: 2, external: 'gear' },
// { id: 3, child: [5, 4] },
// { id: 4, external: 'foo' },
// { id: 5, child: [12, 13] },
// { id: 12 }, { id: 13 }
// ]
[
{
"external": [
"r",
"T1"
],
"child": [
6385376,
6385424
],
"id": 6385328,
"name": "T1",
"data": "Z",
"root": true
},
{
"child": [
0,
0
],
"id": 6385376,
"name": "T1.lchild",
"data": "A"
},
{
"external": [
"t"
],
"child": [
0,
0
],
"id": 6385424,
"name": "T1.rchild",
"data": "B"
}
]
]
}
};
+162
View File
@@ -0,0 +1,162 @@
/**
* 连地址哈希表
*/
class ChainHashTable extends Engine {
defineOptions() {
return {
element: {
head: {
type: 'two-cell-node',
label: '[id]',
size: [70, 40],
style: {
stroke: '#333',
fill: '#b83b5e'
}
},
node: {
type: 'link-list-node',
label: '[id]',
size: [60, 30],
style: {
stroke: '#333',
fill: '#b83b5e'
}
}
},
link: {
start: {
type: 'line',
sourceAnchor: 1,
targetAnchor: 0,
style: {
stroke: '#333',
endArrow: {
path: G6.Arrow.triangle(8, 6, 0),
fill: '#333'
},
startArrow: {
path: G6.Arrow.circle(2, -1),
fill: '#333'
}
}
},
next: {
type: 'line',
sourceAnchor: 1,
targetAnchor: 0,
style: {
stroke: '#333',
endArrow: {
path: G6.Arrow.triangle(8, 6, 0),
fill: '#333'
},
startArrow: {
path: G6.Arrow.circle(2, -1),
fill: '#333'
}
}
}
},
pointer: {
external: {
offset: 8,
style: {
fill: '#f08a5d'
}
}
},
layout: {
xInterval: 50,
yInterval: 50
},
interaction: {
dragNode: ['node']
}
};
}
/**
* 对子树进行递归布局
* @param node
* @param parent
*/
layoutItem(node, prev, layoutOptions) {
if(!node) {
return null;
}
let width = node.get('size')[0];
if(prev) {
node.set('y', prev.get('y'));
node.set('x', prev.get('x') + layoutOptions.xInterval + width);
}
if(node.next) {
this.layoutItem(node.next, node, layoutOptions);
}
}
layout(elements, layoutOptions) {
let headNode = elements.head;
for(let i = 0; i < headNode.length; i++) {
let node = headNode[i],
height = node.get('size')[1];
node.set('y', node.get('y') + i * height);
if(node.start) {
let y = node.get('y') + height - node.start.get('size')[1],
x = layoutOptions.xInterval * 2.5;
node.start.set({ x, y });
this.layoutItem(node.start, null, layoutOptions);
}
}
}
}
const CHT = function(container) {
return{
engine: new ChainHashTable(container),
data: [
{
head: [{
id: 0,
start: 'node#0'
}, {
id: 2,
start: 'node#2'
}],
node: [{
id: 0,
next: 1
}, {
id: 1
},{
id: 2,
next: 3
}, {
id: 3
}]
},
{
}
]
}
};
@@ -1,26 +1,13 @@
/**
* 单链表
*/
class HashLinkList extends Engine {
class LinkStack extends Engine {
defineOptions() {
return {
element: {
headNode: {
type: 'link-list-node',
label: '[id]',
size: [60, 30],
style: {
stroke: '#333',
fill: '#b83b5e'
}
},
node: {
default: {
type: 'link-list-node',
label: '[id]',
size: [60, 30],
@@ -34,7 +21,7 @@
next: {
type: 'line',
sourceAnchor: 1,
targetAnchor: 0,
targetAnchor: 2,
style: {
stroke: '#333',
endArrow: {
@@ -50,7 +37,7 @@
},
pointer: {
external: {
offset: 14,
offset: 8,
style: {
fill: '#f08a5d'
}
@@ -58,7 +45,7 @@
},
layout: {
xInterval: 50,
yInterval: 50
yInterval: 30
}
};
}
@@ -74,11 +61,11 @@
return null;
}
let width = node.get('size')[0];
let height = node.get('size')[1];
if(prev) {
node.set('y', prev.get('y'));
node.set('x', prev.get('x') + layoutOptions.xInterval + width);
node.set('x', prev.get('x'));
node.set('y', prev.get('y') + layoutOptions.yInterval + height);
}
if(node.next) {
@@ -103,20 +90,20 @@
for(i = 0; i < rootNodes.length; i++) {
let root = rootNodes[i],
height = root.get('size')[1];
width = root.get('size')[0];
root.set('y', root.get('y') + i * (layoutOptions.yInterval + height));
root.set('x', root.get('x') + i * (layoutOptions.xInterval + width));
this.layoutItem(root, null, layoutOptions);
}
}
}
const LList = function(container) {
const LStack = function(container) {
return{
engine: new LinkList(container),
engine: new LinkStack(container),
data: [[
{ id: 1, root: true, next: 2, external: ['gg'] },
{ id: 1, root: true, next: 2 },
{ id: 2, next: 3 },
{ id: 3, next: 4 },
{ id: 4, next: 5 },
@@ -128,7 +115,7 @@ const LList = function(container) {
{ id: 10 }
],
[
{ id: 1, root: true, next: 2, external: ['gg'] },
{ id: 1, root: true, next: 2 },
{ id: 2, next: 3 },
{ id: 3, next: 6 },
{ id: 6, next: 7 },
+71
View File
@@ -0,0 +1,71 @@
class Stack extends Engine {
defineOptions() {
return {
element: {
default: {
type: 'rect',
label: '[id]',
size: [60, 30],
style: {
stroke: '#333',
fill: '#95e1d3'
}
}
},
pointer: {
external: {
offset: 8,
style: {
fill: '#f08a5d'
}
}
},
interaction: {
dragNode: false
}
};
}
layout(elements, layoutOptions) {
let blocks = elements.default;
for(let i = 1; i < blocks.length; i++) {
let item = blocks[i],
prev = blocks[i - 1],
height = item.get('size')[1];
item.set('y', prev.get('y') + height);
}
}
}
const St = function(container) {
return{
engine: new Stack(container),
data: [[
{ id: 1 },
{ id: 2 },
{ id: 3 },
{ id: 4 },
{ id: 5 },
{ id: 6 },
{ id: 7 },
{ id: 8 },
{ id: 9 },
{ id: 10 }
],
[
{ id: 1 },
{ id: 2 },
{ id: 3 },
{ id: 6 },
{ id: 7 },
{ id: 8 }
]]
}
};
+1 -1
View File
@@ -37,7 +37,7 @@ class LinkList extends Engine {
},
pointer: {
external: {
offset: 14,
offset: 8,
style: {
fill: '#f08a5d'
}