StructV2/demoV2/Layouter/LinkList.js

137 lines
2.9 KiB
JavaScript
Raw Normal View History

2021-04-16 07:38:52 +00:00
2021-10-29 07:46:18 +00:00
SV.registerLayout('LinkList', {
2021-07-31 16:43:01 +00:00
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 {
2021-10-29 07:46:18 +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: {
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: 'quadratic',
curveOffset: -100,
2021-07-31 16:43:01 +00:00
sourceAnchor: 2,
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: {
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: '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: {
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-12-22 13:56:52 +00:00
},
behavior: {
dragNode: false
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;
}
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];
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