Apply the eight galaxy visual refinements from the review

This commit is contained in:
Tessera Agent
2026-11-09 12:19:04 +00:00
parent 5b40536e37
commit 0ee32fcf8f
4 changed files with 172 additions and 96 deletions

View File

@@ -74,6 +74,61 @@ export function layoutLockLabels(
}
}
const yMin = -160;
const yMax = 108;
const xMin = -230;
const xMax = 230;
for (let i = 0; i < labels.length; i++) {
const star = starPositions[i];
const hitsChrome =
labels[i].y < yMin ||
labels[i].y > yMax ||
labels[i].x < xMin ||
labels[i].x > xMax;
const hitsNeighbor = starPositions.some(
(other, k) => k !== i && dist(labels[i], other) < starR + 20,
);
if (hitsChrome || hitsNeighbor) {
const ang = Math.atan2(star.y, star.x);
labels[i] = {
x: star.x - Math.cos(ang) * (starR + 34),
y: star.y - Math.sin(ang) * (starR + 34),
};
}
labels[i].x = Math.max(xMin, Math.min(xMax, labels[i].x));
labels[i].y = Math.max(yMin, Math.min(yMax, labels[i].y));
const gap = dist(labels[i], star);
if (gap < starR + 16) {
const ang = Math.atan2(labels[i].y - star.y, labels[i].x - star.x) || 0;
labels[i].x = star.x + Math.cos(ang) * (starR + 18);
labels[i].y = Math.max(
yMin,
Math.min(yMax, star.y + Math.sin(ang) * (starR + 18)),
);
}
}
for (let iter = 0; iter < 24; iter++) {
for (let i = 0; i < labels.length; i++) {
for (let j = i + 1; j < labels.length; j++) {
const wi = labelWidth(names[i]);
const wj = labelWidth(names[j]);
const dx = labels[j].x - labels[i].x;
const dy = labels[j].y - labels[i].y;
const needX = (wi + wj) / 2 + 8;
const needY = LABEL_H + 6;
if (Math.abs(dx) < needX && Math.abs(dy) < needY) {
const push = (needX - Math.abs(dx)) * 0.55 + 1;
const dir = dx === 0 ? (i % 2 === 0 ? -1 : 1) : Math.sign(dx);
labels[i].x -= dir * push;
labels[j].x += dir * push;
}
}
labels[i].x = Math.max(xMin, Math.min(xMax, labels[i].x));
labels[i].y = Math.max(yMin, Math.min(yMax, labels[i].y));
}
}
return labels;
}