优化分布

This commit is contained in:
CN-JS-HuiBai
2026-04-06 19:32:54 +08:00
parent 1583758f29
commit 3bdde47c60

View File

@@ -977,16 +977,22 @@
const isForward = (start === pts[0]);
// Calculate curveness: ensure all lines are slightly curved
// Use a canonical hash of the route endpoints to deterministically decide the curve direction
// This helps spread lines across the map even for single routes
const names = [route.source, route.dest].sort();
const routeHash = (names[0] + names[1]).split('').reduce((acc, char) => acc + char.charCodeAt(0), 0);
const baseSign = (routeHash % 2 === 0 ? 1 : -1);
let finalCurve = 0;
if (count === 1) {
finalCurve = 0.15; // Default slight curve for single lines
// Single lines get a decent curve, alternating direction based on hash
finalCurve = 0.2 * baseSign;
} else {
// Spread overlapping lines: 0.15, -0.15, 0.3, -0.3...
// This creates an "eye" or "fan" effect where no line is straight
const magnitude = 0.15 + Math.floor(i / 2) * 0.15;
// Multiple lines between same points fan out with increasing magnitude
const magnitude = 0.2 + Math.floor(i / 2) * 0.15;
const spread = (i % 2 === 0) ? magnitude : -magnitude;
// Adjust sign based on direction so they occupy unique visual slots
finalCurve = isForward ? spread : -spread;
// Apply baseSign to ensure the whole group isn't biased to one side
finalCurve = isForward ? (spread * baseSign) : (-spread * baseSign);
}
finalSeries.push({