StructV2/demoV2/Layouter/LinkList.js

135 lines
2.9 KiB
JavaScript
Raw Normal View History

2021-04-16 07:38:52 +00:00
2021-07-31 16:43:01 +00:00
SV.registerLayouter('LinkList', {
sourcesPreprocess(sources) {
let root = sources[0];
if(root.external) {
root.rootExternal = root.external;
delete root.external;
}
return sources;
},
2021-04-16 07:38:52 +00:00
defineOptions() {
return {
element: {
default: {
type: 'link-list-node',
2021-08-17 15:44:28 +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: {
next: {
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: {
path: G6.Arrow.circle(2, -1),
fill: '#333'
}
}
2021-04-24 12:48:54 +00:00
},
loopNext: {
type: 'arc',
curveOffset: 50,
2021-07-31 16:43:01 +00:00
sourceAnchor: 2,
targetAnchor: 4,
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: {
path: G6.Arrow.circle(2, -1),
fill: '#333'
}
}
2021-04-16 07:38:52 +00:00
}
},
2021-07-31 16:43:01 +00:00
marker: {
rootExternal: {
type: 'cursor',
anchor: 6,
offset: 8,
style: {
fill: '#f08a5d'
}
},
2021-04-16 07:38:52 +00:00
external: {
2021-07-31 16:43:01 +00:00
type: 'cursor',
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
/**
* 对子树进行递归布局
* @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);
}
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
let root = elements[0];
2021-04-16 07:38:52 +00:00
2021-07-31 16:43:01 +00:00
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