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). 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. const WHEEL_POINTS = [ "sun", "moon", "mercury", "venus", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto", "north_node", "lilith", "chiron", ]; const SIGN_ORDER = Object.keys(SIGNS); 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. */ 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)]; } const f = (n: number) => n.toFixed(2); /** Pushes glyphs apart so that neighbours are at least `min` degrees from each other. */ 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(n); order.forEach((orig, k) => (out[orig] = pos[k])); return out; } 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, ); // Longitudes for the aspect line ends (planets and, with a known time, the angles). const ends = new Map(points.map((p) => [p.id, p.longitude])); if (timeKnown) { for (const [key] of ANGLE_LABELS) { const a = angle(key); if (a) ends.set(key, a.longitude); } } const aspects = (chart.aspects ?? []).filter( (a) => a.aspect !== "conjunction" && ends.has(a.point1) && ends.has(a.point2), ); const description = points .map((p) => `${pointName(p.id)} ${signName(p.sign)} ${dms(p.degree_in_sign_dms)}`) .join(", "); return ( Születési képlet {timeKnown && asc ? `Aszcendens ${signName(asc.sign)}. ` : "Születési idő nélkül, házak nélkül. "} {description} {/* Zodiac ring */} {SIGN_ORDER.map((sign, i) => { const [gx, gy] = xy(i * 30 + 15, (R_OUT + R_ZOD) / 2, start); return ( {SIGNS[sign].hu} {SIGNS[sign].glyph} ); })} {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 ; })} {/* Houses */} {cusps.length === 12 && ( {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 ( {c.house} ); })} {ANGLE_LABELS.map(([key, label]) => { const a = angle(key); if (!a) return null; const [x, y] = xy(a.longitude, R_LABEL, start); return ( {pointName(key)}: {dms(a.degree_in_sign_dms)} {signName(a.sign)} {label} ); })} )} {/* Aspects */} {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 kind = ASPECTS[a.aspect]?.kind ?? "neutral"; const strength = a.max_orb > 0 ? 1 - Math.min(a.orb / a.max_orb, 1) : 0.5; return ( {pointName(a.point1)} {ASPECTS[a.aspect]?.hu ?? a.aspect} {pointName(a.point2)} (orbis{" "} {orbText(a.orb)}) ); })} {/* 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(p.longitude, R_INNER, start); const deg = Number.parseInt(p.degree_in_sign_dms, 10); return ( {pointName(p.id)}: {dms(p.degree_in_sign_dms)} {signName(p.sign)} {p.retrograde ? ", retrográd" : ""} {timeKnown && p.house ? `, ${p.house}. ház` : ""} {POINTS[p.id]?.glyph ?? p.id} {deg}°{p.retrograde ? "℞" : ""} ); })} ); }