Files
sorsfonalak/services/frontend/src/components/ChartWheel.tsx
T
fecoandClaude Opus 5.5 0bd5c39080
CI / test (push) Successful in 45s
CI / build (push) Successful in 4m19s
CI / deploy (push) Skipped
Comparisons (synastry) of the own chart and persons
/osszevetesek compares any two of the user's charts (own and persons); the
person card and the person's chart page have "Összevetés velem". The
comparison page shows a double wheel (first person inside with houses, second
outside, aspects between them), the aspects by character, and tabs: paid
relationship analysis (synastry unit), the cross aspect grid, house overlays,
composite and the full aspect list.

Correcting a person within the hour now deletes the user's own comparisons
with them instead of being refused; still refused after a paid analysis or
when someone else's comparison uses the chart.

The relationship analysis prompt is editable on /admin/promptok too, and can be
tried on one of the admin's comparisons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
2026-11-17 16:04:44 +00:00

282 lines
10 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { ASPECTS, POINTS, SIGNS, dms, orbText, pointName, signName } from "@/lib/astro";
import type { ChartResult, Position } from "@/lib/types";
// Radii of the rings (viewBox is SIZE × SIZE, centre C).
export const SIZE = 680;
const C = SIZE / 2;
const R_LABEL = 322; // ASC / MC labels
const R_OUT = 300; // outer edge of the zodiac ring
const R_ZOD = 254; // inner edge of the zodiac ring
const R_GLYPH = 222; // planet glyphs
const R_DEG = 188; // planet degrees
const R_HOUSE = 172; // outer edge of the house-number ring
const R_INNER = 146; // aspect circle
// Points drawn on the wheel; the asteroids and the south node are only in the tables.
export const WHEEL_POINTS = [
"sun",
"moon",
"mercury",
"venus",
"mars",
"jupiter",
"saturn",
"uranus",
"neptune",
"pluto",
"north_node",
"lilith",
"chiron",
];
// Aspects drawn on the wheel, between these points; the rest (minor aspects,
// nodes, Lilith, Chiron) are only in the aspect table.
export const WHEEL_ASPECTS = ["opposition", "square", "trine", "sextile"];
export const ASPECT_POINTS = ["sun", "moon", "mercury", "venus", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto"];
export const SIGN_ORDER = Object.keys(SIGNS);
export const SIGN_ELEMENT = ["fire", "earth", "air", "water"];
const ANGLE_LABELS: [string, string][] = [
["ascendant", "ASC"],
["midheaven", "MC"],
["descendant", "DSC"],
["imum_coeli", "IC"],
];
/** Screen point of an ecliptic longitude: the ascendant (or 0° Aries) is on the left. */
export function xy(lon: number, r: number, start: number): [number, number] {
const a = ((180 + lon - start) * Math.PI) / 180;
return [C + r * Math.cos(a), C - r * Math.sin(a)];
}
export const f = (n: number) => n.toFixed(2);
/** Pushes glyphs apart so that neighbours are at least `min` degrees from each other. */
export function spread(lons: number[], min: number): number[] {
const n = lons.length;
const order = lons.map((_, i) => i).sort((a, b) => lons[a] - lons[b]);
const pos = order.map((i) => lons[i]);
for (let iter = 0; iter < 200 && n > 1; iter++) {
let moved = false;
for (let i = 0; i < n; i++) {
const j = (i + 1) % n;
const gap = pos[j] - pos[i] + (j === 0 ? 360 : 0);
if (gap < min - 0.01) {
const d = (min - gap) / 2;
pos[i] -= d;
pos[j] += d;
moved = true;
}
}
if (!moved) break;
}
const out = new Array<number>(n);
order.forEach((orig, k) => (out[orig] = pos[k]));
return out;
}
export function arcPath(r1: number, r2: number, from: number, to: number, start: number): string {
const [x1, y1] = xy(from, r2, start);
const [x2, y2] = xy(to, r2, start);
const [x3, y3] = xy(to, r1, start);
const [x4, y4] = xy(from, r1, start);
// Increasing longitude runs counter-clockwise on screen (sweep flag 0).
return `M${f(x1)} ${f(y1)} A${r2} ${r2} 0 0 0 ${f(x2)} ${f(y2)} L${f(x3)} ${f(y3)} A${r1} ${r1} 0 0 1 ${f(x4)} ${f(y4)} Z`;
}
/** The natal chart as a wheel: zodiac, houses, planets and aspect lines. */
export function ChartWheel({ chart, timeKnown }: { chart: ChartResult; timeKnown: boolean }) {
const angle = (key: string): Position | null => {
const a = chart.angles?.[key];
return typeof a === "object" && a !== null ? a : null;
};
const asc = timeKnown ? angle("ascendant") : null;
const start = asc?.longitude ?? 0;
const cusps = timeKnown ? (chart.houses?.cusps ?? []) : [];
const points = WHEEL_POINTS.map((id) => chart.points.find((p) => p.id === id)).filter((p) => p !== undefined);
const placed = spread(
points.map((p) => p.longitude),
9,
);
// Aspect line ends: the planets at their spread-out glyph angle (so lines of
// neighbouring planets do not run into one point) and, with a known time,
// the ascendant and the midheaven.
const ends = new Map<string, number>();
points.forEach((p, i) => {
if (ASPECT_POINTS.includes(p.id)) ends.set(p.id, placed[i]);
});
if (timeKnown) {
for (const key of ["ascendant", "midheaven"]) {
const a = angle(key);
if (a) ends.set(key, a.longitude);
}
}
// Only the major aspects; tight ones are drawn last (on top).
const aspects = (chart.aspects ?? [])
.filter((a) => WHEEL_ASPECTS.includes(a.aspect) && ends.has(a.point1) && ends.has(a.point2))
.map((a) => ({ ...a, strength: a.max_orb > 0 ? 1 - Math.min(a.orb / a.max_orb, 1) : 0.5 }))
.sort((x, y) => x.strength - y.strength);
const description = points
.map((p) => `${pointName(p.id)} ${signName(p.sign)} ${dms(p.degree_in_sign_dms)}`)
.join(", ");
return (
<svg
className="chart-wheel"
viewBox={`0 0 ${SIZE} ${SIZE}`}
role="img"
aria-labelledby="wheel-title wheel-desc"
>
<title id="wheel-title">Születési képlet</title>
<desc id="wheel-desc">
{timeKnown && asc ? `Aszcendens ${signName(asc.sign)}. ` : "Születési idő nélkül, házak nélkül. "}
{description}
</desc>
{/* Zodiac ring */}
<circle cx={C} cy={C} r={R_OUT} className="w-ring" />
{SIGN_ORDER.map((sign, i) => {
const [gx, gy] = xy(i * 30 + 15, (R_OUT + R_ZOD) / 2, start);
return (
<g key={sign}>
<path d={arcPath(R_ZOD, R_OUT, i * 30, i * 30 + 30, start)} className={`w-sign w-${SIGN_ELEMENT[i % 4]}`} />
<text x={f(gx)} y={f(gy)} className="w-sign-glyph" dominantBaseline="central" textAnchor="middle">
<title>{SIGNS[sign].hu}</title>
{SIGNS[sign].glyph}
</text>
</g>
);
})}
{Array.from({ length: 360 }, (_, d) => {
const len = d % 10 === 0 ? 9 : d % 5 === 0 ? 6 : 3;
const [x1, y1] = xy(d, R_ZOD, start);
const [x2, y2] = xy(d, R_ZOD + len, start);
return <line key={d} x1={f(x1)} y1={f(y1)} x2={f(x2)} y2={f(y2)} className="w-tick" />;
})}
<circle cx={C} cy={C} r={R_ZOD} className="w-ring" />
{/* Houses */}
{cusps.length === 12 && (
<g>
<circle cx={C} cy={C} r={R_HOUSE} className="w-ring w-faint" />
{cusps.map((c, i) => {
const isAngle = i % 3 === 0;
const [x1, y1] = xy(c.longitude, R_INNER, start);
const [x2, y2] = xy(c.longitude, isAngle ? R_OUT : R_ZOD, start);
const next = cusps[(i + 1) % 12].longitude;
const mid = c.longitude + (((next - c.longitude + 360) % 360) / 2);
const [nx, ny] = xy(mid, (R_HOUSE + R_INNER) / 2, start);
return (
<g key={c.house}>
<line x1={f(x1)} y1={f(y1)} x2={f(x2)} y2={f(y2)} className={isAngle ? "w-axis" : "w-cusp"} />
<text x={f(nx)} y={f(ny)} className="w-house-num" dominantBaseline="central" textAnchor="middle">
{c.house}
</text>
</g>
);
})}
{ANGLE_LABELS.map(([key, label]) => {
const a = angle(key);
if (!a) return null;
const [x, y] = xy(a.longitude, R_LABEL, start);
return (
<text
key={key}
x={f(x)}
y={f(y)}
className="w-axis-label"
dominantBaseline="central"
textAnchor="middle"
>
<title>
{pointName(key)}: {dms(a.degree_in_sign_dms)} {signName(a.sign)}
</title>
{label}
</text>
);
})}
</g>
)}
{/* Aspects */}
<circle cx={C} cy={C} r={R_INNER} className="w-ring w-inner" />
{aspects.map((a) => {
const [x1, y1] = xy(ends.get(a.point1)!, R_INNER, start);
const [x2, y2] = xy(ends.get(a.point2)!, R_INNER, start);
const s = a.strength;
return (
<line
key={`${a.point1}-${a.point2}-${a.aspect}`}
x1={f(x1)}
y1={f(y1)}
x2={f(x2)}
y2={f(y2)}
className={`w-aspect w-asp-${a.aspect}`}
strokeOpacity={(0.2 + 0.8 * s * s).toFixed(2)}
strokeWidth={(0.6 + 1.9 * s).toFixed(2)}
>
<title>
{pointName(a.point1)} {ASPECTS[a.aspect]?.hu ?? a.aspect} {pointName(a.point2)} (orbis{" "}
{orbText(a.orb)})
</title>
</line>
);
})}
{/* Planets */}
{points.map((p, i) => {
const [t1x, t1y] = xy(p.longitude, R_ZOD, start);
const [t2x, t2y] = xy(p.longitude, R_ZOD - 8, start);
const [lx, ly] = xy(placed[i], R_GLYPH + 14, start);
const [gx, gy] = xy(placed[i], R_GLYPH, start);
const [dx, dy] = xy(placed[i], R_DEG, start);
const [ex, ey] = xy(placed[i], R_INNER, start);
const deg = Number.parseInt(p.degree_in_sign_dms, 10);
return (
<g key={p.id} className="w-point">
<title>
{pointName(p.id)}: {dms(p.degree_in_sign_dms)} {signName(p.sign)}
{p.retrograde ? ", retrográd" : ""}
{timeKnown && p.house ? `, ${p.house}. ház` : ""}
</title>
<line x1={f(t1x)} y1={f(t1y)} x2={f(t2x)} y2={f(t2y)} className="w-point-tick" />
<line x1={f(t2x)} y1={f(t2y)} x2={f(lx)} y2={f(ly)} className="w-leader" />
<text x={f(gx)} y={f(gy)} className="w-point-glyph" dominantBaseline="central" textAnchor="middle">
{POINTS[p.id]?.glyph ?? p.id}
</text>
<text x={f(dx)} y={f(dy)} className="w-point-deg" dominantBaseline="central" textAnchor="middle">
{deg}°{p.retrograde ? "℞" : ""}
</text>
{ends.has(p.id) && <circle cx={f(ex)} cy={f(ey)} r={2.2} className="w-end" />}
</g>
);
})}
</svg>
);
}
const LEGEND: [string, string][] = [
["trine", "trigon"],
["sextile", "szextil"],
["square", "kvadrát"],
["opposition", "szembenállás"],
];
/** Key to the aspect lines of the wheel. */
export function WheelLegend() {
return (
<div className="hint wheel-legend">
<p className="wheel-legend-items">
{LEGEND.map(([aspect, label]) => (
<span key={aspect} className="legend-item">
<span className={`legend-line legend-${aspect}`} aria-hidden="true" /> {label}
</span>
))}
</p>
<p>Vastagabb vonal: szorosabb fényszög.</p>
<p>A körön a bolygók, az ASC és az MC főfényszögei vannak; az összes fényszög a táblázatban.</p>
</div>
);
}