2021-04-16 07:38:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 单链表
|
|
|
|
*/
|
2021-10-29 07:46:18 +00:00
|
|
|
SV.registerLayout('LinkStack', {
|
2021-07-31 16:43:01 +00:00
|
|
|
sourcesPreprocess(sources) {
|
|
|
|
const headNode = sources[0];
|
|
|
|
|
|
|
|
if(headNode.external) {
|
|
|
|
headNode.headExternal = headNode.external;
|
|
|
|
delete headNode.external;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sources;
|
|
|
|
},
|
|
|
|
|
2021-04-16 07:38:52 +00:00
|
|
|
defineOptions() {
|
|
|
|
return {
|
|
|
|
element: {
|
2021-04-20 11:12:41 +00:00
|
|
|
default: {
|
2021-04-16 07:38:52 +00:00
|
|
|
type: 'link-list-node',
|
2021-08-24 15:53:43 +00:00
|
|
|
label: '[id]',
|
2021-04-16 07:38:52 +00:00
|
|
|
size: [60, 30],
|
|
|
|
style: {
|
|
|
|
stroke: '#333',
|
|
|
|
fill: '#b83b5e'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
link: {
|
|
|
|
next: {
|
|
|
|
type: 'line',
|
2021-07-31 16:43:01 +00:00
|
|
|
sourceAnchor: 2,
|
|
|
|
targetAnchor: 4,
|
2021-04-16 07:38:52 +00:00
|
|
|
style: {
|
|
|
|
stroke: '#333',
|
|
|
|
endArrow: {
|
|
|
|
path: G6.Arrow.triangle(8, 6, 0),
|
|
|
|
fill: '#333'
|
|
|
|
},
|
|
|
|
startArrow: {
|
|
|
|
path: G6.Arrow.circle(2, -1),
|
|
|
|
fill: '#333'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-07-31 16:43:01 +00:00
|
|
|
marker: {
|
|
|
|
headExternal: {
|
|
|
|
anchor: 5,
|
|
|
|
type: 'pointer',
|
|
|
|
offset: 8,
|
|
|
|
style: {
|
|
|
|
fill: '#f08a5d'
|
|
|
|
}
|
|
|
|
},
|
2021-04-16 07:38:52 +00:00
|
|
|
external: {
|
2021-07-31 16:43:01 +00:00
|
|
|
anchor: 3,
|
|
|
|
type: 'pointer',
|
2021-04-20 11:12:41 +00:00
|
|
|
offset: 8,
|
2021-04-16 07:38:52 +00:00
|
|
|
style: {
|
|
|
|
fill: '#f08a5d'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
layout: {
|
2021-04-20 11:12:41 +00:00
|
|
|
yInterval: 30
|
2021-04-16 07:38:52 +00:00
|
|
|
}
|
|
|
|
};
|
2021-07-31 16:43:01 +00:00
|
|
|
},
|
2021-04-16 07:38:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 对子树进行递归布局
|
|
|
|
* @param node
|
|
|
|
* @param parent
|
|
|
|
*/
|
|
|
|
layoutItem(node, prev, layoutOptions) {
|
|
|
|
if(!node) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-04-20 11:12:41 +00:00
|
|
|
let height = node.get('size')[1];
|
2021-04-16 07:38:52 +00:00
|
|
|
|
|
|
|
if(prev) {
|
2021-04-20 11:12:41 +00:00
|
|
|
node.set('x', prev.get('x'));
|
2021-07-31 16:43:01 +00:00
|
|
|
node.set('y', prev.get('y') - layoutOptions.yInterval - height);
|
2021-04-16 07:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(node.next) {
|
|
|
|
this.layoutItem(node.next, node, layoutOptions);
|
|
|
|
}
|
2021-07-31 16:43:01 +00:00
|
|
|
},
|
2021-04-16 07:38:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
layout(elements, layoutOptions) {
|
2021-07-31 16:43:01 +00:00
|
|
|
this.layoutItem(elements[0], null, layoutOptions);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-04-16 07:38:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|