diff --git a/miniapp/pages/index/index.js b/miniapp/pages/index/index.js index 34a6d2e..689d992 100644 --- a/miniapp/pages/index/index.js +++ b/miniapp/pages/index/index.js @@ -401,6 +401,8 @@ function buildSankeyLayout(links, width, height, renderOptions) { const sourceGapCount = Math.max(0, sourceNames.length - 1); const sourceContentHeight = Math.max(10, height - padding * 2 - sourceGapCount * nodeGap); const sourceUnitHeight = sourceContentHeight / totalValue; + const sourceTotalNodeHeight = totalValue * sourceUnitHeight; + const sourceSpanHeight = sourceTotalNodeHeight + sourceGapCount * nodeGap; const sourcePos = {}; let sourceCursorY = padding; @@ -414,13 +416,19 @@ function buildSankeyLayout(links, width, height, renderOptions) { const targetTotalValue = targetNames.reduce((sum, name) => sum + targetValueMap[name], 0); const targetUnitHeight = targetTotalValue > 0 ? sourceUnitHeight : 0; const targetTotalNodeHeight = targetTotalValue * targetUnitHeight; - const targetBlockHeight = targetTotalNodeHeight + targetGapCount * nodeGap; - const layoutHeight = Math.max(10, height - padding * 2); + let targetGap = nodeGap; + if (targetAlignMode === 'between' && targetNames.length > 1) { + // 与 Web 端一致:两端对齐时,目标列整体高度与 source 列跨度一致。 + targetGap = (sourceSpanHeight - targetTotalNodeHeight) / (targetNames.length - 1); + } + targetGap = Math.max(0, targetGap); + + const targetBlockHeight = targetTotalNodeHeight + targetGapCount * targetGap; let targetStartY = padding; if (targetAlignMode === 'middle') { - targetStartY = padding + Math.max(0, (layoutHeight - targetBlockHeight) / 2); + targetStartY = padding + Math.max(0, (sourceSpanHeight - targetBlockHeight) / 2); } else if (targetAlignMode === 'bottom') { - targetStartY = padding + Math.max(0, layoutHeight - targetBlockHeight); + targetStartY = padding + Math.max(0, sourceSpanHeight - targetBlockHeight); } else if (targetAlignMode === 'top') { targetStartY = padding; } @@ -430,7 +438,7 @@ function buildSankeyLayout(links, width, height, renderOptions) { targetNames.forEach((name) => { const nodeHeight = Math.max(2, targetValueMap[name] * targetUnitHeight); targetPos[name] = { y: targetCursorY, h: nodeHeight }; - targetCursorY += nodeHeight + nodeGap; + targetCursorY += nodeHeight + targetGap; }); const sourceOffset = {};