StructV2/demo/Layouter/Stack.js

79 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-07-31 16:43:01 +00:00
2021-10-29 07:46:18 +00:00
SV.registerLayout('Stack', {
2021-07-31 16:43:01 +00:00
sourcesPreprocess(sources, options) {
const stackBottomNode = sources[sources.length - 1];
if(stackBottomNode.external) {
stackBottomNode.bottomExternal = stackBottomNode.external;
delete stackBottomNode.external;
}
return sources;
},
defineLeakRule(nodes) {
return [];
},
2021-07-31 16:43:01 +00:00
defineOptions() {
return {
element: {
default: {
type: 'array-node',
2021-07-31 16:43:01 +00:00
label: '[id]',
size: [60, 30],
style: {
stroke: '#333',
fill: '#95e1d3'
}
}
},
2021-08-17 15:44:28 +00:00
marker: {
2021-07-31 16:43:01 +00:00
external: {
2021-08-17 15:44:28 +00:00
type: 'pointer',
2021-07-31 16:43:01 +00:00
anchor: 1,
style: {
fill: '#f08a5d'
}
},
bottomExternal: {
2021-08-17 15:44:28 +00:00
type: 'pointer',
2021-07-31 16:43:01 +00:00
anchor: 2,
style: {
fill: '#f08a5d'
}
2021-08-17 15:44:28 +00:00
},
cursor: {
type: 'cursor',
anchor: 1,
style: {
fill: '#f08a5d'
}
2021-07-31 16:43:01 +00:00
}
},
indexLabel: {
index: { position: 'left' }
},
2021-07-31 16:43:01 +00:00
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);
}
}
})