优化算法
This commit is contained in:
@@ -976,23 +976,19 @@
|
|||||||
const pts = [start, end].slice().sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
const pts = [start, end].slice().sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
||||||
const isForward = (start === pts[0]);
|
const isForward = (start === pts[0]);
|
||||||
|
|
||||||
// Calculate curveness: ensure all lines are slightly curved
|
// Simplified calculation to reduce crossings
|
||||||
// Use a canonical hash of the route endpoints to deterministically decide the curve direction
|
// Maintaining a consistent direction for single lines ensures that parallel paths stay parallel
|
||||||
// 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;
|
let finalCurve = 0;
|
||||||
if (count === 1) {
|
if (count === 1) {
|
||||||
// Single lines get a decent curve, alternating direction based on hash
|
// Subtle consistent curve for single routes
|
||||||
finalCurve = 0.2 * baseSign;
|
finalCurve = 0.12;
|
||||||
} else {
|
} else {
|
||||||
// Multiple lines between same points fan out with increasing magnitude
|
// Symmetrical fan-out for multiple lines between the same points
|
||||||
const magnitude = 0.2 + Math.floor(i / 2) * 0.15;
|
// This spreads them cleanly into "eye" shapes without biased clustering
|
||||||
|
const magnitude = 0.12 + Math.floor(i / 2) * 0.12;
|
||||||
const spread = (i % 2 === 0) ? magnitude : -magnitude;
|
const spread = (i % 2 === 0) ? magnitude : -magnitude;
|
||||||
// Apply baseSign to ensure the whole group isn't biased to one side
|
// Ensure visual consistency regardless of the data direction (A->B or B->A)
|
||||||
finalCurve = isForward ? (spread * baseSign) : (-spread * baseSign);
|
finalCurve = isForward ? spread : -spread;
|
||||||
}
|
}
|
||||||
|
|
||||||
finalSeries.push({
|
finalSeries.push({
|
||||||
|
|||||||
Reference in New Issue
Block a user