From a72691449ce30a6cef972542bece97137885d134 Mon Sep 17 00:00:00 2001 From: "douboer@gmail.com" Date: Sat, 14 Feb 2026 11:47:31 +0800 Subject: [PATCH] update at 2026-02-14 11:47:31 --- miniapp/pages/index/index.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/miniapp/pages/index/index.js b/miniapp/pages/index/index.js index 8289ea6..c62cd20 100644 --- a/miniapp/pages/index/index.js +++ b/miniapp/pages/index/index.js @@ -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); - } else if (targetAlignMode === 'bottom') { - startY = padding + Math.max(0, sourceSpanHeight - blockHeight); - } + if (targetAlignMode === 'middle') { + startY = padding + Math.max(0, (globalSpanHeight - blockHeight) / 2); + } else if (targetAlignMode === 'bottom') { + startY = padding + Math.max(0, globalSpanHeight - blockHeight); } let cursorY = startY;