update at 2026-02-14 11:29:28
This commit is contained in:
@@ -401,6 +401,8 @@ function buildSankeyLayout(links, width, height, renderOptions) {
|
|||||||
const sourceGapCount = Math.max(0, sourceNames.length - 1);
|
const sourceGapCount = Math.max(0, sourceNames.length - 1);
|
||||||
const sourceContentHeight = Math.max(10, height - padding * 2 - sourceGapCount * nodeGap);
|
const sourceContentHeight = Math.max(10, height - padding * 2 - sourceGapCount * nodeGap);
|
||||||
const sourceUnitHeight = sourceContentHeight / totalValue;
|
const sourceUnitHeight = sourceContentHeight / totalValue;
|
||||||
|
const sourceTotalNodeHeight = totalValue * sourceUnitHeight;
|
||||||
|
const sourceSpanHeight = sourceTotalNodeHeight + sourceGapCount * nodeGap;
|
||||||
|
|
||||||
const sourcePos = {};
|
const sourcePos = {};
|
||||||
let sourceCursorY = padding;
|
let sourceCursorY = padding;
|
||||||
@@ -414,13 +416,19 @@ function buildSankeyLayout(links, width, height, renderOptions) {
|
|||||||
const targetTotalValue = targetNames.reduce((sum, name) => sum + targetValueMap[name], 0);
|
const targetTotalValue = targetNames.reduce((sum, name) => sum + targetValueMap[name], 0);
|
||||||
const targetUnitHeight = targetTotalValue > 0 ? sourceUnitHeight : 0;
|
const targetUnitHeight = targetTotalValue > 0 ? sourceUnitHeight : 0;
|
||||||
const targetTotalNodeHeight = targetTotalValue * targetUnitHeight;
|
const targetTotalNodeHeight = targetTotalValue * targetUnitHeight;
|
||||||
const targetBlockHeight = targetTotalNodeHeight + targetGapCount * nodeGap;
|
let targetGap = nodeGap;
|
||||||
const layoutHeight = Math.max(10, height - padding * 2);
|
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;
|
let targetStartY = padding;
|
||||||
if (targetAlignMode === 'middle') {
|
if (targetAlignMode === 'middle') {
|
||||||
targetStartY = padding + Math.max(0, (layoutHeight - targetBlockHeight) / 2);
|
targetStartY = padding + Math.max(0, (sourceSpanHeight - targetBlockHeight) / 2);
|
||||||
} else if (targetAlignMode === 'bottom') {
|
} else if (targetAlignMode === 'bottom') {
|
||||||
targetStartY = padding + Math.max(0, layoutHeight - targetBlockHeight);
|
targetStartY = padding + Math.max(0, sourceSpanHeight - targetBlockHeight);
|
||||||
} else if (targetAlignMode === 'top') {
|
} else if (targetAlignMode === 'top') {
|
||||||
targetStartY = padding;
|
targetStartY = padding;
|
||||||
}
|
}
|
||||||
@@ -430,7 +438,7 @@ function buildSankeyLayout(links, width, height, renderOptions) {
|
|||||||
targetNames.forEach((name) => {
|
targetNames.forEach((name) => {
|
||||||
const nodeHeight = Math.max(2, targetValueMap[name] * targetUnitHeight);
|
const nodeHeight = Math.max(2, targetValueMap[name] * targetUnitHeight);
|
||||||
targetPos[name] = { y: targetCursorY, h: nodeHeight };
|
targetPos[name] = { y: targetCursorY, h: nodeHeight };
|
||||||
targetCursorY += nodeHeight + nodeGap;
|
targetCursorY += nodeHeight + targetGap;
|
||||||
});
|
});
|
||||||
|
|
||||||
const sourceOffset = {};
|
const sourceOffset = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user