StructV2/demoV2/Layouter/Stack.js
2021-12-02 17:19:46 +08:00

72 lines
1.7 KiB
JavaScript

SV.registerLayout('Stack', {
sourcesPreprocess(sources, options) {
const stackBottomNode = sources[sources.length - 1];
if(stackBottomNode.external) {
stackBottomNode.bottomExternal = stackBottomNode.external;
delete stackBottomNode.external;
}
return sources;
},
defineOptions() {
return {
element: {
default: {
type: 'indexed-node',
label: '[id]',
size: [60, 30],
style: {
stroke: '#333',
fill: '#95e1d3'
}
}
},
marker: {
external: {
type: 'pointer',
anchor: 1,
style: {
fill: '#f08a5d'
}
},
bottomExternal: {
type: 'pointer',
anchor: 2,
style: {
fill: '#f08a5d'
}
},
cursor: {
type: 'cursor',
anchor: 1,
style: {
fill: '#f08a5d'
}
}
},
behavior: {
dragNode: false
}
};
},
layout(elements, layoutOptions) {
let blocks = elements;
for(let i = 1; i < blocks.length; i++) {
let item = blocks[i],
prev = blocks[i - 1],
height = item.get('size')[1];
item.set('y', prev.get('y') + height);
}
}
})