update at 2026-02-14 11:47:31

This commit is contained in:
douboer@gmail.com
2026-02-14 11:47:31 +08:00
parent 78201cf7c7
commit a72691449c

View File

@@ -539,27 +539,31 @@ function buildSankeyLayout(links, width, height, renderOptions) {
const columnNodeHeightMap = {};
const columnGapMap = {};
const columnBlockHeightMap = {};
const baseColumnBlockHeightMap = {};
columns.forEach((names, depth) => {
const totalNodeHeight = names.reduce((sum, name) => sum + (nodeValueMap[name] || 0) * unitHeight, 0);
columnNodeHeightMap[depth] = totalNodeHeight;
baseColumnBlockHeightMap[depth] =
totalNodeHeight + Math.max(0, names.length - 1) * effectiveGap;
});
const globalSpanHeight = columns.reduce((max, _names, depth) => {
return Math.max(max, baseColumnBlockHeightMap[depth] || 0);
}, 0);
columns.forEach((names, depth) => {
const totalNodeHeight = columnNodeHeightMap[depth] || 0;
let columnGap = effectiveGap;
if (depth === maxDepth && targetAlignMode === 'between' && names.length > 1) {
const sourceNames = columns[0] || [];
const sourceTotalNodeHeight = sourceNames.reduce(
(sum, name) => sum + (nodeValueMap[name] || 0) * unitHeight,
0
);
const sourceSpanHeight =
sourceTotalNodeHeight + Math.max(0, sourceNames.length - 1) * effectiveGap;
columnGap = (sourceSpanHeight - totalNodeHeight) / (names.length - 1);
if (targetAlignMode === 'between' && names.length > 1) {
// 全局两端对齐:每一列都按同一纵向跨度拉伸。
columnGap = (globalSpanHeight - totalNodeHeight) / (names.length - 1);
}
columnGap = Math.max(0, columnGap);
const blockHeight = totalNodeHeight + Math.max(0, names.length - 1) * columnGap;
columnNodeHeightMap[depth] = totalNodeHeight;
columnGapMap[depth] = columnGap;
columnBlockHeightMap[depth] = blockHeight;
});
const sourceSpanHeight = columnBlockHeightMap[0] || 0;
const leftX = padding;
const rightX = Math.max(padding + nodeWidth + 80, width - padding - nodeWidth);
const columnStep = maxDepth > 0 ? (rightX - leftX) / maxDepth : 0;
@@ -570,12 +574,10 @@ function buildSankeyLayout(links, width, height, renderOptions) {
const blockHeight = columnBlockHeightMap[depth] || 0;
const columnGap = columnGapMap[depth] || 0;
let startY = padding;
if (depth === maxDepth) {
if (targetAlignMode === 'middle') {
startY = padding + Math.max(0, (sourceSpanHeight - blockHeight) / 2);
startY = padding + Math.max(0, (globalSpanHeight - blockHeight) / 2);
} else if (targetAlignMode === 'bottom') {
startY = padding + Math.max(0, sourceSpanHeight - blockHeight);
}
startY = padding + Math.max(0, globalSpanHeight - blockHeight);
}
let cursorY = startY;