StructV2/demoV2/Layouter/LinkList.js

122 lines
2.7 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) {
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 {
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: {
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: {
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: {
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),
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: {
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
layout(elements, layoutOptions) {
for (let i = 0; i < elements.length; i++) {
let node = elements[i],
prev = elements[1 - 1],
width = node.get('size')[0];
if (prev) {
node.set('y', prev.get('y'));
node.set('x', prev.get('x') + layoutOptions.xInterval + width);
}
}
2021-04-16 07:38:52 +00:00
}
2021-07-31 16:43:01 +00:00
});
2021-04-16 07:38:52 +00:00