2021-04-16 07:38:52 +00:00
|
|
|
|
|
|
|
|
2021-10-29 07:46:18 +00:00
|
|
|
SV.registerLayout('LinkList', {
|
2022-02-19 16:29:26 +00:00
|
|
|
|
2021-07-31 16:43:01 +00:00
|
|
|
sourcesPreprocess(sources) {
|
|
|
|
let root = sources[0];
|
|
|
|
|
2022-02-19 16:29:26 +00:00
|
|
|
if (root.external) {
|
2021-07-31 16:43:01 +00:00
|
|
|
root.rootExternal = root.external;
|
|
|
|
delete root.external;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sources;
|
|
|
|
},
|
|
|
|
|
2021-04-16 07:38:52 +00:00
|
|
|
defineOptions() {
|
|
|
|
return {
|
2022-02-19 16:29:26 +00:00
|
|
|
node: {
|
2021-04-16 07:38:52 +00:00
|
|
|
default: {
|
|
|
|
type: 'link-list-node',
|
2021-09-13 13:35:59 +00:00
|
|
|
label: '[data]',
|
2021-04-16 07:38:52 +00:00
|
|
|
size: [60, 30],
|
|
|
|
style: {
|
|
|
|
stroke: '#333',
|
2021-07-31 16:43:01 +00:00
|
|
|
fill: '#eaffd0',
|
|
|
|
cursor: 'pointer'
|
2021-04-16 07:38:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
link: {
|
2022-02-19 16:29:26 +00:00
|
|
|
next: {
|
2021-04-16 07:38:52 +00:00
|
|
|
type: 'line',
|
2021-07-31 16:43:01 +00:00
|
|
|
sourceAnchor: 2,
|
|
|
|
targetAnchor: 6,
|
2021-04-16 07:38:52 +00:00
|
|
|
style: {
|
|
|
|
stroke: '#333',
|
2021-05-17 06:02:19 +00:00
|
|
|
endArrow: 'default',
|
2021-04-16 07:38:52 +00:00
|
|
|
startArrow: {
|
2022-02-19 16:29:26 +00:00
|
|
|
path: G6.Arrow.circle(2, -1),
|
2021-04-16 07:38:52 +00:00
|
|
|
fill: '#333'
|
|
|
|
}
|
|
|
|
}
|
2021-04-24 12:48:54 +00:00
|
|
|
},
|
|
|
|
loopNext: {
|
2021-12-17 07:58:13 +00:00
|
|
|
type: 'quadratic',
|
|
|
|
curveOffset: -100,
|
2021-07-31 16:43:01 +00:00
|
|
|
sourceAnchor: 2,
|
2021-12-17 07:58:13 +00:00
|
|
|
targetAnchor: 7,
|
2021-04-24 12:48:54 +00:00
|
|
|
style: {
|
|
|
|
stroke: '#333',
|
2021-05-17 06:02:19 +00:00
|
|
|
endArrow: 'default',
|
2021-04-24 12:48:54 +00:00
|
|
|
startArrow: {
|
2022-02-19 16:29:26 +00:00
|
|
|
path: G6.Arrow.circle(2, -1),
|
2021-04-24 12:48:54 +00:00
|
|
|
fill: '#333'
|
|
|
|
}
|
|
|
|
}
|
2021-04-16 07:38:52 +00:00
|
|
|
}
|
|
|
|
},
|
2021-07-31 16:43:01 +00:00
|
|
|
marker: {
|
|
|
|
rootExternal: {
|
2021-08-24 15:53:43 +00:00
|
|
|
type: 'pointer',
|
2021-07-31 16:43:01 +00:00
|
|
|
anchor: 6,
|
|
|
|
offset: 8,
|
|
|
|
style: {
|
|
|
|
fill: '#f08a5d'
|
|
|
|
}
|
|
|
|
},
|
2021-04-16 07:38:52 +00:00
|
|
|
external: {
|
2021-08-24 15:53:43 +00:00
|
|
|
type: 'pointer',
|
2021-07-31 16:43:01 +00:00
|
|
|
anchor: 0,
|
2021-04-20 11:12:41 +00:00
|
|
|
offset: 8,
|
2021-04-16 07:38:52 +00:00
|
|
|
style: {
|
|
|
|
fill: '#f08a5d'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
layout: {
|
|
|
|
xInterval: 50,
|
|
|
|
yInterval: 50
|
|
|
|
}
|
|
|
|
};
|
2021-07-31 16:43:01 +00:00
|
|
|
},
|
2021-04-16 07:38:52 +00:00
|
|
|
|
|
|
|
|
2022-03-02 14:07:27 +00:00
|
|
|
/**
|
|
|
|
* 对子树进行递归布局
|
|
|
|
* @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);
|
2022-02-19 16:29:26 +00:00
|
|
|
}
|
2022-03-02 14:07:27 +00:00
|
|
|
|
|
|
|
if (node.next) {
|
|
|
|
this.layoutItem(node.next, node, layoutOptions);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
layout(elements, layoutOptions) {
|
|
|
|
let root = elements[0];
|
|
|
|
this.layoutItem(root, null, layoutOptions);
|
2021-04-16 07:38:52 +00:00
|
|
|
}
|
2021-07-31 16:43:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-16 07:38:52 +00:00
|
|
|
|
|
|
|
|