Apply the eight galaxy visual refinements from the review
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user